repo-clean
Skill5 starsChanged 10 days agoMITView on GitHub
Low-friction Git repository and worktree cleanup for merged branches, stashes, and scratch files. Triggers: /repo-clean, "repo clean", "clean workspace", "cleanup leftovers", "清理仓库", "清理工作区", "清理 worktree", "清理中间产物".
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Cor-Incorporated/claude-code-skillstheir own version, first seen Sep 3, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Cor-Incorporated/claude-code-skills★ 5same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository6 other files it gives its agents.
- agent-reviewSkill
- code-syncSkill
- frontend-craftSkill
- plan-reviewSkill
- project-evolutionSkill
- work-reportSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
Never delete remote origin branches, active workspace build/dependency caches (node_modules/, .venv/, dist/, build/, target/, .next/), or …
- Very specific: line 51
All Git-tracked files (git ls-files), .env* and other local secrets or config, active workspace dependency/build caches, and persistent …
- Distinctive: line 64
Offline, read-only scan first: Never run git fetch unprompted, and mutate nothing before the user picks an option.
- Very specific: line 170
After step 1 the worktree is clean, so --force should not be needed.
- Very specific: line 182
Never run git gc --prune=now, so deleted Git objects stay recoverable.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Repo Clean (低心智负担仓库与关联工作区清理)
Clean up leftover worktrees, local branches, stashes, and ephemeral AI scratch/plan files after PR merges or parallel multi-agent tasks—separating fully deterministic cleanups from items needing judgment so the user decides in seconds without auditing raw Git trivia.
When to use
- Tidying stale checkouts, merged/squashed branches, stashes, or temporary AI planning files after shipping PRs or running parallel agent threads.
- Adaptive scope: scan all 4 categories (worktrees, branches, stashes, scratch
files) on
/repo-cleanor workspace-wide requests; scan only worktrees + branches when the user asks specifically to clean branches or worktrees. - Never delete remote
originbranches, active workspace build/dependency caches (node_modules/,.venv/,dist/,build/,target/,.next/), or paths outside the current repo andgit worktree list.
Host adaptation
ask_questionbelow means the host's single-choice question tool (AskUserQuestionin Claude Code,ask_questionin Antigravity). Without one, print the options as a numbered list and wait for a reply. Never add a manual "Other" option when the host adds one natively.- File links follow the host's own convention first (e.g. relative
[plan.md](docs/plan.md)in Claude Code); otherwise use[plan.md](file:///abs/path/plan.md), falling back to plainpath/plan.md. - Template labels below are written in Chinese for brevity; translate them into the user's language when replying in another language.
Hard rules
- Protection floor — never delete, never list as a candidate:
- The current active worktree,
lockedworktrees, currentHEAD,<base_branch>,main,master,develop,dev,release/*, and all remoteorigin/*refs. - All Git-tracked files (
git ls-files),.env*and other local secrets or config, active workspace dependency/build caches, and persistent AI/editor configs (CLAUDE.md,AGENTS.md,GEMINI.md,.cursorrules,.cursor/rules/**,.claude/settings*.json,.claude/skills/**,.agents/**). - This floor also applies inside worktrees slated for removal:
git worktree removesilently deletes ignored files such as.env, so Step 3 must preserve them first.
- The current active worktree,
🟢is only for fully deterministic, zero-ambiguity items that are also idle (see the idle signal below). Every heuristic semantic match—squash or ported branches whose patch IDs differ, untracked AI plan docs, worktrees holding non-cache ignored files—stays in🟡with a 1-line digest and(推荐:删)or(推荐:留).- Offline, read-only scan first. Never run
git fetchunprompted, and mutate nothing before the user picks an option. Reply in the user's language.
Idle signal (> 10 min)
An item is idle only when all of its signals are older than 10 minutes;
when a signal cannot be read, treat the item as hot (🟡):
- Branch: newest reflog entry (
git reflog show --date=unix -n 1 refs/heads/<b>, which also covers branch creation) and tip committer date (git log -1 --format=%ct <b>). - Worktree: its branch's signals plus the mtimes of its index and
HEAD(git -C <wt> rev-parse --git-path index/--git-path HEAD) and of any modified or untracked files. - Stash: the stash commit date (
git log -1 --format=%ct stash@{n}). - Scratch/temp file: file mtime.
Workflow
Step 1: Offline Scan & Classification
Anchor the repo root, shared .git dir, and <base_branch> (origin/HEAD →
main / master / HEAD), then classify non-protected items read-only:
- Worktrees (
git worktree list --porcelain):🟢:prunableworktrees whose directory is missing; or clean, unlocked, idle worktrees detached at<base_branch>or mounting a🟢branch (below), and whosegit -C <wt> status --porcelain --ignoredshows no ignored paths other than regenerable caches (node_modules/,.venv/,dist/,build/,target/,.next/,__pycache__/,.cache/,coverage/). Note size viadu -sh.🟡: dirty,locked, hot, mounting an unmerged or untouched branch (likely a fresh workspace for a parallel task), or holding non-cache ignored files (name them, e.g..env.local). Inspectstatus/diff --statand write a 1-line summary + lean.
- Local branches (
refs/heads) (include branches mounted in🟢/🟡candidate worktrees so both clean in one pass):🟢(idle, deterministic, and not untouched—see below): ingit branch --merged <base_branch>; or upstream[gone]with 0 commits ahead of<base_branch>; orgit cherry <base_branch> <branch>lists only-lines.- Untouched means the tip equals the
<base_branch>tip, or the branch reflog holds only itsbranch: Created fromentry (never committed to). Such a branch is usually a fresh workspace for a parallel task, so it goes to🟡, never🟢. 🟡: hot; untouched; orgit cherryhas+commits. For the latter, inspectgit log -n 8 --oneline <base_branch>..<branch>andgit diff --stat, spot-checking target files on<base_branch>. If the capability clearly landed via squash merge or semantic port, mark(推荐:删 — 已 Squash/语义合入); otherwise(推荐:留)(or(推荐:删)for a clearly obsolete spike).
- Stashes (
git stash list) (skip when scoped to branches/worktrees):🟢: idle, and the full patch (git stash show -p, plus the untracked treestash@{n}^3when present) already exists identically on<base_branch>orHEAD.🟡: unique/partial unapplied edits or hot (1-line summary of changed files/intent +(推荐:删 / 留)).
- Ephemeral AI scratch & temp files (current workspace + kept worktrees
only; skip when scoped to branches/worktrees):
🟢: idle hard temp leftovers (*.orig,*.rej,*.tmp,*.bak,*.swp).🟡(narrow AI scratch match only): untracked items matching.claude/worktrees/,.claude/plans/,.cursor/plans/,.worktrees/,docs/plans/,PLAN*,ANALYSIS*,WALKTHROUGH*,REVIEW*,*推演*,*排查*. Do not flag general docs such asSPEC*,DESIGN*,TODO*,NOTES*. Read at most the first ~50 lines per file (deep-read at most 10 files; summarize the rest by filename/mtime), cross-check against the codebase, and write a 1-line digest +(推荐:删 — 方案已落地)or(推荐:留 — 尚未实现).
Step 2: Dual-Zone Summary & Single Decision Card
- Clean exit (
🟢 = 0and🟡 = 0): confirm clean in 2 lines (mention optionalgit fetch --pruneonly if remotes exist; no question card). - Numbered report (
#1..#N):- Headline (1 line):
扫描完成:共 X 项可归整(约释放 Y MB)| 🟢 确定安全 A 项 | 🟡 需拍板 B 项(append a 1-line passive tip only if.gitexceeds 500 MB). 🟢 确定安全(A 项)(omit ifA = 0): compact grouped bullets (#ID+ short name/link + notable size + 2–4 word reason).🟡 需拍板(B 项)(omit ifB = 0): 1 bullet per item (#ID [类别] 名称 — 1 句内容摘要 → (推荐:删 / 留)). For worktrees, name any non-cache ignored files that will be preserved (.env.local → 回收站).
- Headline (1 line):
- Single
ask_questioncard (adapt toA,B, andK= number of🟡items marked推荐:删; custom#IDpicks work via "Other" or chat):(Recommended) 清理全部 🟢 + 推荐删除的 🟡(#...,共 A+K 项)(whenK > 0; otherwise(Recommended) 清理全部 🟢 安全项(共 A 项), or(Recommended) 保留全部,暂不清理whenA = 0, K = 0)- (Include when
A > 0andK > 0)仅清理全部 🟢(共 A 项),保留全部 🟡 - (Include when remotes exist)
先执行 git fetch --prune 刷新远端状态后再重扫 暂不清理
Step 3: Dependency-Safe Execution & Recovery Receipt
- Snapshot before mutating anything:
git rev-parseevery branch and stash slated for deletion.- For each approved dirty worktree: back up tracked and untracked changes
with
git -C <wt> stash push --include-untracked -m "repo-clean backup: <branch>"and record the stash SHA (the stash list is shared across worktrees, so the backup survives removal). - For each worktree slated for removal: move every non-cache ignored path
(
.env*, local config, data files) to OS Trash and record the paths.
- Execute strictly in order:
- Worktrees:
git worktree remove <path>, thengit worktree prune. After step 1 the worktree is clean, so--forceshould not be needed; if Git still refuses, stop and report instead of forcing. - Branches:
git branch -dfor merged branches;git branch -Donly for explicitly confirmed🟡branches. - Stashes: drop selected stashes in descending index order (
stash@{4}beforestash@{1}) so indices never shift. Never drop the backup stashes created in step 1. - Scratch/temp files (skip paths inside removed worktrees): move untracked
.mdscratch files to OS Trash (trashon macOS,gio trash/trash-puton Linux; when no Trash is available, pause before a permanentrmof.mddocs); remove confirmed*.orig/*.rej/*.tmp/*.bak. - Never run
git gc --prune=now, so deleted Git objects stay recoverable.
- Worktrees:
- Receipt: cleaned counts + freed space, retained
🟡items, and—whenever anything was deleted or backed up—a copy-pasteable recovery block:git branch <name> <sha>,git stash apply <sha>for dropped stashes and worktree backups (noting the backups stay ingit stash listuntil the user drops them), and the Trash paths of preserved ignored files.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

