| name | cleanup-worktree |
| description | Remove a merged slice's worktree and delete its branch. Run from the main checkout after a PR is merged. Triggers on /cleanup-worktree, "clean up the worktree", "remove the merged worktree". |
/cleanup-worktree
Remove the worktree + branch for a slice that has been merged.
When to use
- A slice's PR has been merged to main.
- You're back in the main checkout (not the worktree itself).
Steps
- Identify which worktree to clean up. Ask the user if ambiguous.
- List existing worktrees:
git worktree list
- Verify the branch is merged:
git fetch origin
git branch --merged origin/main | grep "<branch-name>"
If not merged, stop and ask the user. Do not delete unmerged work.
- Remove the worktree:
git worktree remove "<path-to-worktree>"
- Delete the branch:
git branch -d "<branch-name>"
- Prune stale remote refs:
git fetch --prune origin
Hard rules
- Never delete an unmerged branch without explicit user OK.
-d (safe) is the default; -D (force) is a destructive op.
- Don't run from inside the worktree you're trying to remove. Switch to the main checkout first.
- Don't bulk-delete worktrees. One at a time, verified each.
Side benefits
- Frees disk
- Reduces visual clutter in
git worktree list
- Prevents stale state from confusing future slices