// Manage Git worktrees for parallel Claude Code development. Use this skill when engineers ask to "create a worktree", "run parallel Claude sessions", "work on multiple features simultaneously", or need help with worktree management.
| name | git-worktrees |
| description | Manage Git worktrees for parallel Claude Code development. Use this skill when engineers ask to "create a worktree", "run parallel Claude sessions", "work on multiple features simultaneously", or need help with worktree management. |
Run multiple Claude Code sessions in parallel on different branches using Git worktrees. This skill provides simple scripts and workflows to set up, manage, and clean up worktrees, enabling true parallel development without conflicts.
Why Worktrees?
Just run the interactive script:
scripts/create_worktree.sh
This will:
That's it! The script handles all complexity.
scripts/list_worktrees.sh
Shows a clean, formatted list of all your worktrees with their branches and status.
scripts/cleanup_worktrees.sh
Interactive removal of merged or abandoned worktrees.
Scenario: You want Claude to build feature A while you work on feature B.
Steps:
Create worktree for feature A:
scripts/create_worktree.sh
# Enter: feature-a
# Script creates: ../repo-feature-a/
Open Claude Code in the new worktree:
/init to orient ClaudeGive Claude the task:
"Build the user authentication feature with OAuth support"
Continue your work in main:
When both are done, merge:
# Review Claude's work
cd ../repo-feature-a
git log
# If good, merge back
git checkout main
git merge feature-a
# Clean up
scripts/cleanup_worktrees.sh
Scenario: You want Claude to refactor a large module while you continue development.
Steps:
Create refactor worktree:
scripts/create_worktree.sh
# Enter: refactor-auth-module
Start Claude in refactor worktree:
"Refactor the authentication module to use dependency injection"
Continue your daily work in main:
Review and integrate when ready:
cd ../repo-refactor-auth-module
git log --oneline
# Review changes
# Merge when satisfied
git checkout main
git merge refactor-auth-module
Scenario: You want 3 Claude instances working on different features simultaneously.
Steps:
Create 3 worktrees:
scripts/create_worktree.sh # feature-api-endpoints
scripts/create_worktree.sh # feature-ui-dashboard
scripts/create_worktree.sh # feature-email-notifications
Open 3 Claude Code sessions:
../repo-feature-api-endpoints/../repo-feature-ui-dashboard/../repo-feature-email-notifications/Assign tasks to each Claude:
Monitor progress:
scripts/list_worktrees.sh
Merge features as they complete:
# Feature by feature
git checkout main
git merge feature-api-endpoints
git merge feature-ui-dashboard
git merge feature-email-notifications
# Clean up
scripts/cleanup_worktrees.sh
Scenario: Production bug needs immediate fix while Claude is working on a feature.
Steps:
Claude is already working in a feature worktree
Create hotfix worktree from main:
scripts/create_worktree.sh
# Enter: hotfix-login-bug
# Choose base branch: main
Fix the bug yourself or with another Claude session:
cd ../repo-hotfix-login-bug
# Make fixes
git add .
git commit -m "Fix login redirect bug"
Merge hotfix to main:
git checkout main
git merge hotfix-login-bug
git push origin main
Sync feature worktree with latest main:
cd ../repo-feature-xyz
scripts/sync_worktree.sh
# Merges latest main into feature branch
Interactive worktree creation with all the right defaults.
What it does:
Usage:
scripts/create_worktree.sh
# Prompts:
# Feature name: my-feature
# Base branch (default: main):
#
# Creates: ../repo-my-feature/
# Branch: my-feature
Advanced usage:
# Create from specific branch
scripts/create_worktree.sh --base develop
# Specify location
scripts/create_worktree.sh --dir ~/worktrees/my-feature
Shows all active worktrees with status.
Output:
ââââââââââââââââââââââââââââââââââââââââââââââââââ
â Active Git Worktrees â
ââââââââââââââââââââââââââââââââââââââââââââââââââ
đ Main Worktree
Path: /home/user/project
Branch: main
Status: clean
đ Feature Worktrees
Path: /home/user/project-feature-api
Branch: feature-api
Status: 2 uncommitted changes
Path: /home/user/project-refactor
Branch: refactor-auth
Status: clean
Interactive cleanup of old worktrees.
Features:
Usage:
scripts/cleanup_worktrees.sh
# Output:
# Found 3 worktrees
#
# 1. feature-api (merged to main) - Safe to remove
# 2. feature-dashboard (not merged) - Keep
# 3. old-experiment (not merged, 30 days old) - Consider removing
#
# Which worktrees to remove? (1,3): 1
Keep worktree up-to-date with main branch.
What it does:
Usage:
# From within a worktree
cd ../repo-feature-api
scripts/sync_worktree.sh
# Or specify worktree
scripts/sync_worktree.sh ../repo-feature-api
When you open a new Claude Code session in a worktree, always run /init first:
/init
This ensures Claude:
/init to orient Claudegit log or file watchingGood names:
feature-user-auth â
refactor-api-layer â
hotfix-login-bug â
experiment-new-db â
Bad names:
test â (too vague)wt1 â (meaningless)fixes â (unclear)Recommended format:
<type>-<short-description>
Types:
- feature-*
- refactor-*
- hotfix-*
- experiment-*
- review-*
Recommended layout:
~/projects/
âââ myapp/ # Main worktree (main branch)
âââ myapp-feature-api/ # Feature worktree
âââ myapp-refactor-auth/ # Refactor worktree
âââ myapp-hotfix-bug/ # Hotfix worktree
The scripts default to creating worktrees as siblings to your main directory with a naming pattern: <repo>-<branch-name>.
â Use worktrees when:
â Don't use worktrees for:
git checkout)Problem: Feature branches can get out of date with main.
Solution: Regularly sync worktrees:
# Option 1: Use the sync script
cd ../repo-feature-api
scripts/sync_worktree.sh
# Option 2: Manual sync
cd ../repo-feature-api
git fetch origin
git merge origin/main
Recommended frequency:
Quick status of all worktrees:
scripts/list_worktrees.sh
Regular cleanup (weekly):
scripts/cleanup_worktrees.sh
Find stale worktrees:
# Worktrees with old commits
git worktree list | while read path branch commit; do
cd "$path"
last_commit=$(git log -1 --format=%cr)
echo "$branch: Last commit $last_commit"
done
Cause: Branch name has invalid characters
Solution: Use alphanumeric + hyphens only:
# Bad
feature/my_feature â
# Good
feature-my-feature â
Cause: Worktree directory was manually deleted
Solution: Prune worktree references:
git worktree prune
Cause: Didn't run /init after opening worktree
Solution: Always run /init when starting Claude in a new worktree:
/init
Cause: Changes in worktree conflict with main
Solution 1: Resolve conflicts manually:
cd ../repo-feature-api
git fetch origin
git merge origin/main
# Fix conflicts in editor
git add .
git commit -m "Merge main and resolve conflicts"
Solution 2: If you want to discard worktree changes and restart:
cd ../repo-feature-api
git fetch origin
git reset --hard origin/main
# Start feature over
Cause: Branch exists in multiple worktrees
Solution: You can't have the same branch checked out in multiple worktrees. Create a new branch:
scripts/create_worktree.sh
# Use a different branch name
Cause: Git worktrees share the .git directory, but files are duplicated
Solution 1: Clean up old worktrees:
scripts/cleanup_worktrees.sh
Solution 2: For large repos, use sparse-checkout:
git -C ../repo-feature-api sparse-checkout set src/ tests/
Create a /worktree command for Claude Code. See references/slash_command_template.md for the complete setup.
Usage after setup:
/worktree feature-new-api
Claude will:
Worktrees are local only, but you can share the workflow:
Share branch, not worktree:
cd ../repo-feature-api
git push origin feature-api
# Teammate creates their own worktree
git worktree add ../repo-feature-api feature-api
Document your worktree structure in team docs
Use consistent naming across team
For large repos:
Use sparse-checkout (only checkout files you need):
git -C ../repo-feature-api sparse-checkout init
git -C ../repo-feature-api sparse-checkout set src/ tests/
Use worktree prune regularly:
git worktree prune
Limit concurrent worktrees to 3-5 for best performance
| Task | Command |
|---|---|
| Create new worktree | scripts/create_worktree.sh |
| List all worktrees | scripts/list_worktrees.sh |
| Clean up worktrees | scripts/cleanup_worktrees.sh |
| Sync with main | scripts/sync_worktree.sh |
| Manual create | git worktree add ../path branch-name |
| Manual list | git worktree list |
| Manual remove | git worktree remove ../path |
| Prune references | git worktree prune |
Setup:
# Create API worktree
scripts/create_worktree.sh
# Name: feature-api
# Create UI worktree
scripts/create_worktree.sh
# Name: feature-ui
Execution:
../repo-feature-api: "Build REST API for user management"../repo-feature-ui: "Create React UI for user management"Merge:
git checkout main
git merge feature-api
git merge feature-ui
scripts/cleanup_worktrees.sh
Scenario: Need to review PR while Claude works on feature
Setup:
# Claude is working in feature worktree
# You need to review PR #123
scripts/create_worktree.sh
# Name: review-pr-123
# Base: pr-branch-name
Execution:
../repo-review-pr-123../repo-feature-xyzCleanup:
# After review
scripts/cleanup_worktrees.sh
# Select review-pr-123
Scenario: Want to try a radical refactor without breaking current work
Setup:
scripts/create_worktree.sh
# Name: experiment-new-architecture
Execution:
../repo-experiment-new-architectureDecision:
# If experiment succeeded
git checkout main
git merge experiment-new-architecture
# If experiment failed
scripts/cleanup_worktrees.sh
# Delete experiment worktree (no harm done)
scripts/cleanup_worktrees.sh every Fridayscripts/list_worktrees.sh to see what's active/worktree commandGit worktrees enable true parallel development with Claude Code:
â Run multiple Claude sessions without conflicts â Switch contexts instantly without stashing â Experiment safely without breaking main â Simple scripts handle all complexity â Clean workflows for common scenarios
Get started:
scripts/create_worktree.sh
That's it! The scripts make worktrees simple and practical.