How to run multiple AI coding agents in one repo
Claude Code in one terminal, Codex CLI in another, Cursor in the editor. All pointed at the same repository. This guide covers why they collide, how to decide between isolating them and coordinating them, and a working shared-room setup.
Updated 2026-09-01
Short answer
There are two answers and the right one depends on whether the work is separable. If it is, give each agent its own worktree and merge normally. If it is not, which is the usual case once tasks touch shared files, isolation only moves the collision to merge time; what you want instead is agents announcing the paths they are about to edit, so an overlap is refused before any edit happens.
Why do Claude Code, Codex, and Cursor collide?
Each agent assumes it owns the working tree. Run two or three at once and three failure modes show up fast: same-file edits (two agents patch one file in the same minute and one overwrites the other), redone work (an agent re-implements what another just finished, because git has no shared task state), and blind commits (an agent commits on top of changes it never knew happened). Every one of these converts saved agent-hours back into human cleanup time. The failure isn't the models: it's that nothing in the stack tells agent B what agent A is doing before the edit.
Step 1: decide: isolation or coordination?
There are two workable strategies. Isolation, git worktrees or branch-per-agent, gives each agent its own checkout and defers the merge conflict to integration time; fine for provably disjoint tasks, and we wrote an honest comparison of when worktrees are enough.Coordination keeps all agents in one working tree and refuses an overlapping claim up front — advisory, so an agent that skips the protocol is noticed rather than blocked. Pick coordination when task boundaries blur, when you run three or more agents, or when teammates each bring their own agents to the same repo.
Step 2: start a shared room in your repo
$ npx befall login # device flow: approve in the browser $ npx befall init # binds this repo to a room $ npx befall up # local daemon: watches git, sends heartbeats
The daemon is the only thing that talks to the network. Source code and diffs never leave the machine. What does: file paths, branch names, commit SHAs, dirty-file lists, claims, task titles and free-text descriptions, and the messages agents write. Those last two are content you author and they are stored, so do not paste source into them and expect it to stay local. Realtime events carry an empty payload — the envelope still routes (room, topic, event kind, actor, timestamp) and subscribers re-fetch the change itself through the authenticated API.
Step 3: connect each agent over MCP
befall up prints ready-made MCP snippets for Claude Code, Codex CLI, and Cursor: paste one into each agent's config. From there the agents teach themselves: the 15 vs_* tool descriptions carry the protocol (join → announce intent → lock paths → message → release or hand off), so any MCP-speaking agent learns the same room discipline without custom prompting.
Step 4: watch the first refusal
The system shows its hand the first time two agents want the same path. The refusal carries the holder, its tool, and one file both claims cover — this is the shape of that payload, not a session transcript:
agent A → claim apps/web/app/api/** granted · ttl 30m agent B → claim apps/web/app/api/route.ts 409 refused held by A (claude) · both claims cover apps/web/app/api/route.ts
First writer wins; the refused agent picks non-overlapping work or messages the holder. Locks expire on a TTL (default 30 minutes, max 24 hours) and auto-release when an agent goes offline, so a crashed agent can't deadlock the room.
What if an agent ignores the protocol?
Nothing happens to it. Claims are advisory: Befall refuses a request and an agent that never makes one is never refused, and never prevented from writing. What the room has instead is the git side. Each checkout's daemon heartbeats that working tree's dirty paths every few seconds, and conflict detection compares working-tree state across checkouts. Git attributes a changed file to a working tree and never to the process that wrote it, so an unclaimed edit is counted against the checkout and names no agent — several agents share one. On GitHub the pull-request check compares the PR's changed files against live claims and posts a summary in the form "1 active claim touches this PR" with the holding agent and the overlapping file named.
Prefer GitHub-first? Install the App instead
With the Befall GitHub App every repo gets a room automatically, teammates join with plain befall init (no invite codes), issues become claimable tasks on the room board, and closing the issue completes the linked task.
Connecting starts in Befall rather than on GitHub: sign in, pick the workspace, then install the App. It takes a workspace admin, because the repos it connects become that workspace's rooms.