Agent skill
80-04-repo-hygiene
Deep audit and cleanup of repository clutter — stale worktrees, dead branches, orphan files, legacy artifact directories, disk hogs, and convention violations. Use when a repo feels messy, when disk space is low, or when asked to clean up / maintain a repository.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/80-04-repo-hygiene
SKILL.md
80.04 Repo Hygiene
Audit a repository for clutter, stale artifacts, and convention violations, then present an evidence-backed cleanup plan for human approval.
When to Use
- Repository feels cluttered or disorganized
- Disk space is low and repo is suspiciously large
- Before open-sourcing or sharing a repo
- Periodic maintenance (monthly/quarterly)
- User asks to "clean up", "maintain", or "audit" a repo
Process Overview
- Phase 1: Fast Survey — Inventory everything in seconds
- Phase 2: Deep Oracle Dig — Parallel agent investigates each suspect with evidence
- Phase 3: Present Report — Evidence-backed table with classifications
- Phase 4: Execute — On human approval, run cleanup commands
Phase 1: Fast Survey
Run a quick inventory of the target repo. Collect raw data, do not classify yet.
cd <repo-root>
# Identity
git rev-parse --show-toplevel
git remote -v
# Worktrees
git worktree list
# Branches
git branch -a -v
git branch --merged main
git branch --no-merged main
# Git status
git status --short
git ls-files --others --exclude-standard
# Root files
ls -1
# Disk hogs
du -sh . target/ node_modules/ .worktrees/*/ 2>/dev/null
# Stale remote refs
git remote prune origin --dry-run 2>&1
Collect all output. Identify suspect items for Phase 2.
Phase 2: Deep Oracle Dig
Delegate a single oracle worker to investigate ALL suspect items. The oracle MUST investigate each item with the full checklist — not guess by filename.
Dispatch Template
Use teams to delegate:
teams(action: 'delegate', useWorktree: false, tasks: [{
text: '<oracle prompt below>',
assignee: 'oracle-repo-audit'
}])
Oracle Prompt
Construct the oracle prompt with:
- Repo path — absolute path
- Survey data — paste ALL Phase 1 output
- Suspect items list — every file, dir, worktree, branch that needs investigation
- The investigation checklist (below)
Investigation Checklist (per item)
For EACH suspect file or directory, the oracle MUST:
- Read actual content — first 50 lines for files,
ls -lafor directories - Check git history —
git log --oneline -5 -- <path>— when added, by whom, why - Check if tracked —
git ls-files <path>— tracked or gitignored? - Search for references —
rg -l '<name>' --glob '!target' --glob '!node_modules'— is anything using it? - Check size —
du -sh <path> - Compare duplicates — if two similar items exist (e.g. justfile vs Makefile), diff them
- Classify with evidence:
SAFE_DELETE— no references, gitignored or stale, evidence clearARCHIVE_THEN_DELETE— has value but superseded or obsoleteNEEDS_HUMAN_DECISION— active or ambiguous, provide contextKEEP— actively used, referenced, or essentialCONVENTION_FIX— not delete but needs restructuring
For worktrees:
- Check if branch is merged into main
- Check for uncommitted changes (
git statusin worktree) - Check target/node_modules size within worktree
- Check last activity date
For branches:
- Check if changes exist in main (merged, cherry-picked, squash-merged)
- Check last commit date and age
- Check for open PRs (
gh pr listif available)
Mandatory Audit Categories
The oracle MUST check for ALL of these, even if not in the initial suspect list:
Legacy Artifact Directories
Flag any of these directories — they should be tk tickets instead:
.oracle/→ should be tickets taggedresearch,oracle.reviews/→ should be tickets taggedreview.plans/→ should be tickets taggedplan.design-specs/→ should be tickets taggeddesign-specdocs/postmortems/→ should be tickets taggedpostmortemdocs/research/→ should be tickets taggedresearch
For each found: list contents, check if equivalent tickets exist, recommend migration path.
Disk Hogs
target/(Rust),node_modules/,.next/,dist/,build/— in main repo AND all worktrees- Database dumps, backups, large binary files
- Docker volumes / data directories
Convention Violations
config.tomltracked alongsideconfig.template.toml(local config should be gitignored)- Duplicate build systems (justfile + Makefile, package.json scripts + Makefile)
.envfiles tracked (should be gitignored with.env.exampletracked)- Lock files missing or extraneous
Root Clutter
- One-off test/debug scripts
- Evaluation/benchmark result files
- Backup files (
*.backup,*.bak,*.old) - Implementation plans, migration docs that belong in docs/ or tickets
- Empty directories
Stale Tickets
- Untracked
.tickets/files - Modified
.tickets/files not committed in_progresstickets with no recent activity
Second-Pass Check
After the main investigation, the oracle MUST do a second pass:
- Cross-reference findings — did any "KEEP" item reference a "SAFE_DELETE" item?
- Check for orphaned chains — if deleting X, does Y become orphaned?
- Verify no false positives — re-read any item classified SAFE_DELETE that is git-tracked
- Size audit — do the individual sizes add up to the total? Any hidden disk hogs missed?
- Pattern check — are there categories of clutter not covered by the initial suspect list?
Phase 3: Present Report
The oracle creates a ticket (tagged research,oracle,maintenance) with findings organized as:
Report Structure
# Repo Hygiene Audit: <repo-name>
## 1. IMMEDIATE SAFE DELETES
Per item: what, evidence, size, delete command
## 2. CONVENTION FIXES
Per item: what's wrong, what it should be, fix command
## 3. LEGACY ARTIFACT MIGRATION
Per directory: contents summary, recommended tk ticket tags, migration steps
## 4. ARCHIVE THEN DELETE
Per item: what, why archive first, size, commands
## 5. NEEDS HUMAN DECISION
Per item: what, context, options with trade-offs
## 6. KEEP
Per item: brief justification
## 7. DISK RECOVERY SUMMARY
Table: item | size | classification
Totals: immediate | with approval | total potential
## 8. CLEANUP COMMANDS
Ready-to-run bash script, split into:
- Safe (no confirmation needed)
- Needs confirmation (commented out)
Phase 4: Execute
Present the report to the human. On approval:
- Run safe deletes first
- Ask about each human-decision item
- Run convention fixes
- Commit any tracked changes (
.gitignoreupdates, file moves) - Report final disk recovery
Never execute cleanup without human approval. The report IS the deliverable — execution is optional.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?