From Git Worktrees
Finish a git worktree feature branch with a four-option gate (merge locally / push+PR / keep / discard)
How this command is triggered — by the user, by Claude, or both
Slash command
/git-worktrees:worktree-finishThis command is limited to the following tools:
The summary Claude sees in its command listing — used to decide when to auto-load this command
# /worktree-finish - Finish a Worktree Ends feature work in a worktree with an explicit four-option gate. Never silently merges, pushes, or discards - the user picks the outcome, and destructive options require typed confirmation. ## Usage - `worktree-path` (optional): path to the worktree. Defaults to the current directory if it is a worktree, otherwise asks. ## Workflow ### Phase 1: Detect Context 1. If `worktree-path` was passed, use it. Otherwise, run `git rev-parse --show-toplevel` to find the repo root and check `git worktree list` - if the current directory is a worktree, use...
Ends feature work in a worktree with an explicit four-option gate. Never silently merges, pushes, or discards - the user picks the outcome, and destructive options require typed confirmation.
/worktree-finish [worktree-path]
worktree-path (optional): path to the worktree. Defaults to the current directory if it is a worktree, otherwise asks.If worktree-path was passed, use it. Otherwise, run git rev-parse --show-toplevel to find the repo root and check git worktree list - if the current directory is a worktree, use it.
Verify this IS a worktree, not the main checkout:
git rev-parse --git-common-dir # .git of the main repo
git rev-parse --git-dir # .git-worktrees/<name> of this worktree
If they are the same path, this is the main checkout - stop and report: "this is the main checkout, not a worktree; /worktree-finish is only for worktrees."
Gather state:
git rev-parse --abbrev-ref HEADgit rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/nullgit status --porcelaingit log @{u}..HEAD --oneline 2>/dev/nullorigin/main: git merge-base HEAD origin/maingit log origin/main..HEAD --onelineBefore showing options, surface any state the user should know about:
git merge-base HEAD origin/main is not the tip of origin/main, suggest a rebase before merging or opening a PR.Print this prompt to the user VERBATIM and wait for a numeric reply:
Finishing worktree: <path>
Branch: <branch>
Commits ahead of main: <N>
Uncommitted changes: <yes/no>
Choose an action:
1) Merge locally into main (squash, then remove worktree)
2) Push branch and open a PR (worktree stays until PR is merged)
3) Keep the worktree as is (no action, just exit)
4) Discard the worktree and branch (DESTRUCTIVE, requires typed confirmation)
Enter 1, 2, 3, or 4:
Do NOT pick an option on the user's behalf. If the reply is not 1, 2, 3, or 4, re-prompt.
git status --porcelain is non-empty, stop and ask the user to commit or discard the changes first.cd to the main checkout: cd $(git rev-parse --git-common-dir)/..git checkout main && git pull --ff-only origin maingit merge --squash <branch>git commit -m "<message>"git push origin main.git worktree remove <path>git branch -D <branch> (safe after squash merge).origin/main is current: git fetch origin. If behind, offer to rebase first.git push -u origin <branch>gh pr create with title and body. Use the repo's PR template if one exists (check .github/pull_request_template.md, .github/PULL_REQUEST_TEMPLATE.md, and repo root). Do not add AI attribution footers./worktree-finish again after the PR is merged to clean up (or manually git worktree remove).No-op. Report:
Keeping worktree: <path>
Branch: <branch>
(Run /worktree-finish again when you are ready to merge, push, or discard.)
Show what will be lost:
git log origin/main..HEAD --oneline)git status --porcelain)Ask the user to type the EXACT branch name to confirm. Example:
To confirm discard, type the branch name: <branch>
If the typed reply does not match the branch name exactly, abort and report: "Discard cancelled - typed name did not match."
If it matches:
git worktree remove --force <path>git branch -D <branch>git push origin --delete <branch>. This is a second typed confirmation.Report: worktree and branch discarded.
Always report:
main from any option.rm -rf a worktree - always use git worktree remove (with --force only for option 4).npx claudepluginhub lucasmccomb/ccgm --plugin git-worktrees