agentleFS
lastxuanainlastxuanain/ainward-skills/skills/repo-clean/SKILL.md

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

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    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.

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
  1. Very specific:

    Never delete remote origin branches, active workspace build/dependency caches (node_modules/, .venv/, dist/, build/, target/, .next/), or …

    line 27
  2. Very specific:

    All Git-tracked files (git ls-files), .env* and other local secrets or config, active workspace dependency/build caches, and persistent …

    line 51
  3. Distinctive:

    Offline, read-only scan first: Never run git fetch unprompted, and mutate nothing before the user picks an option.

    line 64
  4. Very specific:

    After step 1 the worktree is clean, so --force should not be needed.

    line 170
  5. Very specific:

    Never run git gc --prune=now, so deleted Git objects stay recoverable.

    line 182

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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-clean or workspace-wide requests; scan only worktrees + branches when the user asks specifically to clean branches or worktrees.
  • Never delete remote origin branches, active workspace build/dependency caches (node_modules/, .venv/, dist/, build/, target/, .next/), or paths outside the current repo and git worktree list.

Host adaptation

  • ask_question below means the host's single-choice question tool (AskUserQuestion in Claude Code, ask_question in 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 plain path/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

  1. Protection floor — never delete, never list as a candidate:
    • The current active worktree, locked worktrees, current HEAD, <base_branch>, main, master, develop, dev, release/*, and all remote origin/* 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 remove silently deletes ignored files such as .env, so Step 3 must preserve them first.
  2. 🟢 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 (推荐:留).
  3. Offline, read-only scan first. Never run git fetch unprompted, 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:

  1. Worktrees (git worktree list --porcelain):
    • 🟢: prunable worktrees whose directory is missing; or clean, unlocked, idle worktrees detached at <base_branch> or mounting a 🟢 branch (below), and whose git -C <wt> status --porcelain --ignored shows no ignored paths other than regenerable caches (node_modules/, .venv/, dist/, build/, target/, .next/, __pycache__/, .cache/, coverage/). Note size via du -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). Inspect status / diff --stat and write a 1-line summary + lean.
  2. Local branches (refs/heads) (include branches mounted in 🟢/🟡 candidate worktrees so both clean in one pass):
    • 🟢 (idle, deterministic, and not untouched—see below): in git branch --merged <base_branch>; or upstream [gone] with 0 commits ahead of <base_branch>; or git cherry <base_branch> <branch> lists only - lines.
    • Untouched means the tip equals the <base_branch> tip, or the branch reflog holds only its branch: Created from entry (never committed to). Such a branch is usually a fresh workspace for a parallel task, so it goes to 🟡, never 🟢.
    • 🟡: hot; untouched; or git cherry has + commits. For the latter, inspect git log -n 8 --oneline <base_branch>..<branch> and git 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).
  3. Stashes (git stash list) (skip when scoped to branches/worktrees):
    • 🟢: idle, and the full patch (git stash show -p, plus the untracked tree stash@{n}^3 when present) already exists identically on <base_branch> or HEAD.
    • 🟡: unique/partial unapplied edits or hot (1-line summary of changed files/intent + (推荐:删 / 留)).
  4. 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 as SPEC*, 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 (🟢 = 0 and 🟡 = 0): confirm clean in 2 lines (mention optional git fetch --prune only 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 .git exceeds 500 MB).
    • 🟢 确定安全(A 项) (omit if A = 0): compact grouped bullets (#ID + short name/link + notable size + 2–4 word reason).
    • 🟡 需拍板(B 项) (omit if B = 0): 1 bullet per item (#ID [类别] 名称 — 1 句内容摘要 → (推荐:删 / 留)). For worktrees, name any non-cache ignored files that will be preserved (.env.local → 回收站).
  • Single ask_question card (adapt to A, B, and K = number of 🟡 items marked 推荐:删; custom #ID picks work via "Other" or chat):
    • (Recommended) 清理全部 🟢 + 推荐删除的 🟡(#...,共 A+K 项) (when K > 0; otherwise (Recommended) 清理全部 🟢 安全项(共 A 项), or (Recommended) 保留全部,暂不清理 when A = 0, K = 0)
    • (Include when A > 0 and K > 0) 仅清理全部 🟢(共 A 项),保留全部 🟡
    • (Include when remotes exist) 先执行 git fetch --prune 刷新远端状态后再重扫
    • 暂不清理

Step 3: Dependency-Safe Execution & Recovery Receipt

  1. Snapshot before mutating anything:
    • git rev-parse every 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.
  2. Execute strictly in order:
    1. Worktrees: git worktree remove <path>, then git worktree prune. After step 1 the worktree is clean, so --force should not be needed; if Git still refuses, stop and report instead of forcing.
    2. Branches: git branch -d for merged branches; git branch -D only for explicitly confirmed 🟡 branches.
    3. Stashes: drop selected stashes in descending index order (stash@{4} before stash@{1}) so indices never shift. Never drop the backup stashes created in step 1.
    4. Scratch/temp files (skip paths inside removed worktrees): move untracked .md scratch files to OS Trash (trash on macOS, gio trash / trash-put on Linux; when no Trash is available, pause before a permanent rm of .md docs); remove confirmed *.orig/*.rej/*.tmp/*.bak.
    5. Never run git gc --prune=now, so deleted Git objects stay recoverable.
  3. 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 in git stash list until the user drops them), and the Trash paths of preserved ignored files.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.