/worktrees:conceptsfrom worktrees
Comprehensive reference for git worktrees. Covers concepts, commands, conflict resolution, and best practices. Invoke with "/worktrees:concepts" or when user mentions "worktree reference", "explain worktrees", "worktree documentation", "worktree commands", "worktree concepts", or "learn about worktrees".
Ships in worktrees. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Comprehensive reference for git worktrees in AI development workflows.
Git worktrees allow checking out multiple branches simultaneously in separate directories, all sharing the same .git repository.
Key characteristics:
Ideal for:
Not ideal for:
my-project/
├── .git/ # Shared git directory
├── .gitignore # Must include .worktrees/
├── .worktrees/ # All worktrees live here
│ ├── feature-auth/ # Feature worktree
│ ├── feature-api/ # Another feature worktree
│ └── hotfix-urgent/ # Hotfix worktree
└── src/ # Main working directory
Before creating any worktree, ensure .worktrees/ is gitignored:
grep -q "^\.worktrees" .gitignore 2>/dev/null || echo ".worktrees/" >> .gitignore
git add .gitignore
git commit -m "chore: add .worktrees to gitignore"
Why gitignore? Each worktree contains a complete checkout. Without gitignoring, you'd accidentally commit nested copies of your entire codebase.
| Type | Pattern | Example |
|---|---|---|
| Feature | feature-<name> | feature-auth |
| Agent | <agent-id>-<feature> | agent-42-api |
| Instance | inst-<id> | inst-alpha |
| Hotfix | hotfix-<issue> | hotfix-login |
For multiple concurrent worktrees:
[worktree-name] - projectAvoid port conflicts when running multiple instances:
# Worktree 1
PORT=3001 npm run dev
# Worktree 2
PORT=3002 npm run dev
| Approach | When to Use |
|---|---|
| SQLite per worktree | Simple apps, testing |
| PostgreSQL schemas | Shared DB, isolated data |
| Docker containers | Full isolation |
| In-memory DB | Unit tests |
# SQLite: Different files
DATABASE_URL="file:.worktrees/auth/dev.sqlite"
# PostgreSQL: Different schemas
DATABASE_URL="postgres://localhost/app?schema=worktree_auth"
# Docker: Different containers
docker-compose -p worktree-auth up -d
Keep worktree-specific .env files:
# In worktree
cp ../.env.example .env
# Customize PORT, DATABASE_URL, etc.
Each worktree duplicates working files (not git objects):
# Check worktree sizes
du -sh .worktrees/*
Multiple running dev servers increase memory usage:
top or htop--watch only on active worktreeMany tools use file watchers (webpack, nodemon, etc.):
fs.inotify.max_user_watchesError: fatal: 'branch-name' is already checked out at '/path'
Cause: Each branch can only exist in one worktree.
Solutions:
git worktree listError: fatal: cannot remove worktree with uncommitted changes
Solutions:
git add . && git commit -m "WIP"git stashgit worktree remove --forceProblem: Manually deleted worktree directory leaves stale entry.
Solution: git worktree prune
Problem: Worktree ends up in detached HEAD state.
Solution:
cd .worktrees/<name>
git checkout <branch>
# or create new branch
git checkout -b <new-branch>
| Feature | Git Version |
|---|---|
| Basic worktree | 2.5+ |
worktree list | 2.7+ |
worktree lock/unlock | 2.10+ |
worktree move | 2.17+ |
worktree remove | 2.17+ |
worktree repair | 2.30+ |
--orphan | 2.37+ |
Check version: git --version
| Task | Command |
|---|---|
| Create (new branch) | git worktree add -b <branch> .worktrees/<name> [base] |
| Create (existing branch) | git worktree add .worktrees/<name> <branch> |
| List | git worktree list |
| Remove | git worktree remove .worktrees/<name> |
| Force remove | git worktree remove --force .worktrees/<name> |
| Prune stale | git worktree prune |
| Lock | git worktree lock .worktrees/<name> |
| Unlock | git worktree unlock .worktrees/<name> |
| Move | git worktree move .worktrees/<old> .worktrees/<new> |
| Repair | git worktree repair |
For detailed information, see:
references/commands-reference.md - Complete git worktree command referencereferences/conflict-resolution.md - Handling merge conflictsreferences/best-practices.md - Recommended patterns and tips/worktrees:new - Create a new worktree/worktrees:status - Check worktree health and status/worktrees:finish - Complete and clean up worktree/worktrees:peer - Independent PR-based workflow/worktrees:orchestrator - Multi-subagent parallel developmentWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub aaronbassett/agent-foundry --plugin worktrees6 skills in this plugin
/finishworktrees:finishUse when completing work in a worktree. Handles PR creation or direct merge, worktree removal, and branch cleanup. Invoke with "/worktrees:finish" or when user mentions "finish worktree", "clean up worktree", "merge worktree", "done with worktree", or "complete worktree work"./newworktrees:newUse when creating a new git worktree. Handles gitignore setup, worktree creation, and provides guidance. Invoke with "/worktrees:new <name>" or when user mentions "create worktree", "new worktree", "start feature in worktree", or "isolated workspace"./Other plugins' skills for the same job