Skip to main content

Overview

Parallel Worktrees enables zero dead time in your coding workflow. While one session runs tests, compiles code, or explores approaches, work on something else in a parallel worktree.
Zero dead time. While one Claude thinks, work on something else.

Trigger

Use when:
  • Waiting on tests (2+ minutes)
  • Long builds or compilation
  • Exploring multiple approaches simultaneously
  • Needing to review and develop at the same time
  • Blocked on CI/CD pipeline
claude --worktree    # or claude -w (auto-creates isolated worktree)

Quick Start

Claude Code

# Create isolated worktree and start session
claude -w

# Claude Code auto-creates, manages, and cleans up the worktree
# Each session gets its own isolated working copy
Key features (Claude Code-specific):
  • claude -w auto-creates and cleans up worktrees
  • Subagents support isolation: worktree in agent frontmatter
  • Ctrl+F kills all background agents (two-press confirmation)
  • Ctrl+B sends a task to background

Cursor / Any Editor

# Manually create worktrees
git worktree add ../project-feat feature-branch
git worktree add ../project-fix bugfix-branch

# Open each worktree in a separate editor window
code ../project-feat
code ../project-fix
Both approaches create isolated working copies where changes don’t interfere with your main session.

Workflow

1

Show Current Worktrees

Check what worktrees already exist
git worktree list
Output:
/Users/you/project       a3f5c21 [main]
/Users/you/project-feat  b7d4e92 [feature-branch]
/Users/you/project-fix   c8e1a43 [bugfix-branch]
2

Create Worktree

Add a new worktree for the parallel task
# From existing branch
git worktree add ../project-feat feature-branch

# Create new branch
git worktree add ../project-exp -b experiment

# From specific commit
git worktree add ../project-old abc123
3

Open New Session

Start a new editor/terminal session in the worktree
cd ../project-feat
claude  # or open in Cursor
4

Work Independently

Both sessions work independently:
  • Separate working directories
  • Separate git state (staged changes, current branch)
  • Separate editor state
  • Shared git history and config
5

Clean Up When Done

Remove worktree after completing work
# Check for uncommitted changes first
git -C ../project-feat status

# Remove worktree
git worktree remove ../project-feat

# Clean up stale references
git worktree prune

Usage Pattern

Terminal Layout

Terminal 1: ~/project          → Main work (feature development)
Terminal 2: ~/project-feat     → Feature branch (parallel feature)
Terminal 3: ~/project-fix      → Bug fixes (urgent fix while tests run)
Each terminal runs its own AI session independently.

Typical Workflow

When to Parallelize

ScenarioAction
Tests running (2+ min)Start new feature in worktree
Long buildDebug issue in parallel
Exploring approachesCompare 2-3 simultaneously
Review + new workReviewer in one, dev in other
Waiting on CIStart next task in worktree
Context switchingKeep both contexts alive

Commands

Create Worktrees

# From existing branch
git worktree add ../project-feat feature-branch

# Create new branch
git worktree add ../project-exp -b experiment

# From specific commit
git worktree add ../project-hotfix abc123 -b hotfix/critical-bug

# With custom path
git worktree add /tmp/project-temp main

List Worktrees

git worktree list

# Verbose (show locked status)
git worktree list --porcelain

Remove Worktrees

# Remove specific worktree
git worktree remove ../project-feat

# Force remove (even with uncommitted changes)
git worktree remove ../project-feat --force

# Clean up stale references
git worktree prune

Check Worktree Status

# From any location
git -C ../project-feat status
git -C ../project-feat log --oneline -5

Claude Code Extras

These features are Claude Code-specific (skip if using Cursor):

Auto-Managed Worktrees

# Claude Code handles everything
claude -w

# Behind the scenes:
# 1. Creates worktree in temp location
# 2. Checks out current or new branch
# 3. Opens session in worktree
# 4. Cleans up on exit

Background Agent Management

# Send current task to background
Ctrl+B

# Kill all background agents
Ctrl+F  # Press twice to confirm

# Background agents appear in session list
claude sessions

Subagent Worktree Isolation

In agent frontmatter:
---
name: scout
description: Explore codebase for patterns
background: true
isolation: worktree
---
Benefits:
  • Scout agent gets its own worktree automatically
  • No interference with main session
  • Can make exploratory changes safely
  • Auto-cleanup when agent completes

Guardrails

Important worktree rules:
Changes are isolated. Commits in one worktree don’t appear in another until pushed/pulled.
Before removing a worktree, verify no uncommitted work:
git -C ../project-feat status
Don’t forget to remove worktrees:
git worktree prune
Stale worktree references can cause confusion.
Don’t edit the same files in multiple worktrees simultaneously. Last commit wins, others will conflict.
Git won’t let you checkout the same branch in multiple worktrees:
# Error: 'main' is already checked out at '/Users/you/project'
git worktree add ../project-2 main

Examples

Example 1: Tests Running

# Terminal 1: Main session
$ npm test
# ... tests running (2 minutes) ...

# Terminal 2: Create worktree for parallel work
$ git worktree add ../project-feat -b feat/new-endpoint
Preparing worktree (new branch 'feat/new-endpoint')
HEAD is now at a3f5c21 feat: add user auth

$ cd ../project-feat
$ claude

Claude: What should we work on?

User: Implement the new API endpoint for user preferences

Claude: [Implements feature while tests run in main session]

# Terminal 1: Tests complete
 All tests passed

# Return to main session, handle test results
# Worktree session continues independently

Example 2: Exploring Approaches

# Try 3 different approaches in parallel

$ git worktree add ../project-approach-1 -b experiment/approach-1
$ git worktree add ../project-approach-2 -b experiment/approach-2
$ git worktree add ../project-approach-3 -b experiment/approach-3

# Open each in separate terminal/editor
# Implement different solutions
# Compare results, keep the best one
# Delete the others

$ git worktree remove ../project-approach-2
$ git worktree remove ../project-approach-3
$ git branch -D experiment/approach-2 experiment/approach-3

Example 3: Review + Development

# Terminal 1: Review PR in read-only worktree
$ git worktree add ../project-review pr-branch
$ cd ../project-review
$ claude

Claude: Reviewing PR changes in read-only mode...

# Terminal 2: Continue development on main branch
$ cd ~/project
$ claude

Claude: Implementing new feature...

# Both sessions work independently

Example 4: Urgent Hotfix

# Main session working on feature
$ cd ~/project
# ... feature development in progress ...

# Urgent bug report comes in
$ git worktree add ../project-hotfix -b hotfix/critical-bug main
$ cd ../project-hotfix
$ claude

User: Fix the critical authentication bug

Claude: [Fixes bug, tests, commits]

$ git push origin hotfix/critical-bug
# Create PR for immediate merge

# Return to main session, continue feature work
$ cd ~/project

Integration with Pro Workflow

Smart Commit

Each worktree commits independently with quality gates

Wrap-Up

Wrap up each worktree session before cleanup

Orchestrate

Background agents use worktree isolation automatically

Context Optimizer

Worktrees keep context isolated and manageable

Best Practices

Use descriptive paths:
  • Good: ../project-feat/add-oauth
  • Bad: ../temp, ../test
Don’t create worktrees for every tiny change. Use for:
  • Parallel features taking >5 minutes
  • Exploring different approaches
  • Urgent context switches
Weekly:
git worktree list
git worktree prune
Always commit or stash in one worktree before creating another. Keeps state clean.

Troubleshooting

Can’t Create Worktree - Branch Already Checked Out

# Error: 'feature-branch' is already checked out at '/Users/you/project'

# Solution: Use a different branch or create new branch
git worktree add ../project-feat -b feature-branch-2

Worktree Not Cleaning Up

# Force remove
git worktree remove ../project-feat --force

# Then prune
git worktree prune

Lost Track of Worktrees

# List all worktrees
git worktree list

# Remove all except main
git worktree list | grep -v "$(pwd)" | awk '{print $1}' | xargs -I {} git worktree remove {}

Disk Space Issues

Each worktree is a full working copy:
# Check disk usage
du -sh ../project*

# Clean up node_modules in worktrees
find ../project-* -name "node_modules" -type d -prune -exec rm -rf {} +

Advanced: Subagent Worktree Patterns

Scout Agent (Background, Worktree)

---
name: scout
description: PROACTIVELY explore codebase when confidence is low
tools: ["Read", "Glob", "Grep"]
background: true
isolation: worktree
model: haiku
---

You are a scout agent. Explore the codebase to:
1. Find similar patterns
2. Identify relevant files
3. Score confidence (0-100)
4. Report back with findings

Never make changes. Read-only exploration.

Reviewer Agent (Worktree)

---
name: reviewer
description: Code review with security focus
tools: ["Read", "Grep", "Bash"]
isolation: worktree
model: opus
---

Review changes in this worktree:
1. Security vulnerabilities
2. Performance issues
3. Test coverage
4. Code quality

Never modify code. Report findings only.

Next Steps

Master Pro Workflow

See how parallel worktrees fit into the complete system

Try Orchestrate

Use worktrees with multi-phase development

Optimize Context

Keep context clean with worktree isolation

Explore All Skills

View the complete skill system

Build docs developers (and LLMs) love