Start each session in its own git worktree with claude --worktree <name>, so every agent edits a separate copy of the files on its own branch. Worktrees stop agents overwriting each other’s files on disk, but two branches can still change the same lines, so give each agent its own part of the code and merge often.
When you want one Claude to split a task by itself, Claude Code also has subagents and the experimental agent teams. Here is how the four ways compare, as of 25 November 2026.
| Way | What it is | Who it suits | Stops same-file overwrites? | Stops duplicate work? |
|---|---|---|---|---|
| Worktrees | A separate checkout and branch for each session, from claude --worktree or git worktree add | Anyone running two or more sessions | Yes, on disk. Each session has its own files | No. Two branches can still change the same lines |
| Subagents | Helpers Claude starts inside one session, each with its own context | One person splitting one task | Only with isolation: worktree | Partly. The main session hands out the work |
| Agent teams (experimental) | A lead session plus teammates that share a task list and message each other | One person, on one machine, in an interactive session | No. Anthropic’s docs say two teammates editing one file leads to overwrites | Partly. Claiming a task uses file locking, so two teammates can’t claim the same one |
| Check-ins | Each agent says which repo, branch and files it is taking before it edits | A team, across laptops and tools | Not by itself. The second agent is told before it edits | Partly. A second agent hears who holds the files before it starts |
The first three rows are from Anthropic’s Claude Code docs on worktrees, subagents and agent teams, read in full on 25 November 2026.
How do you start each Claude Code session in its own worktree?
Pass --worktree, or -w, and a name. Claude Code creates the worktree under .claude/worktrees/<name>/ at the root of your repository, on a new branch called worktree-<name>, and starts the session there. Run each command in its own terminal:
claude --worktree billing claude --worktree search
A few points from Anthropic’s worktree docs save trouble later:
- Add
.claude/worktrees/to.gitignore, or the worktrees show up as untracked files in your main checkout. - A worktree is a fresh checkout. Install dependencies in it, and list gitignored files such as
.envin a.worktreeincludefile so Claude Code copies them in. - New worktrees branch from your repository’s default branch on the remote. Set
worktree.baseRefto"head"in your settings to branch from your current work instead. - When you leave an interactive worktree session, Claude Code removes a clean worktree and asks before removing one with work in it. Runs with
-pleave their worktrees in place, so remove those withgit worktree remove. - While a session runs in its worktree, Claude Code blocks edits and commands aimed at your main checkout, including git pointed there. It doesn’t follow every file a shell command writes, so a copy into the main checkout can still get through.
To use a branch that already exists, or to put the worktree somewhere else, create it with git and start Claude in it:
git worktree add ../app-billing billing cd ../app-billing claude
What happens when two sessions change the same line?
We tested it on 25 November 2026 with Claude Code 2.1.331. In a small repository whose src/price.js held TAX_RATE = 0.10, we started two sessions at the same moment, each in its own worktree, and asked one to set the rate to 0.15 and the other to 0.125, then commit. The prompts are shortened here:
claude -p --worktree tax-a "In src/price.js change TAX_RATE to 0.15, then commit." claude -p --worktree tax-b "In src/price.js change TAX_RATE to 0.125, then commit."
- Both finished within about ten seconds, each with its own commit on its own branch,
worktree-tax-aandworktree-tax-b. Neither touched the other’s files. - The main checkout still said 0.10.
git worktree listshowed both worktrees under.claude/worktrees/, marked locked, because runs with-pdon’t clean up after themselves.git statusin the main checkout listed.claude/as untracked, which is why the docs say to ignore it.- Merging the first branch into main went through. Merging the second stopped with a conflict in
src/price.js.
The worktrees did their job: no session overwrote another’s edit while they worked. The clash moved to the merge, where a person had to choose between 0.15 and 0.125. What prevents that is splitting the work so that no two agents touch the same files, which our guide on how to stop AI coding agents editing the same files covers in detail.
When should you use subagents instead?
When one task splits into parts that only need to report back. Subagents run inside your session, each with its own context, and return their results to the main conversation. Give a subagent its own worktree by adding isolation: worktree to its definition in .claude/agents/, or by asking Claude to “use worktrees for your agents”. When a subagent finishes, Claude Code keeps its worktree if it holds changes and can remove it if it doesn’t.
How do you turn on agent teams, and what are their limits?
Agent teams are experimental and off by default. Turn them on by setting CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS to 1, in your environment or in the env block of settings.json:
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
}
}
Then ask for teammates in plain words. One session acts as the lead: it creates a shared task list, starts the teammates and pulls their results together. Each teammate is a separate Claude Code session with its own context. It loads your CLAUDE.md, MCP servers and skills, but not the lead’s conversation, and it can message the other teammates directly. Teammates run inside your terminal by default, or in panes of their own with tmux or iTerm2. Anthropic suggests starting with three to five.
Turning the switch on also changes ordinary delegation: a subagent that Claude names launches as a teammate, so a team can form when you didn’t ask for one. Agent teams also use far more tokens than a single session, because every teammate is its own Claude instance.
The docs list these limits as of 25 November 2026:
- Teammates start only in an interactive session. With
-p, a teammate Claude names runs as an ordinary subagent. We saw this ourselves on 25 November 2026: with the switch on, a-prun that asked for two teammates got two ordinary subagents, and no team was created. /resumeand/rewinddon’t bring back teammates that ran inside your terminal.- Task status can lag, which can hold up the tasks that depend on it.
- Shutting teammates down can be slow.
- One team per session, no teams inside teams, and the lead can’t hand over.
- Teammates start with the lead’s permission mode.
- Split panes need tmux or iTerm2.
And as with worktrees, give each teammate its own files. The docs say plainly that two teammates editing the same file leads to overwrites.
What about agents on your teammates’ laptops?
Worktrees, subagents and agent teams all coordinate one person’s sessions on one machine. A team’s task list and messages live in your home folder, under ~/.claude/teams/ and ~/.claude/tasks/, and a session can have only one team. Your worktree list doesn’t show the branch a teammate’s agent started an hour ago on their laptop.
That is where check-ins help. Before an agent starts, it says which repo, branch and files it is taking, and a teammate’s agent that wants the same files hears about it first. Our guide on stopping AI coding agents editing the same files covers check-ins and the other habits that prevent collisions across a team.
Where does KoalaFix fit?
KoalaFix is a hosted MCP server that gives every agent on your team one shared memory and check-ins. Each agent checks in before it edits, with its repo, branch and files. When another agent already holds those files, it is told who holds what and which files are free. When nobody does, it just gets them. It works in Claude Code, Codex, Cursor, Claude, ChatGPT, OpenCode, GitHub Copilot and any MCP client, alongside worktrees and agent teams.
Add it to Claude Code with claude mcp add --transport http koalafix https://mcp.koalafix.com/mcp, then sign in from /mcp.
Related pages:
- How to stop AI coding agents editing the same files: worktrees, one owner per area, shared rules, shared decisions and check-ins.
- Tools that stop agents editing the same files, side by side on our compare page.
- KoalaFix for Claude Code: setup, and what Claude Code sends.
KoalaFix is opening soon. Join the waitlist to get in on launch day.