/git-hygiene:worktree-cleanupfrom Git Hygiene
Use whenever the user asks to clean up stale branches AND worktrees, prune old worktrees, remove leftover agent-created checkouts (e.g. .claude-worktrees), or when a "clean gone branches" ask mentions worktrees — "clean up my stale/outdated branches and worktrees", "prune old worktrees", "tidy my checkouts". Extends gone-branch cleanup (e.g. /clean_gone) to the worktrees attached to those branches: inventories candidates with their risk, then removes only what the user approves, item by item.
Ships in Git Hygiene. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Gone-branch cleanup tools handle branches; this skill also retires the worktrees those branches live in — including the .claude-worktrees-style checkouts that agent sessions create and abandon. The invariant: nothing is deleted without the user seeing it in a candidate list first, and nothing holding unsaved or unpushed work is deleted without an explicit, per-item "yes".
git fetch --prune
git worktree list --porcelain
git branch -vv # upstream state; [gone] markers
git branch --merged <default-branch>
git worktree prune --dry-run -v # orphaned admin entries (dir already deleted)
| Tier | What | Default action |
|---|---|---|
| 🟢 Orphaned admin entries | git worktree prune --dry-run hits — the directory is already gone | Prune |
🟢 Worktrees on [gone] branches | Remote branch deleted (merged PR, typically) | Propose removal |
| 🟡 Worktrees on branches merged into the default branch | Work landed; checkout is residue | Propose removal |
| 🔴 Stale but unmerged | Old mtime, branch never merged, or no upstream at all | Report only — never propose deletion; unmerged work may be the only copy |
For every proposed worktree, check what it's holding before showing it to the user:
git -C <worktree> status --porcelain # uncommitted changes?
git -C <worktree> rev-parse --abbrev-ref @{u} 2>/dev/null # upstream, or empty if none
Then count unpushed commits. If the branch has an upstream, git -C <worktree> log --oneline @{u}.. lists them. If it has none (@{u} printed nothing — common for the fresh, never-pushed branches these abandoned worktrees sit on), don't run @{u}..: it fatals with "no upstream configured". Treat every local commit not already on the default branch as unpushed instead: git -C <worktree> log --oneline <default-branch>..HEAD (or all of HEAD when the branch shares no history with the default).
Anything dirty or unpushed gets flagged 🔴 in the candidate list regardless of tier — deleting it destroys work.
Show one table: path, branch, tier, dirty/unpushed flags, last-commit age. Ask for approval per item (or an explicit "all the green ones"). A blanket "clean it up" from before the list existed does not count as approval of the list — the user is approving specific deletions, not the concept of cleanup.
For each approved item, in this order:
git worktree remove <path> # refuses dirty trees — good; --force only with explicit per-item consent
git branch -D <branch> # after its worktree is gone; only for [gone]/merged branches from the approved list
git worktree prune # clear remaining admin entries
Never touch the main checkout or the worktree the current session is running in. Close with a summary of what was removed, what was kept and why (especially 🔴 items), and disk space reclaimed if easily available.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
2 skills in this plugin
git-hygiene@cypherpoet-toolchest is listed by cypherpoet/cypherpoet-toolchest — review the source before installing
npx claudepluginhub cypherpoet/cypherpoet-toolchest --plugin git-hygiene