worktree-hygiene
Installation
SKILL.md
Worktree Hygiene
A worktree is shared mutable state. Removal is destructive, a handover is an ownership transfer, and every worktree shares the main repository's
.git. Each rule below guards against a destructive failure seen in production.
"An actor" below is anything that writes into a worktree: an agent, a subagent, a human session, a process one of them spawned.
When to Apply
- Removing a git worktree, or retiring a branch after it landed (its worktree, its local ref, optionally its remote ref)
- Handing a worktree or branch from one actor to another, or resuming an actor that owns one
- Several actors (agents, sessions, scripts) share one repository or one worktree
- Checking out branches or writing
git configwhile other worktrees exist
Removing a Worktree
Verify all three before git worktree remove, freshly, in this order:
- Clean, by fresh status codes. Run a fresh
git -C <tree> status --porcelain -ualland read the STATUS CODES. Never trust a prior report's dirty count: counts cannot distinguish new files from removal-in-progress deletions, and codes can.-ualloverrides astatus.showUntrackedFiles=noconfig that would silently hide untracked files.