| name | teardown |
| description | Clean up completed builds: remove worktrees, delete merged branches, archive plan files, and reset factory state. Trigger: clean up, teardown, remove worktrees, clean factory. |
| user-invocable | true |
/teardown — Factory Cleanup
You are an orchestrator cleaning up after builds complete. Worktrees accumulate, branches linger, plan files scatter. This skill removes everything that's been merged and archives what should be preserved.
What This Skill Does
- Identifies all worktrees, branches, and plan files
- Categorizes each as: merged (safe to remove), active (keep), orphaned (investigate)
- Removes merged worktrees and branches
- Archives completed plan files
- Reports what was cleaned and what remains
Phase 1: INVENTORY
Gather the full state without modifying anything:
git worktree list
git branch
git branch -r
git branch --merged main
git branch --no-merged main
Also scan for:
.claude/worktrees/ directory contents
../worktrees/ directory contents
PLAN-*.md files in any worktree
PRD-*.md files in project root
SHARED_CONTEXT.md entries referencing completed tasks
Phase 2: CATEGORIZE
For each worktree/branch, determine status:
MERGED (safe to remove):
- Branch has been merged into main
- No uncommitted changes in worktree
- All plan steps are checked off
- Critic review score >= 9.5
ACTIVE (keep):
- Branch has NOT been merged
- Worktree has recent commits (< 24 hours)
- Plan has unchecked steps
- Worker may still be running
ORPHANED (investigate):
- Branch exists but no worktree found
- Worktree exists but no branch found
- No commits in > 7 days
- Plan exists but no corresponding worktree
STALE (confirm before removing):
- Branch not merged, no commits in > 48 hours
- Worktree with uncommitted changes and no recent activity
- These require human confirmation before removal
Phase 3: CLEANUP (merged items only)
For each MERGED item, in order:
git worktree remove .claude/worktrees/tNN-description
git branch -d build/tNN-description
git push origin --delete build/tNN-description
Plan file archival:
- Move completed
PLAN-*.md to .claude/archive/plans/ (create if needed)
- Keep
PRD-*.md in project root (they're reference docs, not ephemeral)
SHARED_CONTEXT.md update:
- Move completed tasks from "Active Worktrees" to "Recently Merged"
- Prune "Recently Merged" entries older than 30 days
Phase 4: ORPHAN HANDLING
For each ORPHANED item:
git log main..build/tNN-description --oneline
git branch -D build/tNN-description
echo "Branch build/tNN-description has N unmerged commits. Keep or delete?"
For orphaned worktrees with no branch:
git worktree prune
Phase 5: STALE ITEM REPORT
Do NOT auto-delete stale items. Report them:
Stale items (require human decision):
⚠ build/t05-payments: last commit 3 days ago, 4 uncommitted files
→ Keep working? Or abandon?
⚠ .claude/worktrees/t07-compliance: no branch found, has 12 modified files
→ Orphaned worktree. Review changes before deleting?
Phase 6: REPORT
Factory Cleanup Complete:
Removed:
✓ 3 worktrees (.claude/worktrees/t01, t02, t03)
✓ 3 local branches (build/t01, build/t02, build/t03)
✓ 3 remote branches
✓ 3 plan files archived to .claude/archive/plans/
Kept (active):
• build/t04-api-routes (worker in progress, 6/10 steps done)
Needs attention:
⚠ build/t05-payments: stale 3 days, human decision needed
⚠ Orphaned worktree: .claude/worktrees/t07-compliance
Disk space recovered: ~45 MB
Remaining worktrees: 1 active, 1 stale
Safety Rules
- Never delete unmerged branches without human confirmation.
- Never force-remove worktrees with uncommitted changes unless the human explicitly says to.
- Always
git worktree prune before listing to clean broken references first.
- Archive, don't delete plan files — they're useful for future reference.
- Update SHARED_CONTEXT.md so the next planner has accurate state.
- Check for running agents before removing a worktree — a worker may still be executing.