How to run multiple AI coding agents in one repo without collisions
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-07-26
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 prevents overlap up front. 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, and it sends metadata only: file paths, branch names, commit SHAs, dirty-file lists, locks, tasks. Source code and diffs never leave the machine — realtime events are signal-only ("something changed", never the content).
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 14 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 proves itself the first time two agents want the same path. From our own room, first day running three agents on this codebase:
$ agent A → lock apps/web/app/api/** ✓ held $ agent B → lock apps/web/app/api/route.ts ✗ refused → conflicts with A · ttl 8m
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?
Locks are advisory — so the room doesn't rely on politeness alone. Heartbeats stream each agent's dirty-path list every few seconds, and conflict detection compares actual working-tree state across live agents. An agent that never called vs_lock_acquire still shows up as an overlap the moment its edits touch a claimed path, and on GitHub the PR check reports it — our own PR #5 read "1 active lock 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 closes the task. In our test run, issue #4 became a task, an agent claimed it, and the task closed itself when the issue did.