Run multiple Claude Code agents simultaneously on isolated git branches — no conflicts, full parallelism.
By default, a single Claude Code session works in your repo's main working directory. If you open a second session in the same directory while the first is running, both agents edit the same files — leading to conflicts and overwritten work.
Git worktrees solve this: each worktree is a separate directory checked out to its own branch. Each Claude Code session gets full isolation. You can run 3, 4, or more parallel agents without any interference.
# Create worktree + new branch in one command
git worktree add ../feature-auth -b feature/auth
git worktree add ../feature-ui -b feature/ui
This creates two sibling directories: ../feature-auth/ and ../feature-ui/, each on their own branch.
# Terminal 1
cd ../feature-auth && claude
# Terminal 2
cd ../feature-ui && claude
Each session starts with a fresh context. They share git history but have fully separate working files.
Both agents can read and write freely. Changes in feature-auth never appear in feature-ui until you merge.
# In your main repo directory:
git merge feature/auth
git merge feature/ui
# Remove the worktrees when done
git worktree remove ../feature-auth
git worktree remove ../feature-ui
# Delete the branches
git branch -d feature/auth feature/ui
Claude Code has a built-in /enter-worktree skill that automates worktree lifecycle management for agent tasks. When you ask Claude to use it:
EnterWorktree internally when spawning subagents with isolation: "worktree". This is how the system runs experiments and moonshot tasks without risking the main working tree. You can invoke the same mechanism with /enter-worktree in your session.
| Pattern | Setup | Benefit |
|---|---|---|
| A/B implementation | Two worktrees, same prompt to both agents | Compare two solutions; pick the better one |
| Independent features | One worktree per feature | No coordination needed; merge at end of day |
| Test + fix | Agent 1: write tests. Agent 2: fix code | Tests and fixes land on separate branches; merge both |
| Refactoring passes | Agent 1: clean module A. Agent 2: clean module B | Large refactors complete in half the wall-clock time |
| Research + implement | Agent 1 explores approach. Agent 2 implements known solution | Parallel discovery without blocking shipping |
# Create worktree + new branch
git worktree add <path> -b <branch-name>
# Create worktree from existing branch
git worktree add <path> <existing-branch>
# List all worktrees
git worktree list
# Remove a worktree (directory must be clean)
git worktree remove <path>
# Force-remove (discards uncommitted changes)
git worktree remove --force <path>
# Prune stale worktree refs
git worktree prune
.git directory is shared — git operations that modify global state (e.g. config changes) affect all worktrees./main/ and ../feature-auth/ have different memory paths. Memories written in a worktree won't appear in the main tree's sessions.