From worktree
Remove completed or stale git worktrees. Without --all, only removes worktrees whose branches are already merged. With --all, removes all worktrees but always requires user confirmation for unmerged ones.
How this skill is triggered — by the user, by Claude, or both
Slash command
/worktree:cleanupThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Remove completed or stale git worktrees and their branches.
Remove completed or stale git worktrees and their branches.
Invoked as: $ARGUMENTS
git rev-parse --git-dir 2>/dev/null || echo "NOT_A_GIT_REPO"git worktree list 2>/dev/null || echo "(none)"ls .worktrees/ 2>/dev/null || echo "(empty or missing)"git rev-parse --git-dir. If it fails, stop with: "Not a git repository. Aborting."$ARGUMENTS: if --all is present, set ALL_MODE=true. Otherwise ALL_MODE=false.git worktree list --porcelain. Parse each entry for worktree <path> and branch refs/heads/<name>. Exclude the main worktree (the first entry, which is the repo root)..worktrees/ if it exists: ls .worktrees/ 2>/dev/null. Cross-reference with git's worktree list.git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null → extract branch name.main exists (git rev-parse --verify main 2>/dev/null), then master.git branch --show-current.TARGET.git branch --merged $TARGET. If the branch appears in the output, it is merged.Group all discovered worktrees into 3 categories:
git branch --merged $TARGET → safe to deleteALL_MODE=truegit worktree list but directory does not exist on diskDisplay a classification table:
Worktree Status:
| Path | Branch | Status |
|------|--------|--------|
| .worktrees/step-1 | step-1 | merged |
| .worktrees/feat-x | feat-x | unmerged |
| (missing dir) | old-wt | stale |
Target branch: <TARGET>
Mode: <default or --all>
If no worktrees are found at all, print: "No worktrees found. Nothing to clean up." and stop.
Follow these steps exactly, in order:
Run git worktree prune to clean up stale entries. Report how many were pruned.
For each merged worktree:
git worktree remove <path>git branch -d <branch>If a removal fails, print a warning and continue with the next one.
If ALL_MODE=true AND there are unmerged worktrees:
HARD RULE: ALWAYS use AskUserQuestion before deleting unmerged worktrees. This applies even when called by agents. No exceptions.
Use AskUserQuestion with:
If user confirms deletion:
git worktree remove --force <path>git branch -D <branch>If user declines, print: "Kept unmerged worktrees." and skip them.
Print a final summary:
Cleanup complete.
Removed:
- <path> (<branch>) [merged]
- <path> (<branch>) [force-removed]
Remaining:
- <path> (<branch>) [unmerged]
Stale entries pruned: <N>
If .worktrees/ directory is now empty, note: ".worktrees/ directory is now empty. You can remove it with rmdir .worktrees."
If no worktrees were removed, print: "No worktrees were removed."
npx claudepluginhub jaebit/claudemate --plugin worktreeSafely deletes merged Git worktrees after verifying git merge status and GitHub PR closure via gh CLI. Handles single branch or 'all' for batch cleanup post-PR merge.
Batch removes git worktrees for closed GitHub issues and merged branches. Checks status via gh CLI, reports summary, confirms before pruning and branch deletion.
Removes git worktrees and associated branches after PR merges, sub-scope consolidation, or manual cleanup. Lists worktrees if unspecified, handles uncommitted changes and paused states.