refactor-clean · worldflowai — Claude Code command: remove dead code safely
refactor-clean identifies unused code across your codebase, categorizes findings by risk level, and removes them with test verification. Runs the full test suite before and after each deletion to catch regressions.
MIT ★ 6,739 updated 2026-01-23
/plugin marketplace add WorldFlowAI/everything-claude-code
/plugin install everything-claude-code@everything-claude-codeWhat refactor-clean does
refactor-clean scans your project with knip, depcheck, and ts-prune to find unused exports, files, and dependencies. Results go into a .reports/dead-code-analysis.md report sorted by severity: SAFE for test utilities, CAUTION for routes and components, DANGER for config and entry points.
Before removing anything, the command runs your complete test suite, applies the change, then reruns tests. If tests fail, it rolls back. This prevents accidentally breaking code that has hidden dependencies.
Once finished, it displays a summary of what was cleaned. Works with TypeScript projects that have tests set up.
What it helps with
- find unused exports and dead files
- assess which dead code is safe to remove
- eliminate unused dependencies
- verify deletions do not break existing functionality
Example prompts for the agent
- Run dead code analysis and show recommendations:
/refactor-clean - Analyze the project, generate report, and delete low-risk items:
/refactor-clean --safe-only - Create a dead code report without making changes:
/refactor-clean --report-only
How to install refactor-clean
1Plugin marketplace
/plugin marketplace add WorldFlowAI/everything-claude-code/plugin install everything-claude-code@everything-claude-code2Manually: put the files in place
.claude/commands/refactor-clean.mdCall it with /refactor-clean. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/refactor-clean.mdCall it with /prompts:refactor-clean. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/refactor-clean.prompt.mdManually: put the files in place
.gemini/commands/refactor-clean.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about refactor-clean
How do I install refactor-clean in Claude Code?
Run /plugin marketplace add WorldFlowAI/everything-claude-code, then /plugin install everything-claude-code@everything-claude-code. The command loads from .claude/commands/refactor-clean.md.
What does refactor-clean do?
Scans for unused code using knip, depcheck, and ts-prune, categorizes findings by risk, and removes them while running tests before and after each change.
What do I need to use refactor-clean?
A TypeScript project with tests configured. The command installs knip, depcheck, and ts-prune if they are missing.
Source text
refactor-clean.md · MIT
# Refactor Clean Safely identify and remove dead code with test verification: 1. Run dead code analysis tools: - knip: Find unused exports and files - depcheck: Find unused dependencies - ts-prune: Find unused TypeScript exports 2. Generate comprehensive report in .reports/dead-code-analysis.md 3. Categorize findings by severity: - SAFE: Test files, unused utilities - CAUTION: API routes, components - DANGER: Config files, main entry points 4. Propose safe deletions only 5. Before each deletion: - Run full test suite - Verify tests pass - Apply change - Re-run tests - Rollback if tests fail 6. Show summary of cleaned items Never delete code without running tests first!
© Affaan Mustafa · MIT · WorldFlowAI/everything-claude-code
Similar slash commands
All slash commands for Code review and refactoring →refactor-clean by other authors comes first.