| name | manage-worktree |
| description | Create, move, or remove a git worktree. Use when the user asks to create a worktree, start a new branch in a worktree, move a branch to a worktree, work on something in parallel, remove/delete a worktree, or says "/manage-worktree <name>". Handles stashing, branch management, setup, and cleanup.
|
| argument-hint | ["branch-name"] |
| allowed-tools | Bash(git worktree *), Bash(bin/dev/setup-worktree *), Bash(bin/dev/remove-worktree *), Bash(git branch *), Bash(git stash *), Bash(git checkout *), Bash(git switch *) |
Manage Worktree
Path Resolution
Always resolve the worktree base from the main repo โ relative paths like ../apartment-worktrees/
break when invoked from inside an existing worktree.
MAIN_REPO=$(git worktree list --porcelain | head -1 | sed 's/^worktree //')
WORKTREE_BASE="$(dirname "$MAIN_REPO")/apartment-worktrees"
Use $WORKTREE_BASE/<name> for all worktree paths in the steps below.
Conventions
- Path:
$WORKTREE_BASE/<name> (sibling to main repo)
- Branch:
<dev-prefix>/<name> (e.g., man/v4-foundation, jb/fix-auth)
- Base: current branch (confirm if it's a feature branch rather than
development)
- Always run
bin/dev/setup-worktree after git worktree add
- Remove with:
bin/dev/remove-worktree <name> --delete-branch
Mode Detection
Determine the mode from the argument and user intent:
- Remove mode โ if the user says "remove", "delete", "clean up", or "tear down" a worktree
- Move mode โ if
$ARGUMENTS matches an existing local branch (git branch --list "$ARGUMENTS"), or the user says "move this branch to a worktree"
- Create mode โ otherwise (new branch + worktree)
Create Mode (new branch)
-
Detect developer prefix from remote branches:
git branch -r | sed 's|^ *origin/||' | grep -E '^[a-z]{2,4}/' | cut -d/ -f1 | sort | uniq -c | sort -rn
Known prefixes: man. Exclude automated prefixes (seer/, fix/, feat/, docs/). Ask if unclear.
-
Stash uncommitted changes (if dirty): git stash push -u -m "pre-worktree: $ARGUMENTS"
-
Get base branch: git branch --show-current
-
Create worktree:
mkdir -p "$WORKTREE_BASE"
git worktree add "$WORKTREE_BASE/$ARGUMENTS" -b <prefix>/$ARGUMENTS <base-branch>
-
Run setup (copies .claude, .bundle, .vscode, sets Peacock color):
bin/dev/setup-worktree "$WORKTREE_BASE/$ARGUMENTS"
-
Pop stash in the original worktree (not the new one) if stashed in step 2.
-
Report: worktree path, branch name, base branch, any issues.
Move Mode (existing branch โ worktree)
Moves the current or specified branch out of the main repo into a dedicated worktree.
The main repo switches back to a base branch (development by default).
-
Identify the branch to move: $ARGUMENTS or git branch --show-current
-
Derive worktree name from the branch name (strip the dev prefix):
man/v4-foundation โ worktree name: v4-foundation
- Already unprefixed โ use as-is
-
Stash uncommitted changes (if dirty): git stash push -u -m "pre-worktree-move: <branch>"
-
Determine return branch: default is development.
-
Switch main repo to the return branch: git switch <return-branch>
-
Create worktree with the existing branch (no -b):
mkdir -p "$WORKTREE_BASE"
git worktree add "$WORKTREE_BASE/<worktree-name>" <branch>
-
Run setup:
bin/dev/setup-worktree "$WORKTREE_BASE/<worktree-name>"
-
Pop stash in the new worktree (that's where the work continues):
cd "$WORKTREE_BASE/<worktree-name>" && git stash pop
-
Report: worktree path, branch name, return branch in main repo, any issues.
Remove Mode (delete worktree)
-
Resolve worktree name from $ARGUMENTS
-
Verify it exists:
ls "$WORKTREE_BASE/<name>" 2>/dev/null
-
Run removal:
bin/dev/remove-worktree <name> --delete-branch --confirm
Omit --confirm if the user hasn't explicitly confirmed.
-
Report: confirm removal, branch deletion, any issues.