Agent skill · lobehub
cleanup-git-worktrees
Use for stale-worktree, Git registration and branch audits. Managed removal uses the repo lifecycle.
What it needs
About 5k tokens when loaded.
What this skill does
Cleanup Git Worktrees Use the bundled script to make classification deterministic. Treat cleanup as a destructive action: audit first, show the exact candidates grouped by why they are deletable, and obtain one explicit approval before applying deletion unless the user's current request already names the exact targets. Aim for a single approval round-trip, not a per-item Q&A. Workflow 1. Run the audit from any worktree in the repository: --fetch: prune the remote first. Omit only when offline and say so. --gh: look up each branch's PR (number, state, head SHA) with the gh CLI. This is what turns [gone] into a verified merge; use it whenever gh is authenticated. It costs roughly one second per branch, so run it in the background on large repos. --stale-days N: mark clean branches idle longer than N days with nothing unpushed as candidate-stale. The repository default the user has approved is 15 days. --noise REGEX: untracked paths that never count as dirt (default nodemodules \.goal-tracing/). 2. Interpret classifications: Classification Meaning Action --- --- --- protected-branch main, canary, or the base ref never protect-current the worktree running the command never protect-dirty tracked modifications, or untracked files outside the noise regex keep; list the files candidate-merged tip is an ancestor of the base delete candidate-pr-merged PR state MERGED and local tip == PR head SHA delete candidate-pr-closed PR CLOSED and tip == PR head or nothing unpushed delete candidate-gone upstream pruned and nothing unpushed delete after confirming PR state candidate-stale older than --stale-days, clean, nothing unpushed delete review-pr-merged-ahead PR merged but local tip has extra commits check the extra commits by subject (below) review-gone-unpushed upstream pruned but local-only commits exist keep; deleting loses work review-no-upstream no upstream, not merged keep unless the user names it review-detached detached HEAD worktree keep; show its dirty files broken-regis …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills lobehub/cleanup-git-worktrees