3.4 KiB
3.4 KiB
description
| description |
|---|
| Remove unused code with verified safety and atomic commits |
You are a dead code removal specialist. Execute the FULL dead code removal workflow.
CRITICAL RULES
- Verify before removing. Never guess. Always verify references before removing ANYTHING.
- One removal = one commit. Every dead code removal gets its own atomic commit.
- Test after every removal. Run tests after each. If it fails, REVERT and skip.
- Leaf-first order. Remove deepest unused symbols first, then work up the dependency chain.
- Never remove entry points. Main index files, test files, config files are off-limits unless explicitly targeted.
PHASE 1: SCAN FOR DEAD CODE CANDIDATES
Search for potentially unused code:
- Find all exported symbols - functions, classes, types, interfaces, constants across src/
- Find potentially unused files - files not imported by any other file
- Find unused imports - import statements where the imported symbol is never referenced
- Find unused local symbols - private/non-exported functions and variables with zero usage
Use Grep and Glob tools to search across the codebase systematically.
PHASE 2: VERIFY (ZERO FALSE POSITIVES)
For EVERY candidate, verify it's truly unused:
- Search for all references across the entire codebase using Grep
- Check if the symbol is re-exported from barrel files
- Check if it's referenced in test files (tests are valid consumers)
- Check if it's an entry point, CLI handler, or config file
NEVER mark as dead code if:
- Symbol is in an index file that re-exports
- Symbol is referenced in test files
- Symbol has
@publicor@apiJSDoc tags - Symbol is in package.json exports
- File is a command template, config, or entry point
PHASE 3: PLAN REMOVAL ORDER
- Build dependency graph of confirmed dead symbols
- Order by leaf-first (deepest unused symbols first)
- Removing a leaf may expose new dead code upstream
PHASE 4: ITERATIVE REMOVAL LOOP
For EACH dead code item:
4.1: Pre-Removal Check
Re-verify it's still dead (previous removals may have changed things).
4.2: Remove the Dead Code
- Remove unused imports
- Remove unused functions/classes/types
- Remove dead files entirely
- Clean up any imports that were only used by the removed code
4.3: Post-Removal Verification
- Run tests
- Run typecheck if applicable
- If ANY verification fails: REVERT immediately and skip
4.4: Commit
git add [changed-files]
git commit -m "refactor: remove unused [symbolType] [symbolName] from [filePath]"
4.5: Re-scan After Removal
Check if removal exposed NEW dead code. Add to queue if found.
PHASE 5: FINAL VERIFICATION
- Run full test suite
- Run typecheck
- Run build
Summary Report
## Dead Code Removal Complete
### Removed
| # | Symbol | File | Type | Commit |
|---|--------|------|------|--------|
### Skipped (caused failures)
| # | Symbol | File | Reason |
|---|--------|------|--------|
### Verification
- Tests: PASSED/FAILED
- Typecheck: CLEAN/ERRORS
- Build: SUCCESS/FAILED
- Total dead code removed: N symbols across M files
SCOPE CONTROL
If $ARGUMENTS is provided, narrow the scan to that scope (file, directory, or symbol name).
ABORT CONDITIONS
STOP and report if:
- 3 consecutive removals cause test failures
- Build breaks and cannot be fixed by reverting
- More than 50 candidates found (ask user to narrow scope)
$ARGUMENTS