Skip to main content

Two AI coding agents, one file: detecting overlapping edits with exit code 3

Updated 3 min readMarkdown

aisync is a local hub for Multi-Agent Context Management, Coordination & Observability. This post covers the coordination part: how two coding agents on one machine find out they are about to edit the same file.

The problem

Run Claude Code and Codex in the same repository and nothing stops both from rewriting app/payments/refunds.py. Each tool only sees its own session, so the clash shows up later as a confusing merge or a silently overwritten fix.

What aisync does about it

An agent declares a claim on the files it is about to touch. If another agent already holds a claim on those files, the CLI refuses with exit code 3, so a script or a hook can stop instead of editing.

I ran this in a throwaway virtualenv with AISYNC_HOME pointing at a temp directory, so it did not touch my real hub (aisync 0.2.9):

pip install aisync-cli
aisync init
aisync claim -a claude-code -p api -f app/payments/refunds.py -m "refund fix"
# claimed api [app/payments/refunds.py] for claude-code until 05:28      (exit 0)

aisync claim -a codex -p api -f app/payments/refunds.py -m "sdk upgrade"
# OVERLAP: claude-code is working on api [app/payments/refunds.py] until 05:28: refund fix
# stop and coordinate with claude-code, or pick other files (exit 3). Your claim is noted, so claude-code can see you are waiting.   (exit 3)

aisync release -a claude-code -p api
# released 1 claim(s)

aisync claim -a codex -p api -f app/payments/refunds.py -m "sdk upgrade"
# claimed api [app/payments/refunds.py] for codex until 05:28            (exit 0)

aisync verify
# journal chain intact                                                   (exit 0)

Three details from that run. The refused claim is still recorded, so the first agent can see someone is waiting. aisync claims lists both. And claims carry an expiry: the output above says until 05:28 for a claim made around 03:28, so about two hours.

The observability half

Every claim, release and other agent event goes into a journal in the hub, which is a plain git repo. Each event stores the id of the one before it, so aisync verify can detect an edited entry, or a removed one that a later entry points at (a removed last entry is not caught).

Limits

This post and the test run were written and tested by an AI agent (Claude Code) for the maintainer. The outputs above are copied from that run.

Originally published on Dev.to.

No comments yet. Be the first to comment.

More from this blog