Short answer: no single thing stops it. A git worktree for each agent stops overwrites on one machine. Nothing in git tells your agent what a teammate's agent is doing on another machine. For that, each agent has to say which files it is about to touch before it edits, somewhere the other agents can see.
I'm a co-founder of KoalaFix, which works on that last part, so weigh the end of this post with that in mind. Everything before it works with plain git and costs nothing.
Why this keeps happening
At my previous start-up, three of us ran AI coding agents all day, each in a different tool. For months they walked over each other's work. We found the clash at merge, or after we had shipped.
It comes down to three gaps:
- Two agents edit the same files at the same time.
- Agents can't see each other across people and tools.
- Agents work from decisions that have since changed.
It is not only us. A study of 33,596 pull requests opened by AI coding agents took a sample of 600 rejected ones. In 142 of them, the work already existed in another pull request.
1. Give each agent its own worktree
A worktree is a second checkout of the same repo, in its own folder, on its own branch. Two agents in two worktrees can't overwrite each other's files.
git worktree add ../app-billing -b billing
git worktree add ../app-search -b search
The limit: a worktree lives on one machine. It does nothing about your teammate's agent on their laptop. And two branches can still change the same function. You find that out at merge.
2. Give each area one owner
Most collisions are planning problems.
- Size each task so it touches its own part of the code.
- Files that every change touches go one task at a time. Lockfiles, migrations and shared config are the usual ones.
- Keep tasks small and merge often. A branch that lives for an hour collides less than one that lives for a week.
- Review an agent's branch the way you would review a teammate's pull request.
If you use CODEOWNERS and branch protection on GitHub, they back this up at review time.
3. Put the rules where every tool reads them
Your agents can't follow a convention they never see. Write it once, in the repo.
- Codex reads
AGENTS.md. - Cursor reads rules in
.cursor/rules, andAGENTS.mdtoo. - Claude Code reads
CLAUDE.md, and readsAGENTS.mdwhen a repo has noCLAUDE.md.
The limit: a rule is advice the agent reads at the start. It can say "don't touch the billing folder without asking". It can't say that someone's agent is in the billing folder right now.
4. Make agents say what they are about to touch
This is the part git doesn't have. There are two ways to do it.
File locks. The first agent takes the file, and other agents are turned away until it is released. Authora explains how this works, and their tool AgentSync does file locking.
Warnings and check-ins. Nothing is locked. The second agent is told who is already there before it edits, and it picks other work. Amoeba warns when two agents' work overlaps. KoalaFix, the one my team builds, does check-ins.
Locks are stricter. Check-ins are lighter. Pick by how strict your team wants it to be.
What we do
In July 2026 we made one rule. Before an agent touches anything, it says what it is about to do. If another agent is already checked in on those files, the new one is told before it starts. The collisions stopped.
That rule became KoalaFix. It is a hosted MCP server. Before its first edit, an agent tells it what it is working on and which files. Every other agent on the team can see that, and an agent about to start on the same thing is told first. It works with Claude Code, Codex, Cursor, Claude, ChatGPT, OpenCode, GitHub Copilot and any other MCP client, so each person keeps their own tool.
I wrote a longer guide with a side-by-side table. We also keep a comparison of the tools that work on this, ours included.
The checklist
- One worktree and one branch for each agent.
- One owner for each area of the code.
- Small tasks, merged often.
- Team rules in one file every tool reads.
- A check-in or a lock before every task.
How does your team handle it? I'd like to hear what has worked and what hasn't.
This post was drafted with AI help. The facts and links were checked against each source on November 30, 2026, and the experience in it is my team's.
Top comments (0)