name: code-cleaner description: Audit codebase for dead code, style violations, and structural issues. Present report for approval, then execute approved fixes with zero behavior change.
Two-phase cleanup: audit everything first, touch nothing until approved. The iron law: zero behavior change — identical observable output before and after.
$ARGUMENTS
If blank → entire project from repository root.
Read the project's coding standards in this priority order:
CLAUDE.md at project root (primary authority).eslintrc*, .prettierrc*, tsconfig.jsonpyproject.toml, setup.cfg, .flake8, ruff.tomlphpcs.xml, .php-cs-fixer.php.golangci.yml.editorconfigCLAUDE.md rules always win over tool configs when they conflict.
Systematically scan the target for three categories of issues.
A. Dead code
TODO/FIXME comments older than 90 days (check with git log)
# Check age of TODO/FIXME comments
git log --all -p --reverse -S "TODO" -- <file> | head -40
B. Style and norm violations
C. Structural issues
Produce a structured report with three sections. Each item follows this format:
file:line — description — severity — proposed fix
Severity levels:
info: optional improvement (minor structural suggestions)
CODE-CLEAN AUDIT — <target>
Scanned: <N files, N lines>
Norms source: <CLAUDE.md / .eslintrc / PEP8 fallback / etc.>
═══ DEAD CODE ═══
1. src/utils.py:42 — unused import `os` — warn — delete import
2. src/api/handler.ts:118-134 — commented-out block — warn — delete block
3. ...
═══ STYLE VIOLATIONS ═══
1. src/core/parser.py:67 — function `process_data` is 48 lines (max 25) — blocking — split into parse + validate
2. ...
═══ STRUCTURAL ISSUES ═══
1. lib/helpers/auth.ts — auth logic in helpers/, should be in lib/auth/ — info — move file
2. ...
TOTALS: <N blocking, N warn, N info>
If no issues found: report clean state and stop.
Present the report. Ask the user:
Do NOT proceed to Phase 2 until the user explicitly approves.
If the user says "all" or "go ahead" → approve everything. If the user cherry-picks → execute only approved items.
Process approved dead-code items first — they're the safest changes:
Guard rail: if a symbol is exported or part of a public API, do NOT delete it even if it appears unused internally. Flag it and ask for explicit per-item confirmation.
For approved style and structural items:
$HOME/.claude/agents/refactorer.mdDo NOT call the /refactor skill — invoke the agent directly.
If cleanup reveals actual bugs (not style issues — real defects):
Append each bug to .claude/audits/BUGS-FOUND.md (run mkdir -p .claude/audits first):
## [date] Bug found during code-clean
- **File**: <file:line>
- **Description**: <what's wrong>
- **Severity**: <estimate>
- **Discovered while**: <what cleanup task surfaced it>
Do NOT fix bugs here. Cleanup and bugfixing are separate concerns.
After all changes are applied:
Run tests if available:
# detect and run project test suite
Run linter/formatter if available
CODE-CLEAN COMPLETE — <target>
REMOVED:
- <N> dead code items (unused imports, functions, commented blocks)
REFACTORED:
- <N> style fixes
- <N> structural improvements
SKIPPED (user decision):
- <item> — <reason>
BUGS FOUND: <N> (logged to .claude/audits/BUGS-FOUND.md)
TESTS: passing / no test suite / <failures>
/ship-feature for a proper redesign.