How to Run 50 Coding Agents Without Merge Conflicts
Running coding agents without merge conflicts gets harder with every agent you add. Two agents rarely collide. Fifty will, unless the work is divided before they start and something keeps them to the division. This guide gives a procedure that scales from a handful of parallel coding agents to dozens: decompose by files, isolate each agent, record claims, merge in small steps, and route conflicts back to the planner. It draws on what Cursor, Anthropic and GitHub have published and on Forkit's file claims.
Why running coding agents without merge conflicts is hard
People avoid conflicts through habit. They know who is working on what, they ask before touching a shared file, and they rebase often. Agents have none of that unless you supply it.
Three things make it worse:
- Agents are thorough. Asked to fix a bug, an agent may also tidy the imports of every file it opens.
- Agents are fast. Fifty branches can diverge a long way in an hour.
- Agents do not know about each other. Each session starts with the repository and a task, not with a picture of the other forty-nine.
Anthropic's documentation for agent teams states the result plainly: two teammates editing the same file leads to overwrites, and the fix is to break the work so each teammate owns a different set of files.
Step 1: Decompose by files, not by features
Task decomposition is where conflicts are prevented or created. Split the work so that each task's set of files is disjoint from the others.
Good splits:
- One package or module per agent.
- One endpoint per agent, where each endpoint lives in its own file.
- One test file per agent.
Bad splits:
- "Add logging" and "improve error handling" across the same code.
- Any two tasks that both need to edit a central file: a router, a schema, a shared types file, a lockfile.
For the shared files, give them to one agent. A common pattern is a single "integration" task that owns the router and the schema, runs after the others and wires their work together.
Write the file scope into each task. "Migrate packages/billing/ to the new client. Do not edit files outside that directory" is a better task than "migrate billing".
Step 2: Give each agent its own working copy
Agents that share a directory fight over build output, ports and half-saved files. Give each one a separate copy.
- Locally: git worktrees. Claude Code's
--worktreeflag creates one under.claude/worktrees/on a new branch. Desktop tools such as Conductor and Vibe Kanban create a workspace per task for you. - In the cloud or CI: one sandbox or job per agent, each with its own clone.
This guarantees agents cannot overwrite each other on disk. It guarantees nothing about whether their branches will merge.
Step 3: Record file claims before editing
A working copy per agent turns edit conflicts into merge conflicts. To catch them earlier, each agent states which paths it will touch, and something checks the statements against each other.
With Forkit, an agent calls claim_paths at the start of its task:
await codemode.claim_paths({
patterns: ['packages/billing/**'],
ttl_seconds: 3600,
reason: 'migrate billing to the new client'
});
What the documentation says happens next:
- The claim lasts for the time given: 30 minutes by default, 4 hours at most. Activity on the agent's session renews it, and the session's end releases it.
- If another agent already claims overlapping paths, the claim is still granted, and the response lists the conflicts. Both agents get a notice.
- Before an edit, the Claude Code hook checks the paths. An edit under another agent's exclusive claim is refused, with the holder's name.
So an agent that strays outside its scope into someone else's files is stopped at the edit, not at the merge.
Claims expire because locks do not work for agents. Cursor reported that with plain locks, agents held them too long or forgot to release them, and twenty agents slowed to the throughput of two or three.
Step 4: Keep one planner
Cursor's experiments found that a flat group of agents coordinating among themselves churned without progress, and that separating planners from workers fixed most of the coordination problems. Workers take one task and do not coordinate with other workers.
For conflict avoidance, the planner has three jobs:
- Produce the disjoint split from step 1.
- Receive each worker's result.
- Treat any conflict notice as a planning error and re-split.
A conflict between two workers is almost always the planner's mistake: two tasks whose scopes overlapped. The fix is to change the plan, not to have the workers negotiate.
Step 5: Merge early and in order
Fifty branches merged at the end is fifty chances to conflict with everything before. Instead:
- Merge each worker's branch as soon as it passes its checks.
- Have later workers start from the updated main branch.
- Order the work by dependency. If task B needs task A's new function, B waits.
Dependencies between tasks are worth making explicit. Forkit's tasks can block one another, and ready_tasks returns only tasks whose blockers are done, so a worker asking for work never receives one that is too early. See task dependencies for agents.
Step 6: Constrain what agents touch
Even with a good plan, limit drive-by edits.
- Put the scope in the prompt, as in step 1.
- In Claude Code, permission rules can deny edits to named paths.
- Keep generated files and lockfiles out of workers' hands. One agent regenerates them at the end.
- Ask each worker to report the files it changed, and compare the report with what was recorded.
A worked example
A team migrates forty packages to a new HTTP client.
- A planner lists the packages and creates forty tasks, each scoped to
packages/<name>/, plus one final task for the shared lockfile and the root config, blocked by all forty. - Forty workers start in forty sandboxes. Each asks for a ready task, claims it, and claims its package's path.
- Two workers discover they both need to change
packages/shared/http.ts. The second one's edit is refused. It sends a question to the planner. - The planner creates a new task for the shared file, assigns it to one worker and blocks the two packages on it.
- Branches merge as they pass. The final task regenerates the lockfile.
The conflict in step 3 cost one refused edit and one message. Found at merge time, it would have cost two packages' worth of rework.
What this does not solve
Semantic conflicts still happen: two changes that merge cleanly and break each other. Tests catch those, not claims. Run the full suite on main after each merge.
Related: git worktrees vs file leases, file locking for AI agents and multi-agent architectures compared.
Where Forkit fits
Forkit provides the claims, the task dependencies and the messages between workers and planner. Worktrees and sandboxes come from your other tools. It is free to try. More at forkit-mcp.com.