plugins/git-and-pr/skills/cleanup-worktrees/SKILL.md
Safely scans all git worktrees, checks merge status and PR state, categorizes them (Merged/PR Closed/Remote Deleted/Active), presents a report, and deletes with user approval. Never deletes the current worktree. Invoke when asked to "clean up worktrees", "remove merged worktrees", or "prune worktrees".
npx skillsauth add arosenkranz/claude-code-config cleanup-worktreesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Intelligent git worktree cleanup. Discovers all worktrees, checks their status, categorizes them, and removes stale ones safely.
List all worktrees:
git worktree list --porcelain
Parse the output to collect:
HEAD in output)Skip automatically:
~/.claude/worktrees/ (Claude Code internal worktrees — managed separately)Also run a basic sanity check:
git worktree list
If any worktree paths are missing from disk (unlocked but directory gone), note them as "orphaned" — they should be pruned first:
git worktree prune
For each remaining worktree branch, check in this order:
2a. Is the branch merged into main?
git branch --merged main | grep "<branch-name>"
If it appears: category = Merged.
2b. Is there an open or closed PR?
gh pr list --head "<branch-name>" --state all --json number,state,title,mergedAt
state: MERGED: category = PR Merged (if not already caught by 2a)state: CLOSED (not merged): category = PR Closed (Abandoned)state: OPEN: category = Active (has open PR — do not delete)2c. Does the remote branch still exist?
git ls-remote --heads origin "<branch-name>"
2d. Does the worktree have uncommitted changes?
git -C "<worktree-path>" status --porcelain
If there are uncommitted changes, mark as Dirty regardless of other categories. Never auto-delete dirty worktrees.
Display the results in a clear table:
## Worktree Status Report
### Safe to Delete
| Branch | Path | Reason | PR |
|--------|------|--------|----|
| train-123-my-feature | ~/workspace/... | Merged | #45 (merged) |
| train-456-old-thing | ~/workspace/... | Remote deleted | None |
### Active (keeping)
| Branch | Path | Status |
|--------|------|--------|
| train-789-current | ~/workspace/... | Open PR #67 |
### Dirty (manual review needed)
| Branch | Path | Changes |
|--------|------|---------|
| train-999-wip | ~/workspace/... | 3 modified files |
### Skipped
| Path | Reason |
|------|--------|
| ~/.claude/worktrees/... | Claude Code internal worktree |
| (main worktree) | Primary checkout |
If there is nothing to delete, say so clearly and stop.
Present the "Safe to Delete" list and ask:
"Ready to remove N worktrees listed above. Proceed? (This removes the worktree directories and their local branch refs.)"
Wait for explicit user confirmation before deleting anything.
If confirmed, for each worktree in the "Safe to Delete" list:
git worktree remove "<worktree-path>" --force
git branch -d "<branch-name>"
Notes on --force: Only use it for worktrees where the branch is confirmed merged or remote-deleted. If git worktree remove without --force fails for an unexpected reason, stop and report — do not blindly retry with --force.
For dirty worktrees: never delete. Tell the user to commit, stash, or discard changes manually first.
After deletion, run:
git worktree list
Report:
git worktree prune was run to clean up any remaining administrative filesgit worktree remove fails unexpectedly, stop and report rather than escalating with destructive flags.tools
Lightweight orchestrator for spec-before-plan workflow. Use when starting a feature with ambiguous requirements. Walks SPEC.md → PLAN.md → execute, delegating to /superpowers:writing-plans and /superpowers:executing-plans. Invoke when asked to "spec this out", "spec-first", "spec and plan for X", or when feature requirements are vague.
tools
Problem Statement Co-Authoring Skill
development
Structure and maintain professional brag documents with clear templates for accomplishments, projects, and growth tracking. Use when documenting achievements, creating brag document entries, formatting accomplishments, or tracking career progress.
development
Analyze technical documentation for clarity, conciseness, and effectiveness using Google Technical Writing principles. Use when reviewing documentation, checking writing quality, improving docs, or providing writing feedback.