Skip to main content
command CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/refactor-clean.md
Open on GitHub

What 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-clean and 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.md

Call it with /refactor-clean. For all projects use ~/.claude/commands/

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.

refactor-clean Seth Hobson The refactor-clean command reviews code for structural issues, SOLID violations, and performance risks, then lays out practical cleanup steps without over-engineering. CX Codex +1 ★ 42,780repo stars refactor-clean Affaan Mustafa 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. CX Codex +1 ★ 6,739repo stars refactor-cleaner Affaan Mustafa refactor-cleaner is a Claude Code subagent that finds and removes unused code, duplicates, and dependencies. It runs knip, depcheck, and ts-prune during codebase cleanup. CX Codex ★ 6,739repo stars refactor-safely tirth8205 refactor-safely — a skill for Claude Code that plans refactoring via dependency graphs. It checks impact radius before editing and validates diffs against the plan. CX Codex +1 1,200installs refactor SethGammon Multi-file refactoring with automated Git rollback, typechecking, and test baseline verification across edits. CX Codex +1 ★ 937repo stars llm-artifacts-detection existential-birds llm-artifacts-detection detects leftover cruft from AI coding assistants: dead code, duplicate test helpers, redundant wrapper classes, and obvious comments. CX Codex +1 151installs refactor-method-complexity-reduce official github refactor-method-complexity-reduce refactors a chosen method by moving complex logic into helpers. Use it when nested conditions or branching make a method hard to follow. CX Codex +1 9,992installs typescript-clean-code bmad-labs typescript-clean-code — a skill for reviewing and refactoring TypeScript: code smell catalogs, four detection layers, and step-by-step workflows. CX Codex +1 669installs

From the same set44

The whole set →
build-fix build-fix runs npm or pnpm builds, parses compiler errors, and fixes them incrementally. It verifies every edit with a fresh build run. CX Codex +1 ★ 880repo stars update-codemaps The update-codemaps command examines a project’s structure and refreshes architecture maps in codemaps/. Use it when code changes need matching documentation. CX Codex +1 ★ 880repo stars update-docs update-docs rebuilds docs/CONTRIB.md and docs/RUNBOOK.md from package.json and .env.example, then reports which docs have gone stale. CX Codex +1 ★ 880repo stars testing testing enforces a strict TDD workflow in Claude Code with an 80% coverage floor, Playwright E2E suites, and three test tiers. CX Codex +1 ★ 880repo stars date-calculation date-calculation stops the assistant from calculating dates mentally by enforcing system tools like date and python3. Helps avoid arithmetic mistakes on leap years and intervals. CX Codex +1 ★ 880repo stars korean-character-count korean-character-count counts graphemes, lines, and UTF-8 bytes in Korean text by grapheme cluster rules, for self-intro forms with strict limits. CX Codex +1 ★ 880repo stars loop-forge loop-forge converts a single-line routine task into a reusable slash command equipped with safety gates and evaluation checks. CX Codex +1 ★ 880repo stars korean-spell-check korean-spell-check — a Claude Code skill that checks Korean spelling and returns edits instead of a rewritten draft. Long input gets split into chunks before it goes out. CX Codex +1 ★ 880repo stars

Project sponsors

Companies that keep this analytics open