How to Check That Parallel Agents' Work Will Merge
Parallel coding agents each work in their own checkout, so they never overwrite each other's files. Their branches can still conflict when they are merged. Most setups find out at that point, after every agent has finished and left. By then nobody who wrote the code is around to fix it.
This guide shows how to check, before an agent says it is done, whether its change would merge with its peers' changes, and how to make that check automatic for a fan-out of agents.
A note on a shared word: when one of Forkit's factories (saved fan-outs) starts agents, the same check applies to them. The company Factory is unrelated.
How often agent branches conflict
Xu, Subramanian and Karthik ("AI Agent Pull Requests on GitHub: Frequency, Structure, and Merge Conflict Rates", arXiv 2607.04697v2, 7 Jul 2026, preprint) replayed merges of pull requests that agents opened in the same repository at overlapping times. Of 601 pairs written by the same agent model, 19.8% had a textual conflict. Of 115 pairs written by different agent models, 41.7% did. The confidence intervals do not overlap.
At the far end of scale, Anthropic's "Redesigning source control at Anthropic" (13 Oct 2026) reports merged changes rising from about 2,500 a day in May 2026 to over 30,000 a day by September. A global lock on merges did not scale, so Anthropic tests after changes merge and before they deploy, and accepts that concurrent changes will sometimes conflict: "Claude can typically fix these conflicts faster than humans can even identify them."
That works when an agent is available after the merge to fix it. In a fan-out, the agents that wrote the two sides have usually ended. A check while they are still running reaches the agents that can fix the conflict.
What the merge check does
From Forkit's engineering notes ("Would our work merge?", 23 Nov 2026):
- A fan-out agent sends its checkout's change since the commit it started from, with that base commit, to
POST /api/v1/merge-check. The base is kept in.git/forkit-basefrom the first time Forkit sees the checkout, so committing does not hide work or move the base. - The change includes tracked edits, commits and new files, minus paths you exclude.
- Forkit keeps each agent's latest change and compares it with each fan-out peer's latest, the way git's merge decides: changes to the same or adjacent base lines conflict unless they are identical.
- The answer is
clean, orconflicts(the file, both line ranges and the peer), pluswaiting_for(peers with no change sent yet),different_base(peers that started from another commit, which are not compared) andpeers(who checked, who is open, when each was last seen).
It compares only peers of the same fan-out. It gave the same verdict as git on all 26 merges CooperBench had recorded when the check was built, and on all 37 by the end of that week's runs (one benchmark; the cases are not published).
It compares text. It does not run tests on the combined code. Two changes that merge cleanly can still break each other when run; that check is not built.
Step 1: Check by hand
Any fan-out agent, or a person in its checkout, can ask:
forkit check-merge
Exit codes:
- 0: the change would merge with every peer that has checked in.
- 1: it would conflict. The output says where and with whom.
- 2: it could not be checked.
The output also names peers that have not sent a change yet and peers that started from another commit. To leave generated files out:
forkit check-merge --exclude package-lock.json --exclude dist/
FORKIT_MERGE_EXCLUDE sets the same for the hook.
Run it before a commit, in CI after each agent's push, or as a final step in the agent's prompt.
Step 2: Let the Stop hook ask
For fan-out keys (they start with fo_), Forkit's Claude Code Stop hook runs the check when the agent tries to end its turn. FORKIT_MERGE_CHECK=1 turns it on for other keys; 0 turns it off.
If the change would conflict, the hook holds the agent: it refuses the stop and tells the agent the file, both line ranges and the peer, and that the peer may have sent a patch it can apply with forkit apply. The agent can then message the peer, take the peer's patch, or change its own work. The hook never holds an agent when another Stop reason already applies.
How many times the hook holds an agent is set by FORKIT_MERGE_HOLDS: a count (default 3), or auto, which holds once for each conflict not seen before in the session. A conflict's identity changes when either side's change in that place changes, so two diffs flipping back and forth do not hold the agent again for one it has already seen.
Step 3: Make the first agent wait for its peers
The check needs something to compare with. Forkit learned this from its own CooperBench runs: four runs in a row, the first agent to finish checked, found nobody to compare with, and left. The second was held alone with a conflict only the first could fix.
So an agent that finishes first waits for its peers to check in:
FORKIT_MERGE_WAIT: seconds to wait, default 300. Orauto: wait while some peer that has not checked in has an open session active withinFORKIT_MERGE_QUIETseconds (default 180).FORKIT_MERGE_POLL: how often to check again, default every 15 s.0does not wait.
A conflict found when a later peer arrives then holds the first agent while it can still help.
Step 4: Know the hard caps
A peer can be stuck, slow or hostile. Whatever the settings, two caps hold:
FORKIT_MERGE_MAX: at most 840 s of waiting in total (inside Claude Code's 900 s Stop hook limit).FORKIT_MERGE_MAX_HOLDS: at most 10 holds in a session.
The behaviour was tested against a peer that never starts, one busy forever without checking in, one gone quiet, the same conflict repeated, two diffs flipping, endless new conflicts, a stranger from another fan-out, and a hundred large diffs (Forkit's merge_check.test.ts). The check parses only diffs that name one of the agent's own files, so a large unrelated diff costs little.
Step 5: Resolve what the check finds
A held agent has three good moves:
- Message the peer and agree who owns the conflicting lines.
- Take the peer's change. If the peer sent a patch,
forkit apply ID. If the peer's version already contains this agent's work (it built both),forkit apply ID --replacesets this agent's own change aside as a backup patch and applies the peer's. A real run on 25 Nov 2026 with two Claude Code agents needed exactly that: one built both features, and the other could not take it without discarding its own edits. - Change its own work so it no longer touches the peer's lines.
See how to send a patch from one coding agent to another for the details, including why forkit apply refuses patches that write agent, CI or editor settings unless told --allow-config.
What it did in practice
In Forkit's CooperBench runs (two-agents-one-function-cooperbench, 23 Nov 2026), four task pairs forced both agents to change the same lines. With CooperBench's own messaging, 0 of 8 runs merged. Adding the merge check without waiting merged 0 of 4, for the reason above. Adding the wait merged 3 of 4. Those versions ran once per pair: a signal, not a measured rate. The one miss came from an agent running git commit, which moved the base the check compared from; changes now start from the commit an agent began on.
Where this check sits among others
| Check | When | What it catches | Who can fix it |
|---|---|---|---|
| Worktree or sandbox per agent | Throughout | Overwrites on disk | Nothing to fix |
| File claims | At each edit | One agent editing another's files | The agent, at once |
| Merge check before finishing | At the agent's Stop | Textual conflicts with peers | The agents, still running |
| Merge queue | At merge | Textual conflicts, tests in order | Whoever is around |
| Tests after merge (Anthropic) | After merge | Semantic breakage too | An agent started for it |
They combine. Claims stop most overlaps early. The merge check catches what claims missed while the authors can still act. Tests after the merge, or after forkit fanout collect --merge, catch changes that merge cleanly and still break.
A setup for a fan-out
- Start the fan-out:
forkit fanout create --name refactor --agents 8 --max-cost 10 --repo-from ./repo. - In each sandbox:
forkit init --sandbox, then start the agent with its key. - Leave
FORKIT_MERGE_CHECKat its default forfo_keys; setFORKIT_MERGE_WAIT=autoandFORKIT_MERGE_HOLDS=autoif agents finish at very different times. - Exclude generated files with
FORKIT_MERGE_EXCLUDE. - Collect:
forkit fanout collect ID ./out --merge. Agents whose branches still conflict are left as branches. - Run the full test suite on the merged result.
What is not covered
- Semantic conflicts: two changes that merge and break each other. No test is run on the combined code.
- Peers that started from another commit are reported, not compared.
- The automatic hold is in Claude Code's Stop hook. Other agents can run
forkit check-mergethemselves.
Related: how to run 50 coding agents without merge conflicts, git worktrees vs file leases, merge queue, post-merge tests or a merge check and we checked our merge check against 26 real merges.
Where Forkit fits
Forkit is the coordination system for agent teams: plans, handoffs, file claims and decisions, shared by every agent and the people behind them. The merge check tells agents, while they are still running, whether their work fits together. Forkit runs no agents; it checks the ones you run. It is free to try at forkit-mcp.com.
Sources
- Xu, Subramanian and Karthik, "AI Agent Pull Requests on GitHub: Frequency, Structure, and Merge Conflict Rates", arXiv 2607.04697v2, 7 Jul 2026, https://arxiv.org/html/2607.04697v2 (preprint; read 25 Nov 2026).
- Anthropic, "Redesigning source control at Anthropic", 13 Oct 2026, https://www.anthropic.com/research/redesigning-source-control (read 25 Nov 2026).
- Forkit, "Two Coding Agents, One Function: What We Learned Running CooperBench", 23 Nov 2026, /blog/two-agents-one-function-cooperbench.
- Forkit engineering notes (CLAUDE.md): "Would our work merge?", 23 Nov 2026; "Patches between agents", 23 Nov 2026.
forkit check-merge,forkit applyandforkit fanout collect, forkit-cli command reference, 25 Nov 2026.