Dead Code Eliminator
Automatically identifies and removes unused code to improve codebase quality and maintainability. This loop performs iterative scans for dead code, removes it gradually, and ensures no regressions are introduced.
Goal
Remove unused code
How to Run
This loop guides an AI agent to iteratively identify and remove dead code while ensuring safety. It uses a dead code scan tool and stops when no unused code remains.
- 01
Start the loop
Initiate the loop in your coding environment (e.g., Cursor, Claude Code).
- 02
Monitor iterations
Watch as the agent scans for dead code, removes it, and checks again.
- 03
Verify completion
Ensure the 'Analysis clean' condition is met and the exit condition is reached.
Workflow Steps
- 01
Identify dead code
Use static analysis or linting tools to detect unused functions, variables, or modules.
- 02
Run check command
Execute the configured dead code scan to generate a report of unused code.
- 03
Inspect results
Review the scan output to distinguish true dead code from false positives.
- 04
Remove dead code
Delete confirmed unused code while preserving active logic and dependencies.
- 05
Document changes
Log all deletions for transparency and audit purposes.
- 06
Repeat until clean
Loop back to step 1 if unused code is still detected.
- 07
Exit on success
Terminate when the dead code scan reports no issues.
Kickoff Prompt
Start the "Dead Code Eliminator" loop. Goal: Remove unused code Max iterations: 10 Between iterations run: dead code scan Exit when: Analysis clean Please analyze this codebase to identify and remove all dead code. Begin by running a dead code scan to detect unused functions, variables, and modules. After each removal, rerun the scan to confirm the codebase is now clean. Do not proceed if any false positives are detected without explicit approval. Self-pace this loop. After each iteration, run `dead code scan` and evaluate the output, and only continue if the exit condition is not met (Analysis clean). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
Guardrails
hardcoded- ·Never remove code that is referenced elsewhere or conditionally used (e.g., feature flags).
- ·Run in a version-controlled environment to allow easy rollback of changes.
- ·Use a reliable dead code detection tool compatible with your tech stack.
- ·Manually review critical deletions before finalizing them.
- ·Avoid modifying files outside the scope of dead code removal.
Flow Diagram
Related loops — Quality
Quality
Lint Until Clean
Automatically iterates through lint error detection and resolution until the codebase passes linting with zero issues. This loop ensures code quality and consistency by having the agent fix problems as they are identified.
Quality
Refactor Safely
This loop systematically refactors your codebase to improve structure while maintaining test coverage. The agent identifies opportunities for cleaner code without breaking existing functionality.
Quality
Code Quality Until A Grade
A prompt-only loop designed to iteratively improve code quality and maintainability until a specified quality gate passes. The agent analyzes the codebase, identifies quality issues, and applies targeted fixes to achieve an 'A' grade quality score.