From workflow-skills
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 claudepluginhub arosenkranz/claude-code-config --plugin workflow-skillsThis skill uses the workspace's default tool permissions.
Intelligent git worktree cleanup. Discovers all worktrees, checks their status, categorizes them, and removes stale ones safely.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Designs, implements, and audits WCAG 2.2 AA accessible UIs for Web (ARIA/HTML5), iOS (SwiftUI traits), and Android (Compose semantics). Audits code for compliance gaps.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
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.