Git Worktree Management
Manage git worktrees for parallel Claude Code sessions.
Command Routing
Arguments received: $ARGUMENTS
Route based on arguments (check in order):
- •If empty/blank → Show Help section
- •If
create <name>→ Execute Create Worktree section - •If
status→ Execute Status section - •If
pull-all→ Execute Pull All section - •If
pull(no argument) → Execute Pull Interactive section - •If
pull <branch>→ Execute Pull section - •If
push→ Execute Push section - •If
remove <name>→ Execute Remove Worktree section - •Otherwise → Show Help section with "Unknown command" note
Help
/worktree - Manage git worktrees for parallel Claude Code sessions
Commands:
create <name> Create new worktree as sibling directory
status Show all worktrees and their state
pull Interactive: choose which branch(es) to pull
pull <source> Pull changes from a specific branch into current
pull-all Pull changes from ALL other worktrees into current
push Push current branch changes into main
remove <name> Remove worktree (optionally delete branch)
Mental model:
"pull" brings changes INTO your current branch (git merge <source>)
"push" sends your changes TO main (git checkout main && git merge <yours>)
Workflows:
From ./folder (worktree main):
/worktree pull feature-b # pulls feature-b changes into main
From ../folder-feature-b (worktree feature-b):
/worktree pull main # pulls main changes into feature-b
/worktree push # merges feature-b into main locally
git push # pushes feature-b to GitHub
From any worktree:
git push --all # pushes all worktrees to GitHub
Note: All worktrees share the same local repo.
Commits are instantly available to pull - no git push needed between worktrees.
Examples:
/worktree create feature-auth
/worktree pull # interactive selection
/worktree pull main # pull from specific branch
/worktree pull-all # merge all other worktrees
/worktree push
/worktree remove feature-auth
Create Worktree
Extract name from: $ARGUMENTS (after "create ")
Steps:
- •Validate name - no spaces, valid git branch name
- •Get project name:
basename $(git rev-parse --show-toplevel) - •Check branch doesn't exist:
git show-ref --verify --quiet refs/heads/<name> - •Create worktree:
bash
git worktree add ../<project>-<name> -b <name>
- •Install guardrails and pty-mcp in new worktree:
bash
cd ../<project>-<name> && make install-guardrails && make install-pty-mcp
- •Report success:
code
Created worktree: ../<project>-<name> Branch: <name> Next steps: 1. Open new terminal: cd ../<project>-<name> 2. Start Claude: claude 3. Work independently in this worktree
Status
Steps:
- •List worktrees:
git worktree list - •For each worktree, gather:
- •Path
- •Branch name
- •Uncommitted changes:
git -C <path> status --porcelain | wc -l
- •Present as table:
code
| Path | Branch | Changes | |------|--------|---------| | /path/to/main | main | 0 | | /path/to/feature | feature-x | 3 |
Pull
Extract source from: $ARGUMENTS (after "pull ")
Steps:
- •Validate source branch exists:
git show-ref --verify --quiet refs/heads/<source> - •Show current branch:
git branch --show-current - •Merge:
bash
git merge <source>
- •Report result - success or conflicts to resolve
Mental model: This IS a merge - you're bringing changes FROM source INTO current.
Pull Interactive
Triggered by: pull with no arguments
Steps:
- •Get current branch:
git branch --show-current - •List branches with active worktrees (excluding current):
bash
git worktree list --porcelain | grep '^branch' | sed 's|branch refs/heads/||' | grep -v <current>
- •Build options for AskUserQuestion:
- •First option: "All worktrees" (meta-option)
- •Then each worktree branch as individual option
- •Use AskUserQuestion:
code
question: "Which branch(es) do you want to pull into <current>?" header: "Pull from" multiSelect: true options: - label: "All worktrees" description: "Merge all other worktree branches into current (sequential)" - label: "<branch1>" description: "Merge <branch1> into <current>" - label: "<branch2>" description: "Merge <branch2> into <current>" - •Execute based on selection:
- •If "All worktrees" selected → Go to Pull All logic
- •Otherwise → Merge each selected branch sequentially
Pull All
Triggered by: pull-all OR "All worktrees" selection from interactive
Steps:
- •Get current branch:
git branch --show-current - •List branches with active worktrees (excluding current):
bash
git worktree list --porcelain | grep '^branch' | sed 's|branch refs/heads/||' | grep -v <current>
- •For each worktree branch, merge sequentially:
bash
git merge <branch>
- •If conflict occurs, stop and report which branch caused it
- •Ensure guardrails and pty-mcp are up-to-date:
bash
make install-guardrails && make install-pty-mcp
- •Report summary:
Or if conflicts:code
Pulled into <current> from other worktrees: ✓ main ✓ feature-a ✓ feature-b All worktree branches merged successfully.
codePulled into <current> from other worktrees: ✓ main ✗ feature-a (conflicts - resolve before continuing) Resolve conflicts, then run: /worktree pull-all
Push
Steps:
- •Check for uncommitted changes:
git status --porcelain- •If changes exist, warn user and stop
- •Get current branch:
git branch --show-current - •Switch to main:
bash
git checkout main
- •Merge current branch:
bash
git merge <current-branch>
- •Switch back:
bash
git checkout <current-branch>
- •Report result
Mental model: This IS a merge - you go TO main, then merge FROM your branch.
Remove Worktree
Extract name from: $ARGUMENTS (after "remove ")
Steps:
- •Get project name:
basename $(git rev-parse --show-toplevel) - •Check worktree exists:
git worktree list | grep <name> - •Check for uncommitted changes in worktree:
bash
git -C ../<project>-<name> status --porcelain
- •If changes exist, warn and use AskUserQuestion to confirm
- •Ask about branch deletion: Use AskUserQuestion
- •"Delete the branch '<name>' as well?"
- •Options: Yes (delete branch) / No (keep branch)
- •Remove worktree:
bash
git worktree remove ../<project>-<name>
- •Optionally delete branch:
bash
git branch -d <name>
- •Report success