Claude Code and Codex Editing the Same Repo: File Locks Only Cover the First Layer of Trouble
Two agents editing the same repo in parallel—fighting over files is only the surface. In his second post, Erwin breaks productionization into four gates: ACP driving, worktree isolation, hybrid workflow gates, and an outer sandbox. The conclusion is restrained: get the process stable first; don't roll out the full stack on day one.
Claude Code writes the backend, Codex writes the frontend, and the two agents modify the same repo at the same time. It looks smooth in a demo. In a real project, they first collide over files, then over ports. Each branch is clean on its own, but the build fails after merging. This kind of problem cannot be solved with a single prompt.
In his second article, Erwin breaks the productionization of multi-agent orchestration into four gates: how the orchestrator commands the underlying agents, how far isolation should go, how rigid the workflow should be, and how permissions should be constrained. Part 1 passed 500k views, yet he still calls the version that only connects the basic modules a “demo toy.” The second article discusses the journey from a model showroom to a workshop that can actually start work. The original article is here, and Baoyu's retelling is in the original tweet.
First, distinguish the two protocol directions. MCP is the orchestrator exposing tools outward for models to call. ACP is the orchestrator driving native harnesses such as Claude Code downward, taking over the session stream and permission callbacks. The driving methods have gone through three stages: early headless CLI relied on one-way stdout round trips—simple, but dynamic input and blocking approvals easily get stuck; later, native SDKs from various vendors enabled bidirectional interaction, at the cost of maintaining an adapter layer for every agent connected; ACP is like building an LSP for coding agents, folding messages, file IO, terminal execution, and permission approval into a unified interface. In reality, ACP coverage is still incomplete. Mature tools keep flagship harnesses like Claude Code and Codex on their native private protocols and route the rest through ACP, reducing adapter maintenance.
Concurrent isolation has three layers. Directory locks and file locks are the simplest, with zero concurrency, but they also kill parallelism; the Git staging area and build artifacts of shared modules can still collide. Git worktrees are more common: each agent gets a working copy and merges back to main after changes. They isolate only on-disk source code, not shared runtime resources. Two agents can still fight over port 8088, overwrite global caches, and share local API credentials. Putting worktrees into Docker containers truly separates source, ports, and environment variables, but memory overhead also rises.
Even with sufficient isolation, logical conflicts still occur. The backend agent changes a response field on one branch, while the frontend agent writes a call against the old field on another branch. Both branches look clean individually, but merging explodes. One commenter said two agents fixing package-lock.json in parallel is their new favorite merge conflict. That picture is not exaggerated. Trying to catch all logical conflicts through mechanisms has high cost and low payoff. A more reliable approach is to borrow the rules human teams use in large repos.
Contract first. Before dispatching parallel tasks, lock the shared interface definitions or type files. Downstream teams develop in parallel against the same contract, and interface files are read-only. This eliminates most integration conflicts. Directory ownership boundaries. Give each worker an explicit whitelist of writable paths. When they touch shared files like package.json, the edit is blocked and handed to the coordinator for unified handling. Merge queue. Workers do not merge directly into main. Completed branches enter a queue, and the orchestrator rebases them one by one onto the latest main and runs CI. If a later branch conflicts, it sends the conflict context back to the corresponding worker for targeted repair.
How rigid the workflow should be is another hurdle. Lock everything down, and agents cannot adapt to unexpected errors or requirement changes. Open everything up, and they may skip standards, forget review, and spin while two agents wait on each other. Mainstream approaches fall into three camps: deterministic graph orchestration, using a DAG to hard-code states, nodes, and transition conditions—auditable and replayable, with no extra tokens burned on routing, but for exploratory work like coding it is very hard to enumerate branches in advance; hybrid orchestration, where an outer deterministic state machine locks down major stages and hard gates while the inner layer is left to the native harness to decide how to work; high-autonomy soft guidance, using system prompts and skills to teach the coordinator to split work and find teammates—open-ended tasks have a high ceiling, but stability depends more on the model following instructions. Erwin's principle is blunt: leave dependencies, quality gates, and cost caps to deterministic code; leave execution freedom to the model.
Don't rush to reinvent the sandbox either. Codex and Claude Code come with OS-level sandboxes, but they are not enough once multiple harnesses are put on real projects. Sandbox maturity varies by vendor, and the weakest open-source CLI can drag down the whole security gate. Native sandboxes mainly protect the host; they are not responsible for interference among multiple agents. In a team, builders need read/write access, reviewers should only read—permissions cannot be one-size-fits-all. An outer sandbox needs to do three things: keep credentials outside the sandbox or at a proxy layer, injecting outbound requests according to policy; decide mounted directories, IO permissions, and tool exposure by role; and catch approval requests bubbling up from underlying harnesses, collecting them into the orchestrator's unified approval UI.
If you build a lightweight multi-agent orchestration system yourself, you do not need to max out every module on day one. Get ACP driving, worktree isolation, and hybrid workflow gates running smoothly, and you already cover most everyday engineering. Add the outer sandbox and unified approval flow later, once team size or automation depth increases. Implementation code can be handed to AI, but architectural tradeoffs still need humans to think through.
One commenter uses a more old-school division of labor: one agent only writes to a directory, while another process reads and executes, handing off through files. It is less flexible than an orchestrator, but they almost never fight, and problems are easy to trace. This compromise is worth remembering. The hard part of multi-agent work is often not whether the model can write code, but whether the engineering boundaries are clearly drawn.
发布时间: 2026-12-03 07:31