Zwei Claude-Code-Agenten im selben Ordner: Git meldete in 30 Laeufen nie einen Konflikt
Ein Test liess zwei Claude Code agents ohne separate Worktrees im selben Ordner 30-mal dieselbe Zeile aendern. Beim vorherigen Versuch mit je einem Worktree fuehrte das beim Merge zu einem Konflikt, der manuell aufgeloest werden musste; ohne Worktrees entstand kein Konflikt.

Im letzten Monat gaben wir zwei Claude-Code-Agents jeweils ein git worktree und dieselbe Zeile zum Ändern. Die Kollision zeigte sich beim Merge als Konflikt, und ein Mensch musste entscheiden. Die naheliegende nächste Prüfung besteht darin, auf die Worktrees zu verzichten. Viele Menschen öffnen ein zweites Terminal im selben Ordner und starten dort eine weitere Session. Am 3. Dezember 2026 haben wir das 30-mal getan. Unsere KI-Agent-Sessions führten den Test unter der Anleitung eines Gründers durch.
Ein Wegwerf-Repository mit zwei Dateien. src/price.js:
export const TAX_RATE = 0.10; export const SHIPPING = 5; Enter fullscreen mode Exit fullscreen mode und src/label.js:
export const LABEL = "Total"; Enter fullscreen mode Exit fullscreen mode Für jeden Durchlauf erstellten wir eine frische Kopie und starteten darin gleichzeitig zwei claude -p Sessions. Claude Code 2.1.335, beide Sessions auf Sonnet 5.5, Dateibearbeitungen und git-Befehle ohne Rückfrage erlaubt, unsere eigenen Einstellungen und MCP-Server außen vor gelassen. Drei Paare von Aufträgen:
Jedes Paar lief fünfmal mit ausgeschriebenem Commit-Befehl, wie im früheren Beitrag:
Ändere in src/price.js TAX_RATE auf 0.15. Commite dann mit git: git commit -am 'Tax 15'. Antworte nur mit dem Commit-Hash. Enter fullscreen mode Exit fullscreen mode und fünfmal, wobei der Agent den Befehl selbst wählen durfte:
Ändere in src/price.js TAX_RATE auf 0.15. Commite deine Änderung dann mit der Message 'Tax 15'. Antworte nur mit dem Commit-Hash. Enter fullscreen mode Exit fullscreen mode Dreißig Durchläufe, kein Konflikt Paar git commit -am vorgegeben Wählte eigenen Befehl Dieselbe Zeile 5 von 5: der zweite Commit ersetzte den Wert des ersten 5 von 5: genauso Dieselbe Datei, verschiedene Zeilen 3 von 5: ein Commit enthielt beide Änderungen 2 von 5: ein Commit enthielt beide Änderungen. 3 von 5: eine Änderung ging verloren Verschiedene Dateien 5 von 5: ein Commit enthielt beide Dateien 5 von 5: zwei saubere Commits Git meldete in keinem der 30 Durchläufe einen Merge-Konflikt. Es gab nichts zu mergen. Ein Branch, ein Arbeitsverzeichnis, und jeder Commit kam oben auf den vorherigen.
Alle zehn Durchläufe endeten auf dieselbe Weise. Die Historie liest sich wie eine Person, die es sich anders überlegt:
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; Enter fullscreen mode Exit fullscreen mode Fünf Durchläufe endeten bei 15% und fünf bei 12,5%. Welchen Wert wir bekamen, hing davon ab, welche Session eine Sekunde später war.
In neun der zehn Fälle schlug die Änderung des langsameren Agenten fehl, weil der Text, den er ersetzen wollte, nicht mehr in der Datei stand. Er las die Datei erneut, fand die Zahl des anderen Agenten dort, wo 0.10 hätte stehen sollen, ersetzte diese Zahl durch seine eigene und committete. Im zehnten Fall wurde bei beiden Änderungen gemeldet, sie seien geschrieben worden, und der langsamere Agent bemerkte es erst, als sein Commit auf gits Lock-Datei stieß. Danach machte er dasselbe.
Alle 20 Antworten bestanden aus einem nackten Commit-Hash. Keine erwähnte, dass wenige Sekunden zuvor ein anderer Wert in der Datei gestanden hatte. Um fair gegenüber den Agenten zu sein: Wir hatten nur den Hash angefordert. Aber bei den anderen Paaren durchbrachen sie dieses Format, um uns zu warnen, und hier taten sie es nicht.
Mit Worktrees endete genau dieses Paar von Aufträgen in einem Merge-Konflikt, und jemand musste wählen. Ohne sie wurde niemand gefragt.
Mit git commit -am erzeugten alle fünf Durchläufe einen Commit, der beide Dateien enthielt. -a stagt jede veränderte, getrackte Datei, und die Datei des anderen Agenten hatte sich verändert. Viermal hieß der Commit "Label" und enthielt zusätzlich die Steueränderung. Der andere Agent fand dann nichts mehr zum Committen und teilte uns mit:
Ein anderer Prozess hat Commit 90e7b4a, "Label", erstellt, der sowohl meine Änderung `TAX_RATE = 0.15` als auch eine nicht dazugehörige Änderung an `src/label.js` enthält. Enter fullscreen mode Exit fullscreen mode In drei der fünf Fälle wies auch der Agent, der den Commit erstellt hatte, auf die zusätzliche Datei hin. In den anderen beiden antwortete er nur mit dem Hash und sonst nichts.
Durften sie selbst wählen, führte jede Session git add für ihre eigene Datei aus und committete dann. Zehn Sessions, zehn saubere Commits.
Dies ist das Paar, das sicher aussieht. Verschiedene Zeilen, keine Überschneidung.
Mit -am landeten in drei der fünf Durchläufe beide Änderungen in einem Commit namens "Tax 15".
Mit selbst gewähltem Befehl führten die Agenten git add src/price.js aus. Das stagt die gesamte Datei, die Zeile des anderen Agenten eingeschlossen, sodass in zwei Durchläufen erneut beide Änderungen unter einem Namen landeten. In den anderen drei wurde die Änderung von Agent B als erfolgreich gemeldet und war dann nicht in der Datei. Beide Sessions hatten die Datei gelesen und schrieben sie innerhalb eines Sekundenbruchteils zurück. Das spätere Schreiben enthielt nur die eigene Änderung.
Was danach geschah, war jedes Mal anders:
Die Grenzen: ein winziges Repository, ein Modell, fünf Durchläufe pro Zelle, und beide Sessions starteten im selben Moment, was der Worst Case ist. Sessions, die eine Minute versetzt gestartet würden, würden die fertigen Commits der jeweils anderen meist sehen.
Das Worktree-Setup, das all das vermeidet, steht in unserem Leitfaden, How to run several Claude Code agents at once without collisions.
Wir bauen KoalaFix, ein Werkzeug zur Koordination der KI-Coding-Agents eines Teams, und haben daher ein eigenes Interesse an diesem Thema. Wägen Sie ab, was wir sagen, mit diesem Wissen.
Dieser Beitrag wurde mit KI-Unterstützung verfasst und von einem Gründer geprüft.
Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.
Original (Englisch) anzeigen
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.
A throwaway repository with two files. src/price.js:
export const TAX_RATE = 0.10; export const SHIPPING = 5; Enter fullscreen mode Exit fullscreen mode and src/label.js:
export const LABEL = "Total"; Enter fullscreen mode Exit fullscreen mode 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:
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. Enter fullscreen mode Exit fullscreen mode 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. Enter fullscreen mode Exit fullscreen mode 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.
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; Enter fullscreen mode Exit fullscreen mode 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.
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. Enter fullscreen mode Exit fullscreen mode 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.
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:
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.
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.