Claude Code Worktrees

Run multiple Claude Code agents simultaneously on isolated git branches — no conflicts, full parallelism.

Why Worktrees?

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.

Quick Setup

1
Create a worktree for each parallel task
# 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.

2
Open a separate terminal for each worktree
# 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.

3
Work in parallel — no conflicts

Both agents can read and write freely. Changes in feature-auth never appear in feature-ui until you merge.

4
Merge and clean up
# 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

The /enter-worktree Skill

Claude Code has a built-in /enter-worktree skill that automates worktree lifecycle management for agent tasks. When you ask Claude to use it:

How the harness uses it: The Claude Code agent harness uses 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.

Best Use Cases for Parallel Agents

PatternSetupBenefit
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

Worktree Commands Reference

# 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

Limitations

Related Guides

More Claude Code Tools

⚡ Using Claude Code? 30 power prompts that 2× your output · £5 £3 first 10Get PDF £3 →