| name | aio-worktree |
| description | Manage git worktrees for parallel development workflows — create, sync, and spotlight preview.
|
| when_to_use | create worktree, sync worktree, manage worktrees, parallel development, worktree, git worktree, branch isolation, spotlight, worktree merge, worktree cleanup |
| effort | medium |
| argument-hint | <branch-name> |
Git Worktree Management
Manages git worktrees for parallel development workflows.
Environment
- git: !
which git 2>/dev/null || echo "NOT INSTALLED"
- Scripts: !
echo "${CLAUDE_PLUGIN_ROOT}/skills/aio-worktree"
Scripts Path
WT="${CLAUDE_PLUGIN_ROOT}/skills/aio-worktree"
Set this in every shell block that calls a script. Then reference scripts as $WT/script-name.
Available Scripts
| Script | Purpose |
|---|
worktree-create.sh | Create new worktree with branch |
worktree-list.sh | List all worktrees and their status |
worktree-sync.sh | Sync worktree ↔ main (rebase + ff) |
worktree-spotlight.sh | Live file sync for hot reload |
worktree-spotlight-status.sh | Check if spotlight is running |
worktree-merge.sh | Merge worktree branch to/from parent |
worktree-remove.sh | Remove worktree and delete branch |
worktree-cleanup.sh | Emergency cleanup after crash |
Workflow
1. Create Worktree
WT="${CLAUDE_PLUGIN_ROOT}/skills/aio-worktree"
$WT/worktree-create.sh <name> [source_ref]
$WT/worktree-create.sh feature-login
$WT/worktree-create.sh hotfix-bug main
$WT/worktree-create.sh experiment abc123
2. Sync (Rebase + Fast-Forward)
Sync worktree with parent branch. Both end up at the same commit with same hash.
$WT/worktree-sync.sh
How it works:
- Rebase worktree onto parent (get latest from main, put your commits on top)
- Fast-forward parent to worktree (now both identical)
Result: Both branches at same commit, same hash. No duplicates.
Example workflow:
git add . && git commit -m "feat: new feature"
$WT/worktree-sync.sh
3. Spotlight (Temporary File Sync)
Preview worktree changes in main repo with hot reload. One-way sync, temporary.
$WT/worktree-spotlight.sh <worktree_path> . [excludes...]
$WT/worktree-spotlight.sh ../myrepo--wtr-feature . node_modules dist .env
How it works:
- Watches worktree for file changes
- Copies changed files to main repo (for hot reload preview)
- On exit: main repo restored to clean state
- Does NOT commit anything - purely temporary
Important:
- Run with
run_in_background: true
- Main repo must be clean before starting
To stop: Ctrl+C or kill <PID>. Cleanup is automatic.
4. Remove Worktree
WT="${CLAUDE_PLUGIN_ROOT}/skills/aio-worktree"
$WT/worktree-remove.sh <path_or_name>
$WT/worktree-remove.sh ../myrepo--wtr-feature
$WT/worktree-remove.sh feature
Common Scenarios
"Multiple AI agents working in parallel"
WT="${CLAUDE_PLUGIN_ROOT}/skills/aio-worktree"
$WT/worktree-create.sh agent-a-task
$WT/worktree-create.sh agent-b-task
cd ../repo--wtr-agent-a-task
$WT/worktree-sync.sh
cd ../repo--wtr-agent-b-task
$WT/worktree-sync.sh
cd ../repo--wtr-agent-a-task
$WT/worktree-sync.sh
"I want hot reload preview while working in worktree"
- Ensure main repo is clean
- Run spotlight:
worktree-spotlight.sh <worktree> . node_modules
- Edit in worktree → changes appear in main for hot reload
- Stop spotlight → main restored clean
- Commit in worktree, then sync:
worktree-sync.sh
"I want to work on a feature and sync with main"
- Create worktree:
worktree-create.sh feature-x
- Work in worktree, commit as usual
- Sync anytime:
worktree-sync.sh
- When done:
worktree-remove.sh feature-x
Error Recovery
"Spotlight crashed"
WT="${CLAUDE_PLUGIN_ROOT}/skills/aio-worktree"
$WT/worktree-cleanup.sh .
"Sync has conflicts"
Script will stop at rebase conflict. Resolve conflicts, then:
git rebase --continue
$WT/worktree-sync.sh
Worktrees + Agent Teams
When using Agent Teams (experimental, requires CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1), combine worktrees with agent teams for maximum parallel safety.
Pattern: Each teammate gets their own worktree
WT="${CLAUDE_PLUGIN_ROOT}/skills/aio-worktree"
$WT/worktree-create.sh teammate-frontend
$WT/worktree-create.sh teammate-backend
$WT/worktree-create.sh teammate-tests
Why: Agent teams let multiple Claude instances work in parallel. Worktrees give each instance an isolated filesystem. Combined = true parallel development without merge conflicts.
Sync strategy with teams:
- Teammates work and commit independently in their worktrees
- When a teammate finishes, they message the lead
- Lead runs
worktree-sync.sh in order (first-done-first-synced)
- Later teammates get earlier teammates' work when they sync
- All worktrees converge to the same history
When NOT to combine: If tasks are small and touch different files anyway, agent teams alone (without worktrees) work fine. Use worktrees when there's ANY risk of file overlap.
Key Points
- Naming convention:
wtr- prefix for easy identification
- Folder:
{repo}--wtr-{name} (e.g., myrepo--wtr-feature)
- Branch:
wtr-{name} (e.g., wtr-feature)
- Sync keeps same hash: Rebase + fast-forward = identical commits
- No duplicate commits: Unlike cherry-pick, sync keeps history clean
- Parallel-friendly: Multiple worktrees can sync independently
- Spotlight = file-based: Temporary file copying for preview, no commits
- Always commit before sync: Sync works with commits, not uncommitted changes
- Spotlight fallback: Uses polling if fswatch not installed (
brew install fswatch)