
Worktree Mastery
- 4 installs
- 35 repo stars
- Updated April 29, 2026
- spences10/claude-code-toolkit
Helps with ai & agent building tasks.
About
worktree-mastery is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- worktree-mastery
- AI & Agent Building
- AI-coding skill
Worktree Mastery by the numbers
- 4 all-time installs (skills.sh)
- Ranked #13,372 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/spences10/claude-code-toolkit --skill worktree-masteryAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 4 |
|---|---|
| repo stars | ★ 35 |
| Last updated | April 29, 2026 |
| Repository | spences10/claude-code-toolkit ↗ |
What it does
Helps with ai & agent building tasks.
Files
Worktree Mastery
Run 3-5 parallel Claude sessions on same repo. "The single biggest productivity unlock." - Boris Cherny
Core Concept
Git worktrees = independent working directories sharing one repo. Each Claude session gets its own worktree. No branch conflicts, no stash juggling.
Quick Setup
# From repo root, create worktrees
git worktree add ../myproject-review main
git worktree add ../myproject-refactor main
git worktree add ../myproject-test main
# List active worktrees
git worktree listNaming Convention
myproject/ # Main worktree (original clone)
myproject-review/ # Code review session
myproject-refactor/ # Refactoring session
myproject-test/ # Test writing session
myproject-docs/ # Documentation sessionSession Strategy
| Worktree | Use Case |
|---|---|
| main | Primary development, commits |
| main-review | PR reviews, code reading |
| main-refactor | Large refactors, experiments |
| main-test | Test writing, debugging |
Workflow
1. Create worktrees before starting parallel work 2. Start Claude in each worktree directory 3. Work independently - each session has isolated state 4. Sync via git - commit in one, pull in another 5. Cleanup when done
Sync Between Sessions
# In worktree needing updates
git fetch origin
git rebase origin/main
# Or if working on branches
git checkout feature-branch
git pullReferences
- worktree-commands.md - Full command reference
- session-strategies.md - Multi-session patterns
- cleanup.md - Removal and maintenance
Cleanup
Remove Worktrees
# Remove worktree (fails if uncommitted changes)
git worktree remove ../repo-review
# Force remove (discards changes)
git worktree remove --force ../repo-scratchPrune Stale References
After manually deleting worktree directories:
# Clean up stale worktree metadata
git worktree prune
# Dry run first
git worktree prune --dry-run
# Verbose output
git worktree prune -vFull Cleanup Script
#!/bin/bash
# cleanup-worktrees.sh
# List current worktrees
echo "Current worktrees:"
git worktree list
# Remove all non-main worktrees
for wt in $(git worktree list --porcelain | grep "^worktree" | cut -d' ' -f2); do
if [[ "$wt" != "$(pwd)" ]]; then
echo "Removing: $wt"
git worktree remove --force "$wt" 2>/dev/null || true
fi
done
# Prune stale references
git worktree prune -v
echo "Remaining:"
git worktree listCleanup Checklist
Before removing worktrees:
- [ ] Commit or stash valuable changes
- [ ] Push branches you want to keep
- [ ] Check for untracked files worth saving
Disk Space Recovery
Worktrees share .git but duplicate working files.
# Check worktree sizes
du -sh ../project-*
# After removal, git gc for full cleanup
git gc --prune=nowTroubleshooting
"worktree is locked"
git worktree unlock ../locked-worktree
git worktree remove ../locked-worktree"not a valid worktree"
Directory deleted manually. Prune metadata:
git worktree pruneBranch still exists after removal
Worktree removal doesn't delete branches:
# Delete local branch after worktree removal
git branch -d feature-branch
# Force delete if unmerged
git branch -D feature-branchSession Strategies
Recommended Setup: 3-5 Worktrees
Sweet spot for most projects. More adds overhead, fewer limits parallelism.
Standard Configuration
project/ # Main: commits, primary work
project-review/ # Reviews: PRs, code reading
project-refactor/ # Heavy lifting: large changes
project-test/ # Testing: write tests, debug
project-scratch/ # Throwaway: experimentsSession Isolation Benefits
Each Claude session in separate worktree:
- No conflicts - Different files, different branches
- Context preserved - Each session maintains own state
- Safe experiments - Trash one without affecting others
- Parallel progress - Review PR while feature develops
Coordination Patterns
Primary + Satellites
One main worktree for commits, others for auxiliary work.
[main] ──commits──> origin
[review] reads from main
[refactor] PRs back to mainFeature Branches
Each worktree on different feature branch.
[main] on main
[feature-a] on feature-a branch
[feature-b] on feature-b branchReview Pipeline
[dev] Write code
[review] Self-review before PR
[test] Verify behaviorCommunication Between Sessions
Worktrees share git history. Coordinate via commits:
# Session A: commit work
git add . && git commit -m "WIP: feature progress"
# Session B: pull changes
git fetch && git rebase origin/mainContext Switching
When moving between worktrees:
1. Don't cd - Open new terminal in worktree directory 2. Separate shells - One terminal per worktree 3. Name terminals - Match worktree names for clarity
When NOT to Use Multiple Worktrees
- Tiny changes (single file edits)
- Sequential tasks (no parallelism benefit)
- Limited disk space (each worktree = full checkout)
Worktree Commands
Create Worktrees
# Create from current branch
git worktree add ../repo-name-suffix
# Create from specific branch
git worktree add ../repo-review main
# Create with new branch
git worktree add -b feature-x ../repo-feature main
# Create detached (no branch)
git worktree add --detach ../repo-experiment HEADList and Inspect
# List all worktrees
git worktree list
# Verbose output with branch info
git worktree list --porcelainLock/Unlock
Prevent accidental removal:
# Lock a worktree
git worktree lock ../repo-important
# Unlock when done
git worktree unlock ../repo-important
# Lock with reason
git worktree lock --reason "Long-running refactor" ../repo-refactorMove Worktrees
# Relocate worktree directory
git worktree move ../old-path ../new-pathRepair
Fix broken worktree references:
# Repair all worktrees
git worktree repair
# Repair specific path
git worktree repair ../broken-worktreeCommon Patterns
Parallel Feature Development
git worktree add -b feature-a ../repo-feature-a main
git worktree add -b feature-b ../repo-feature-b mainQuick PR Review
git worktree add ../repo-pr-123 origin/pr-branch
# Review, then remove
git worktree remove ../repo-pr-123Experimental Work
git worktree add --detach ../repo-experiment HEAD
# Experiment freely
# Discard or cherry-pick results
git worktree remove --force ../repo-experiment