Codebase Cleanup Audit
Find what can be deleted, merged, renamed, archived, or made easier to manage. Audit first; edit only when the user asks for implementation.
Quick Start
Read local rules, then run the bundled snapshot:
node scripts/cleanup-snapshot.mjs --root /path/to/project
For a focused cleanup, scan the smallest useful directory instead of the whole repo:
node scripts/cleanup-snapshot.mjs --root /path/to/project/apps/admin
node scripts/cleanup-snapshot.mjs --root /path/to/project/packages/auth
node scripts/cleanup-snapshot.mjs --root /path/to/project/docs
Default report path: .scratch/<datetime>-cleanup-snapshot.html under the scanned root. HTML reports written inside .scratch are timestamp-prefixed. Use --format json|markdown --out - when you need a machine-only stdout snapshot.
Use codebase-design when cleanup involves shallow modules, noisy interfaces, misplaced seams, deletion-test calls, or testability/locality problems. Escalate to improve-codebase-architecture when the cleanup finding should become a visual architecture candidate instead of a safe cleanup batch.
Workflow
- Define scope: whole repo, package, app area, docs, tests, scripts, assets, generated output, or workspace clutter. Prefer a scoped
--root when the request names one area.
- Read local truth:
AGENTS.md, CLAUDE.md, README.md, CONTEXT.md, ADRs, manifests, scripts, CI, package exports, routes, deploy config, and docs.
- Map the repo with
cleanup-snapshot.mjs, rg --files, package manifests, test config, route lists, and dependency tooling available in the project.
- Search for cleanup signals:
legacy, old, deprecated, unused, dead, backup, copy, tmp, wip, duplicate file names with content variants, duplicate function bodies, duplicate function names with body variants, generic buckets, empty folders, stale docs, disabled tests, skipped scripts, TODO/FIXME/HACK clusters, generated files in source, and unused exports/deps when tooling supports it.
- Classify each finding:
- delete: safe dead artifact, generated output, duplicate copy, stale scratch file
- merge: duplicate docs, repeated config, same concept split across shallow modules
- rename/reword: vague name, misleading skill description, stale terminology
- archive: potentially useful history not needed in active source
- defer: needs product decision, external contract, migration plan, or more evidence
- Apply the deletion test from
codebase-design: if removing a module removes complexity, candidate is cleanup; if complexity spreads to callers, propose a deeper module instead and route that finding through improve-codebase-architecture when it needs architecture exploration.
- Report before editing. Include risk, evidence, safe batch order, verification commands, and what must not move.
Output
## Cleanup Audit
- Scope:
- Local rules:
- Snapshot:
- Safe deletes:
- Merge/dedupe:
- Rename/reword:
- Architecture candidates:
- Keep because:
- Risks/blockers:
- Suggested first batch:
- Verification:
Keep wording direct. Prefer concrete file paths and exact search evidence over broad opinions.
1---2name: codebase-cleanup-audit3description: Audits a codebase for removable legacy, unused, duplicate, stale, confusing, or overcomplicated pieces before cleanup. Use when the user asks to simplify a repo, remove dead code, find legacy or unused things, fix duplicate wording/files, or research cleanup opportunities; use codebase-design for module-depth checks and improve-codebase-architecture when cleanup becomes an architecture candidate.4---56# Codebase Cleanup Audit78Find what can be deleted, merged, renamed, archived, or made easier to manage. Audit first; edit only when the user asks for implementation.910## Quick Start1112Read local rules, then run the bundled snapshot:1314```bash15node scripts/cleanup-snapshot.mjs --root /path/to/project16```1718For a focused cleanup, scan the smallest useful directory instead of the whole repo:1920```bash21node scripts/cleanup-snapshot.mjs --root /path/to/project/apps/admin22node scripts/cleanup-snapshot.mjs --root /path/to/project/packages/auth23node scripts/cleanup-snapshot.mjs --root /path/to/project/docs24```2526Default report path: `.scratch/<datetime>-cleanup-snapshot.html` under the scanned root. HTML reports written inside `.scratch` are timestamp-prefixed. Use `--format json|markdown --out -` when you need a machine-only stdout snapshot.2728Use `codebase-design` when cleanup involves shallow modules, noisy interfaces, misplaced seams, deletion-test calls, or testability/locality problems. Escalate to `improve-codebase-architecture` when the cleanup finding should become a visual architecture candidate instead of a safe cleanup batch.2930## Workflow31321. Define scope: whole repo, package, app area, docs, tests, scripts, assets, generated output, or workspace clutter. Prefer a scoped `--root` when the request names one area.332. Read local truth: `AGENTS.md`, `CLAUDE.md`, `README.md`, `CONTEXT.md`, ADRs, manifests, scripts, CI, package exports, routes, deploy config, and docs.343. Map the repo with `cleanup-snapshot.mjs`, `rg --files`, package manifests, test config, route lists, and dependency tooling available in the project.354. Search for cleanup signals: `legacy`, `old`, `deprecated`, `unused`, `dead`, `backup`, `copy`, `tmp`, `wip`, duplicate file names with content variants, duplicate function bodies, duplicate function names with body variants, generic buckets, empty folders, stale docs, disabled tests, skipped scripts, TODO/FIXME/HACK clusters, generated files in source, and unused exports/deps when tooling supports it.365. Classify each finding:37 - delete: safe dead artifact, generated output, duplicate copy, stale scratch file38 - merge: duplicate docs, repeated config, same concept split across shallow modules39 - rename/reword: vague name, misleading skill description, stale terminology40 - archive: potentially useful history not needed in active source41 - defer: needs product decision, external contract, migration plan, or more evidence426. Apply the deletion test from `codebase-design`: if removing a module removes complexity, candidate is cleanup; if complexity spreads to callers, propose a deeper module instead and route that finding through `improve-codebase-architecture` when it needs architecture exploration.437. Report before editing. Include risk, evidence, safe batch order, verification commands, and what must not move.4445## Output4647```md48## Cleanup Audit49- Scope:50- Local rules:51- Snapshot:52- Safe deletes:53- Merge/dedupe:54- Rename/reword:55- Architecture candidates:56- Keep because:57- Risks/blockers:58- Suggested first batch:59- Verification:60```6162Keep wording direct. Prefer concrete file paths and exact search evidence over broad opinions.