Last month we gave two Claude Code agents a git worktree each and the same line to change. The collision showed up at merge time, as a conflict, and a person had to pick. The obvious next test is to skip the worktrees. Plenty of people open a second terminal in the same folder and start another session. On 3 December 2026 we did that 30 times. Our AI agent sessions ran the test under a founder's direction.
The setup
A throwaway repository with two files. src/price.js:
export const TAX_RATE = 0.10; export const SHIPPING = 5; and src/label.js:
export const LABEL = "Total"; For each run we made a fresh copy and started two claude -p sessions in it at the same moment. Claude Code 2.1.335, both sessions on Sonnet 5.5, file edits and git commands allowed without asking, our own settings and MCP servers kept out. Three pairs of jobs:
| Pair | Agent A | Agent B |
|---|---|---|
| Same line | TAX_RATE to 0.15 | TAX_RATE to 0.125 |
| Same file, different lines | TAX_RATE to 0.15 | SHIPPING to 7 |
| Different files | TAX_RATE to 0.15 | LABEL to "Grand total" |
Each pair ran five times with the commit command spelled out, as in the earlier post:
In src/price.js change TAX_RATE to 0.15. Then commit with git: git commit -am 'Tax 15'. Reply with the commit hash only. and five times with the agent left to choose the command:
In src/price.js change TAX_RATE to 0.15. Then commit your change with the message 'Tax 15'. Reply with the commit hash only. Thirty runs, no conflict
| Pair | Told to run git commit -am | Chose its own command |
|---|---|---|
| Same line | 5 of 5: the second commit replaced the first one's value | 5 of 5: the same |
| Same file, different lines | 3 of 5: one commit held both changes | 2 of 5: one commit held both changes. 3 of 5: an edit went missing |
| Different files | 5 of 5: one commit held both files | 5 of 5: two clean commits |
Git reported no merge conflict in any of the 30. There was nothing to merge. One branch, one working folder, and each commit went on top of the last.
Same line: the last one wins and says nothing
All ten runs ended the same way. The history reads like one person changing their mind:
commit febcf2d Tax 12.5 -export const TAX_RATE = 0.10; +export const TAX_RATE = 0.125; commit 2957708 Tax 15 -export const TAX_RATE = 0.125; +export const TAX_RATE = 0.15; Five runs ended at 15% and five at 12.5%. Which one we got depended on which session was a second slower.
In nine of the ten, the slower agent's edit failed, because the text it meant to replace was no longer in the file. It read the file again, found the other agent's number where 0.10 should have been, replaced that number with its own, and committed. In the tenth, both edits were reported as written, and the slower agent found out when its commit hit git's lock file. Then it did the same thing.
All 20 replies were a bare commit hash. None mentioned that a different value had been in the file a few seconds earlier. To be fair to the agents, we asked for the hash only. But in the other pairs they broke that format to warn us, and here they did not.
With worktrees, this exact pair of jobs ended in a merge conflict and somebody had to choose. Without them, nobody was asked.
Different files: the commit command decides
With git commit -am, all five runs produced one commit holding both files. -a stages every tracked file that has changed, and the other agent's file had changed. Four times the commit was named "Label" and carried the tax change as well. The other agent then found nothing left to commit and told us:
Another process made commit 90e7b4a, "Label", which includes both my `TAX_RATE = 0.15` change and an unrelated `src/label.js` change. In three of the five, the agent that made the commit also flagged the extra file. In the other two it replied with the hash and nothing else.
Left to choose, every session ran git add on its own file and then committed. Ten sessions, ten clean commits.
Same file, different lines: edits went missing
This is the pair that looks safe. Different lines, no overlap.
With -am, three of the five runs put both changes in one commit named "Tax 15".
Choosing their own command, the agents ran git add src/price.js. That stages the whole file, the other agent's line included, so two runs again put both changes under one name. In the other three, agent B's edit was reported as successful and then was not in the file. Both sessions had read the file and both wrote it back within a fraction of a second. The later write carried only its own change.
What happened next was different each time:
- Once the agent noticed when its commit found nothing to commit. It made the edit again and committed. Both replies were a bare hash, so nothing told us an edit had been lost and redone.
- Once its commit hit git's lock file. It read the file again, saw
SHIPPING = 5, stopped and asked what to do. That run ended with the shipping change never made. - Once it committed straight away, and its "Shipping 7" commit contained only the other agent's tax change. It checked, redid its edit and committed "Shipping 7" a second time. That repository has two commits called "Shipping 7" and none called "Tax 15".
What we take from it
- Sharing a folder does not fail loudly. In every one of the 30 runs the history looks normal and the working tree is clean.
- One worktree per agent for anything that writes. The merge conflict we got from worktrees last time is exactly what was missing here.
- If two sessions must share a folder, no
git commit -a. Stage by file name. That fixed the different-files pair and nothing else. - After an agent commits,
git show --stat HEADshows what the commit holds. It takes two seconds. - A bare commit hash as a reply means a commit exists. It does not tell you what the agent saw on the way.
The limits: one tiny repository, one model, five runs per cell, and both sessions started in the same instant, which is the worst case. Sessions started a minute apart would mostly see each other's finished commits.
The worktree setup that avoids all of this is in our guide, How to run several Claude Code agents at once without collisions.
Disclosure
We build KoalaFix, a tool for coordinating a team's AI coding agents, so we have an interest in this topic. Weigh what we say with that in mind.
This post was drafted with AI assistance and checked by a founder.
