Running several coding agents at once is one of the best ways to get more done with them. It’s also the fastest way to lose work, if they all run in the same folder. This guide explains what actually goes wrong, then the fixes, from plain git to tools that do it for you.
What goes wrong in a shared folder
When you start two agents in one checkout of a repository, they share three things: the working tree (the files on disk), the index (what’s staged for the next commit) and HEAD (the branch that’s checked out). Nothing in git or in most agents stops two of them from using those at the same time.
That leads to a handful of failures, roughly in order of how often people hit them.
Edits based on an old copy
An agent reads a file, decides on a change, then writes it. If another agent changed the file in between, the second change is based on an old copy. Depending on the agent and the edit, it either fails and has to re-read the file, or it quietly undoes the other agent’s work. The second case is the one that hurts, because nothing tells you it happened.
Formatters and code generators
Many projects run a formatter, a linter with auto-fix or a code generator over the whole tree. When one agent runs it, it rewrites files another agent is editing. The other agent then sees changes it didn’t make, and often “fixes” them back.
Shared files every task touches
Some files change in almost every task:
- lockfiles, like
package-lock.jsonorCargo.lock, rewritten whenever a dependency changes; - database migrations, often numbered in sequence, so two agents both create “migration 42”;
- registries: route tables, dependency injection setup, barrel files that re-export modules;
- changelogs and config files at the root of the project.
Two agents touching these at once is a conflict even when their real work is in different places.
Git commands that affect everyone
This is the one that surprises people most. Agents run git commands, and in a shared folder those commands affect every agent:
git add -Aorgit commit -astages and commits another agent’s half-finished changes;git checkoutorgit switchchanges the branch, and every file with it, under the other agent’s feet;git stash,git reset --hardorgit checkout -- .can throw away another agent’s uncommitted work entirely.
Edits that clash in meaning
Even when two agents never touch the same file, their work can clash. One renames a function, and the other adds three new calls to the old name. Each change is fine on its own. Together, the build breaks.
How to stop it
1. Give each agent its own git worktree
A git worktree is a second (or third, or tenth) folder for the same repository, checked out on its own branch. Each worktree has its own working tree, its own index and its own HEAD, while sharing the repository’s history. It’s built into git, and it’s the standard fix.
# From your main checkout: one folder and one branch per agent
git worktree add ../myapp-search -b agent/search
git worktree add ../myapp-billing -b agent/billing
# Start an agent in each folder
cd ../myapp-search && claude
A few things to know:
- Each worktree needs its own setup. Untracked files like
.envaren’t copied, and dependency folders likenode_modulesaren’t shared. Install and copy what the project needs to run. - Dev servers need different ports if several agents run the app at once.
- A branch can only be checked out in one worktree at a time. Give each agent a new branch.
- Clean up when you’re done with
git worktree remove <path>, and list them withgit worktree list. Git won’t remove a worktree with uncommitted changes, so you can’t lose work that way.
The guide to git worktrees for Claude Code goes through this step by step.
2. Split the work by area
Worktrees stop agents from overwriting each other while they work. They don’t stop conflicts at merge time. The more two agents’ changes overlap, the bigger the merge.
So give each agent a clear area: the search feature, the billing page, the API client. Say it in the prompt, including what not to touch. Tasks that cut across the whole codebase, like a rename or a dependency upgrade, are best done by one agent while the others wait, or done first.
3. Give shared files one owner
Decide which agent owns each shared file. For lockfiles, it’s often simplest to let agents change the dependency manifest, then regenerate the lockfile once after merging. For migrations, let one agent create them, or renumber them at merge time.
4. Keep git commands out of shared folders
If agents do share a folder, tell them not to run commands that affect the whole tree: no git add -A, no branch switching, no stash or reset. With Claude Code, the place for that is the project’s CLAUDE.md. It’s a safety net, not a guarantee, which is why worktrees come first.
5. Merge one at a time
When agents finish, merge their branches into main one by one. After each merge, bring the remaining branches up to date with the new main (git rebase main in each worktree, or merge main into them) and run the tests there. Conflicts show up one branch at a time, while they’re small, instead of all at once at the end.
6. Review as they go
The earlier you see what an agent is changing, the earlier you see it heading for another agent’s area. Watching the diff as it’s written is much cheaper than untangling two finished branches. More on that in reviewing AI-written code as it’s written.
How Tenfold handles it
Tenfold is a Mac app for running coding agents side by side, starting with Claude Code, and it builds these fixes in.
It notices overlaps as they happen. When two agents edit the same file in the same checkout, both get flagged: the Board tile says who else is editing the file, the Focus inspector shows an “Overlapping edits” banner naming it, and the Code layout counts and lists the overlaps. The banner has a Give one its own copy link that starts the second agent in a copy of its own.
It gives each agent its own copy in a few keys. In the New agent sheet (⌘N), choose Its own copy under Where it works, name the branch and press ⌘↩. Each copy is a git worktree, kept under ~/.tenfold/worktrees/ so it stays out of your project folder. When another agent already works in that repository, Tenfold marks its own copy as recommended.
It compares agents in separate copies too. When two agents touch the same files or lines on their branches, the git panel says so before either lands, with a line like “Pogo and Sprig are editing the same lines” and a “Will clash with Pogo” chip on the agent’s card.
It lands work carefully. When an agent is done, bring its work into main from its Board tile or the git panel. Tenfold checks for clashes with main first. If there are any, you settle them side by side in the agent’s own copy, and main isn’t touched. It can test the result on a fresh copy of main before it lands, then removes the agent’s copy and keeps a backup of the branch for 30 days. If main is protected on GitHub, it opens a pull request instead.
It also recognizes Claude Code sessions in worktrees you made yourself with git worktree add, so you can mix both ways of working. For the full picture, see running multiple Claude Code agents in parallel.