Claude Code agent teams and worktrees: running parallel agents across a team without collisions
Worktrees keep one person's agents apart; Claude Code agent teams coordinate them. Tested: what neither covers, and how a whole team runs parallel agents without collisions.
By Scott Strang
Last updated
The short answer. Run each coding agent in its own git worktree on its own branch, so parallel agents never edit the same checkout. Claude Code's agent teams coordinate one person's agents inside one session; they don't see a teammate's agents, and neither do worktrees or subagents. For a team, commit and push each agent's branch after its first change, and before the next agent starts, check which files teammates' pushed branches already touch: a worktree moves a collision to merge time; it doesn't prevent it.
Claude Code, Codex and Cursor each run agents in parallel, and none of them sees your teammate's agents
Every coding tool now runs several agents at once. They differ in who coordinates and whether each agent gets its own copy of the code.
| Way | What it is | Own copy of the code? | Reaches a teammate's agents? |
|---|---|---|---|
| Claude Code subagents | Helpers inside one session that do a side task and report back | Only if you ask for worktrees | No |
| Claude Code agent teams | A lead session that spawns teammate sessions with a shared task list and messages. Experimental, off by default | No: the docs say to split files between teammates | No: one team per session |
| Claude Code agent view | One screen (claude agents) to dispatch and watch background sessions. Research preview | Yes: a dispatched session moves into its own worktree before it edits | No |
Claude Code --worktree sessions | Sessions you start yourself, each in .claude/worktrees/ on its own branch | Yes | No |
| Codex app worktrees | Worktree chats in the Codex app (ChatGPT desktop), stored in $CODEX_HOME/worktrees | Yes | No |
| Cursor worktrees | Agents in Cursor's Agents Window, each in its own checkout | Yes | No |
From each vendor's docs, read Nov 20, 2026; Claude Code --worktree also tested (2.1.283). These tools change often, so check the date.
Claude Code's cross-session messaging can pass notes between sessions, even on another machine or in the cloud, but only sessions you run yourself.
A worktree isolates files, not merges, ports or your .env
A git worktree is a second checkout of the same repository, on its own branch, sharing one history. It's the fix Claude Code's, Codex's and Cursor's docs all recommend, and it works for what it covers. We tested what it does and doesn't isolate.
| What two branches in two worktrees did (scripted edits standing in for agents) | Result |
|---|---|
| Edited the same function, one in each worktree | ✅ no overwrite while they worked |
| Merged both branches | ❌ CONFLICT (content): Merge conflict in price.js |
| Started a dev server on the same port | ❌ Address already in use |
Looked for the gitignored .env | ❌ not there |
| Checked out the same branch in a second worktree | ❌ git refuses: already checked out |
Used Claude Code's .worktreeinclude to copy .env | ✅ copied |
Ran claude -w headless (-p) | ⚠️ worktree left behind, locked |
Run on Nov 20, 2026 with git and Claude Code 2.1.283 on macOS, in throwaway repos. Every result matches the git and Claude Code docs.
A worktree stops agents overwriting each other's files. The collision still comes at merge time, and anything the machine shares (ports, a local database, caches, background services) still clashes.
Give every agent its own worktree
Claude Code. Ignore the worktree folder once, then start each agent with a name:
echo ".claude/worktrees/" >> .gitignore
claude --worktree tax # creates .claude/worktrees/tax on branch worktree-tax
claude --worktree discount # in a second terminal
claude --worktree "#1234" # or start from a pull requestNew worktrees branch from your default branch. To branch from where you are instead, set worktree.baseRef to "head" in Claude Code's settings. To give subagents their own worktrees too, ask Claude to "use worktrees for your agents".
Codex CLI. Newer versions have codex --worktree, which starts a session in a managed worktree. To pick the branch and folder yourself, make the worktree with git, then start Codex in it:
git worktree add ../myapp-tax -b tax
codex -C ../myapp-taxIn the Codex app, pick Worktree under the composer instead. In Cursor, start the agent in a worktree from the Agents Window.
Install dependencies and bring your ignored files. A worktree is a fresh checkout: no node_modules, no .env. Run your setup (for example npm install) in each new worktree. Claude Code's --worktree and the Codex app's managed worktrees both copy gitignored files listed in a .worktreeinclude file at the repo root, in .gitignore syntax:
# .worktreeinclude
.env
.env.localA worktree you make yourself with git worktree add doesn't read it, and neither does codex --worktree in the Codex CLI, so copy .env and any other ignored files the app needs in yourself. Cursor uses a setup script in .cursor/worktrees.json instead.
Give each worktree its own port and database. After .env is copied, change the port and database name in that worktree's copy, so two agents running the app don't fight over one server.
Clean up. When an interactive Claude Code session exits, it removes a clean worktree (a named session asks first) or asks about one with work in it. Headless runs and worktrees you made with git stay until you remove them:
git worktree list
git worktree remove ../myapp-tax # add --force if it has uncommitted work you don't need
git worktree unlock <path> # if git says the worktree is locked
git worktree prune # forget worktrees whose folders are goneGive every agent its own files
Worktrees keep agents apart while they work; ownership keeps them apart at merge. Before you start several agents, split the work so each one owns a different set of files.
Some files every task wants to touch. Change those one at a time, in one agent, and merge each change before the others need it:
- lockfiles (
package-lock.json,pnpm-lock.yaml) - database migrations and schema files
- registries, routers and other files every feature adds a line to
- generated files
- the instruction files:
AGENTS.md,CLAUDE.md
Merge small and often. A branch that lives for an hour conflicts with less than one that lives for a week. Review each branch before it merges; an agent that says it's done hasn't proved it.
Claude Code agent teams vs subagents, and how to turn agent teams on
Subagents report back to the session that started them. Agent teams' sessions message each other and share a task list, and they share one checkout, so ownership matters even more: Claude Code's docs warn that "Two teammates editing the same file leads to overwrites." The docs also say agent teams use more tokens and fit best when teammates can work independently; for sequential work, same-file edits or many dependencies, use one session or subagents.
Agent teams are experimental and off by default. To turn them on:
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1or put the same key under "env" in settings.json. Then ask Claude to spawn a team. Agent-team sessions run inside your terminal; split panes need tmux or iTerm2.
How we do it: two people, 34 sessions, 5 shared files in a week
In the seven days to Nov 20, 2026, two people's agents worked on the same 5 files in our go-to-market data repo, one of them
AGENTS.md, even though their agents had posted 98 notes on what they were doing.
That repo, where this guide was written, runs parallel agents all day: 34 recorded agent sessions that week. Of the 98 notes, 28 named the files they were about to touch, and another five said which files they were staying out of because another session held them.
Parallel agents make one engineer a team, and nobody else can see it
The same afternoon, 19 pull requests were open and 110 files were changed by two or more of them. Most of that overlap was one person's own agents: one registry file sat in 8 open pull requests, and the laptop this guide was written on holds 138 worktrees of that one repo. Parallel agents give a single engineer the merge conflicts a whole team used to have. Then two or three teammates each do the same.
| Agent | src/price.js | src/registry.js | AGENTS.md |
|---|---|---|---|
| Ana · agent 1 | ● | ||
| Ana · agent 2 | ● | ||
| Ana · agent 3 | ● | ||
| Ben · agent 1 | ● | ||
| Ben · agent 2 | ● | ||
| Ben · agent 3 |
Illustration: two teammates, six agents in six worktrees, two files that both people's agents change. Neither laptop shows the other's agents.
Nothing on Ana's laptop knows what Ben's agents are doing, so she finds out in review, after both agents have rewritten the same function. Agent teams, subagents and worktrees all stop at one person. The only place both laptops meet is the shared remote, so that's where the team fix goes.
The team-sized fix: push after the first change, check before the next agent starts
Three habits and one small script, with git alone:
- Commit and push the branch as soon as the agent changes its first file, not when it's done.
git pushonly sends commits, so uncommitted edits stay invisible to everyone else. Open it as a draft pull request if your team reviews there. A pushed branch is how teammates see your agent's files. - Before an agent starts, check what pushed branches already touch. The script below compares the files you're about to change (or your branch's changes so far) with every branch on the remote, and exits 1 if anyone else is in them. It sees only what teammates have committed and pushed; their unpushed local work is invisible to it.
- Agree who owns the shared files (lockfiles, migrations, registries), and keep that list in
AGENTS.mdso every agent reads it.
Save this as scripts/who-else.sh and make it executable (chmod +x scripts/who-else.sh):
#!/usr/bin/env bash
# scripts/who-else.sh: list teammates' pushed branches that touch the same files as yours.
# Usage: scripts/who-else.sh # your branch's changes vs every remote branch
# scripts/who-else.sh path/a path/b # the files you're about to touch
set -euo pipefail
base="${BASE:-origin/main}"
git fetch -q --prune origin 2>/dev/null ||
echo "warning: git fetch failed; using remote branches from your last fetch" >&2
me=$(git rev-parse --abbrev-ref HEAD)
if [ "$#" -gt 0 ]; then
mine=$(printf '%s\n' "$@" | sort -u)
else
mine=$( { git diff --name-only "$base"...HEAD; git diff --name-only HEAD; } | sort -u)
fi
[ -n "$mine" ] || { echo "No changed files yet. Pass the files you plan to touch."; exit 0; }
found=0
for ref in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin); do
case "$ref" in "$base"|origin/HEAD|origin|"origin/$me") continue;; esac
theirs=$( { git diff --name-only "$base...$ref" 2>/dev/null || true; } | sort -u)
both=$(comm -12 <(echo "$mine") <(echo "$theirs"))
if [ -n "$both" ]; then
found=1
who=$(git log -1 --format='%an, %cr' "$ref")
echo "$ref ($who) also touches:"; echo "$both" | sed 's/^/ /'
fi
done
[ "$found" -eq 0 ] && echo "No pushed branch touches your files." || exit 1We tested it with two simulated teammates (two clones of one shared remote on one Mac, scripted edits standing in for agents), on macOS bash 3.2 and 5.3. "Ana" pushed her branch; "Ben" ran scripts/who-else.sh src/price.js before starting and got origin/tax (Ana, 0 seconds ago) also touches: src/price.js, exit 1. When Ben's change went to another file, it printed No pushed branch touches your files., exit 0. When he edited price.js anyway, the check caught it from the diff. Then we gave fresh Claude Code and Codex runs only this guide and a repo where a teammate's branch already held src/price.js: both set the repo up, ran the check before editing, and stopped.
If your main branch isn't main, run it as BASE=origin/master scripts/who-else.sh. It needs bash: on Windows, run it in Git Bash or WSL.
Put the habit where every agent reads it, in AGENTS.md:
## Working in parallel
- Work only in your own worktree and branch.
- Before editing, run `scripts/who-else.sh <files you plan to change>`.
If it exits 1, tell me who else is in those files and stop.
- Commit and push after your first change, then after each step.
- Shared files (lockfiles, migrations, src/registry/*) belong to one task at a time. Ask first.If your team runs Claude Code and Codex side by side, keep that block in the one rules file both read: see Claude Code and Codex together on one team.
Done means a teammate's agent, starting tomorrow in another checkout, stops before it edits a file that your agent has already committed and pushed.
Where SageOx helps
SageOx is not an agent. It's a tool-agnostic context layer that keeps teams of humans and agents coordinated, so every person and every agent knows what the team knows. For parallel agents, it puts each agent's work in progress where every teammate's agents can see it, without waiting for a push.
- Murmurs: an agent posts a short note ("wip: tax,
src/price.js") that teammates and their agents see. Notes expire. - Whispers: teammates' notes arrive inside a running agent session, so an agent learns what teammates' agents are working on, and which files when the notes name them, while it works.
ox glance: lists the team's recent notes and flags files more than one person is working on.- Plan enrichment: flags active work by others that collides with a draft plan, before any code exists.
- Team mural: a picture of what moved on the team. Once an admin connects Slack, selects the destination channel and enables nightly team murals for it, the mural posts there, so a lead who isn't running agents sees what's in flight too.
In the repo where we wrote this guide, ox glance --since 7d listed the 5 shared files above and said "coordinate now". The agent session that drafted this guide started with 16 notes from other running sessions, two of them naming files they were staying out of. Checked Nov 20, 2026.
See how a team stays in the loop →
Have your agent do it
Paste this into Claude Code, Codex or Cursor at the root of a repo. It commits nothing until you've seen the diff.
Set this repo up so several people can each run parallel coding agents without collisions.
1. Add .claude/worktrees/ to .gitignore if it isn't there.
2. List the gitignored files a fresh checkout needs to run (.env and similar). Put them in
a .worktreeinclude file at the root. Never copy secrets into tracked files.
3. Tell me which settings in those files a second copy of the app would clash on
(port, database name, cache folders) and how to change them per worktree.
4. List the files most tasks touch (lockfiles, migrations, registries, routers, generated
files, AGENTS.md). Use git log to find the ones changed by the most branches.
5. Add scripts/who-else.sh with exactly this content (without the 3-space indent), make it executable, and run it once:
#!/usr/bin/env bash
# scripts/who-else.sh: list teammates' pushed branches that touch the same files as yours.
# Usage: scripts/who-else.sh # your branch's changes vs every remote branch
# scripts/who-else.sh path/a path/b # the files you're about to touch
set -euo pipefail
base="${BASE:-origin/main}"
git fetch -q --prune origin 2>/dev/null ||
echo "warning: git fetch failed; using remote branches from your last fetch" >&2
me=$(git rev-parse --abbrev-ref HEAD)
if [ "$#" -gt 0 ]; then
mine=$(printf '%s\n' "$@" | sort -u)
else
mine=$( { git diff --name-only "$base"...HEAD; git diff --name-only HEAD; } | sort -u)
fi
[ -n "$mine" ] || { echo "No changed files yet. Pass the files you plan to touch."; exit 0; }
found=0
for ref in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin); do
case "$ref" in "$base"|origin/HEAD|origin|"origin/$me") continue;; esac
theirs=$( { git diff --name-only "$base...$ref" 2>/dev/null || true; } | sort -u)
both=$(comm -12 <(echo "$mine") <(echo "$theirs"))
if [ -n "$both" ]; then
found=1
who=$(git log -1 --format='%an, %cr' "$ref")
echo "$ref ($who) also touches:"; echo "$both" | sed 's/^/ /'
fi
done
[ "$found" -eq 0 ] && echo "No pushed branch touches your files." || exit 1
6. Add a "Working in parallel" section to AGENTS.md: own worktree and branch, run
scripts/who-else.sh before editing, commit and push after the first change, shared files one task
at a time. If CLAUDE.md is a separate file, tell me; don't create a second copy of the rules.
7. Run git worktree list and tell me which worktrees look finished or abandoned.
Don't remove any.
Show me the diff before committing anything.Questions
Can Claude Code agent teams include my teammates? No. An agent team is a lead session plus the teammate sessions it spawns for you, and a session has exactly one team that can't be shared across sessions. Your teammates' agents are outside it.
What's the difference between Claude Code agent teams and subagents? Subagents are helpers that report back to the session that started them. Agent teams are separate sessions that message each other and share a task list; they cost more tokens, and they're experimental and off by default.
Can I use git worktrees to run multiple Claude Code sessions in parallel?
Yes: claude --worktree <name> in each terminal. Each session gets its own folder under .claude/worktrees/ and its own branch.
Do worktrees prevent merge conflicts? No. They stop agents overwriting each other's files while they work, but two branches that change the same lines still conflict when you merge.
Do agent teams work on Windows? Claude Code's docs don't mention Windows. They say the default mode, where teammates run inside your main terminal, works in any terminal; split panes need tmux or iTerm2, and iTerm2 is macOS only.
Related guides
- Advice · Claude Code and Codex together on one team: standardize the files, not the tool
- How-to · CLAUDE.md and AGENTS.md: keeping them right for a whole team
- Template · A decision log people and agents both use
Sources
Read Nov 20, 2026: Claude Code: run agents in parallel · Claude Code agent teams · Claude Code worktrees · Codex worktrees · Cursor worktrees · git worktree · git push · SageOx Slack integration. Tests: git and Claude Code 2.1.283 on macOS, bash 3.2 and 5.3; agent test in Claude Code 2.1.283 and Codex CLI 0.146.0; Nov 20, 2026. Codex app and Cursor not tested.

