Code Cleanup Pruner
Overview
Follow a behavior-preserving cleanup workflow: detect candidates, remove only what is defensible, and prove no regressions with lint/build/tests before finishing.
Workflow
1) Build a Safe Baseline
- Inspect current repo state with
git status --short. - Identify validation commands used by the project (
test,lint,build, static analysis). - Run at least one relevant validation command before editing to establish a baseline.
2) Find Cleanup Candidates
Use multiple signals instead of guessing:
- Run
scripts/find_duplicate_blocks.py . --min-lines 10to detect repeated code blocks. - Search for stale markers:
rg -n "TODO.*remove|deprecated|obsolete|legacy|unused|dead code" .
- Use language-specific unused checks when available:
- TypeScript:
npx tsc --noEmit --noUnusedLocals --noUnusedParameters - Python:
ruff check . --select F401,F841 - Go:
go vet ./...(andstaticcheck ./...when installed)
- TypeScript:
- Detect likely orphan files by checking whether modules are imported/referenced.
3) Prioritize Low-Risk Removals
Prioritize in this order:
- Unreferenced private helpers and files.
- Exact duplicate logic that can be centralized.
- Conditional branches that are permanently unreachable.
Avoid risky removals unless explicitly requested:
- Public API surface changes.
- Behavior changes mixed with cleanup.
- Large refactors without test coverage.
4) Apply Minimal, Traceable Changes
- Keep each cleanup slice focused on one concern.
- Preserve observable behavior; if behavior must change, isolate and document it.
- Document important removals with file paths and rationale.
5) Validate Before Delivery
- Run the strongest available checks (prefer full test suite, lint, and build).
- If full suite is unavailable, run the broadest subset and state the limitation.
- Confirm no accidental API/export removals.
- Use
references/safe-removal-checklist.mdas the final gate.
Resources
scripts/find_duplicate_blocks.py: reports repeated normalized code windows to triage dedup opportunities.scripts/duplicate_blocks_*.py: helper modules used by the duplicate-block scanner.tests/test_find_duplicate_blocks.py: regression tests for the bundled scanner.references/safe-removal-checklist.md: final validation checklist for dead-code/duplication cleanup.