This skill should be used when the user asks to "clean up worktrees", "remove merged worktrees", "prune worktrees", or wants to delete git worktrees and branches for PRs that have been merged.
Remove git worktrees and local branches whose PRs have been merged into the main branch.
git worktree list
Identify all worktrees besides the main one. Extract the branch name for each.
For each worktree branch, check whether it has a merged PR on GitHub:
gh pr list --state merged --head "<branch-name>" --json number,title \
--jq 'if length > 0 then .[0] | "#\(.number) \(.title)" else empty end'
Do NOT use git branch --merged main — this is unreliable for squash-merged PRs and also matches branches that simply haven't diverged from main yet (e.g., newly created branches with active local work).
Only branches with a confirmed merged PR on GitHub are candidates for removal.
Show the user a summary:
Ask for confirmation before proceeding with removal.
For each confirmed merged branch:
git worktree remove --force .worktrees/<worktree-dir>
git branch -D <branch-name>
Use --force for worktree removal since merged branches may have stale local changes (lock files, build artifacts, etc.) that are no longer relevant.
Use git branch -D (force delete) because squash-merged branches won't pass git branch -d validation — the local commits differ from the squashed merge commit on main.
git worktree list
Confirm only unmerged worktrees remain.
.worktrees/ directory convention uses branch names with / replaced by -