refactor-clean · sangrokjung — Claude Code command: clean dead code
The refactor-clean command finds unused code, proposes cautious deletions, and checks the test suite around every change.
MIT ★ 880 updated 2026-09-03
.claude/commands/refactor-clean.mdWhat refactor-clean does
refactor-clean scans a project with knip, depcheck, and ts-prune. It writes the findings to .reports/dead-code-analysis.md and sorts them by risk, from test files and unused utilities to configuration files and main entry points.
Only deletions marked as safe are proposed. Before each one, the command runs the full test suite, applies the change, and runs the tests again. A failed check triggers a rollback. For a refactor expected to touch 3 files or more, run /plan first.
The command ends with a summary of removed items. You can then run /code-review, /handoff-verify, or /sync for separate code, build, test, and documentation checks.
What it helps with
- find unused exports and files
- spot dependencies that the project no longer uses
- review unreferenced TypeScript exports
- remove dead code with test-based rollback
- write a report of dead-code findings
Example prompts for the agent
- Run
/refactor-cleanand inspect dead code in this project. - Test each proposed deletion and remove only items marked safe.
- Create
.reports/dead-code-analysis.md, then show the cleaned items.
How to install refactor-clean
Manually: 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?
Copy the command file to .claude/commands/refactor-clean.md.
What does refactor-clean do?
It scans for unused files, exports, and dependencies, creates a report, and removes approved items while testing before and after each change.
When should I run /plan before refactor-clean?
Run /plan first when the refactor is expected to change 3 files or more.
Source text
refactor-clean.md · MIT
--- description: Safely identify and remove dead code with test verification --- # Refactor Clean > **참고**: 대규모 리팩토링(3파일 이상 변경 예상)은 `/plan`을 먼저 실행하세요 (Golden Principle #9: HARD-GATE). 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! --- ## 다음 단계 | 리팩토링이 끝나면 | 커맨드 | |:----------------|:-------| | 코드 검사 | `/code-review` | | 빌드/테스트 검증 | `/handoff-verify` | | 문서 동기화 | `/sync` |
© sangrokjung · MIT · sangrokjung/claude-forge
Similar slash commands
All slash commands for Code review and refactoring →refactor-clean by other authors comes first.