Principle
A git worktree creates a second (or third) working directory from the same repository, each checked out on a distinct branch. No git stash, no branch switching — two terminals, two contexts, zero friction between them.
Available since Git 2.5.0 (2015), natively compatible with Claude Code.
Essential commands
# Create a worktree on an existing or new branchgit worktree add ../myproject-feature feature/authgit worktree add ../myproject-hotfix -b hotfix/login-bug
# List all active worktreesgit worktree list
# Clean up after mergegit worktree remove ../myproject-hotfixgit worktree prune # Remove stale referencesParallel Claude Code pattern
# Terminal 1: main featurecd ../myproject-featureclaude> "Implement JWT authentication"
# Terminal 2: urgent hotfix (simultaneous)cd ../myproject-hotfixclaude> "Fix the timeout bug on Safari"Each Claude instance indexes its own worktree and maintains an independent context. Both sessions run in parallel without interference.
Claude Code context in worktrees
| File | Scope |
|---|---|
~/.claude/CLAUDE.md | Global, shared by all worktrees |
CLAUDE.md (repo root) | Project, committed, shared |
.claude/CLAUDE.md (inside the worktree) | Local to the worktree only |
A worktree can have its own .claude/ configuration for branch-specific conventions.
Dependency management
The main limitation: node_modules or vendor/ are not shared automatically. Each worktree needs its own dependencies, which can take disk space and time.
Recommended solution — symlink node_modules from the main worktree:
cd ../myproject-featureln -s ../myproject/node_modules node_modulesThe /git-worktree custom command does this automatically. Use --isolated when dependencies must differ.
When to use worktrees
Suited for: multiple features in parallel, comparing approaches, code review during development, long CI builds while continuing to code.
Not suited for: simple and quick branch switches, teams unfamiliar with the tool (adds operational complexity), limited disk space.
Shell aliases for quick navigation
# In ~/.zshrcalias wa="cd ../myproject-feature-a"alias wb="cd ../myproject-feature-b"alias wm="cd ../myproject" # Main worktreePattern used by the Claude Code team internally to navigate instantly between active worktrees.
Cleanup after merge
After merging the branch, remove the worktree to free up space. git worktree prune cleans references to worktrees that were manually deleted (folder removed without going through git worktree remove).
Enter your email to read the full card and get the complete PDF bundle.
All content is free and open-source. We just ask for your email.