Skip to main content
command CX Codex

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

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add WorldFlowAI/everything-claude-code
/plugin install everything-claude-code@everything-claude-code
Open on GitHub

What 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-code

2Manually: 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?

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.

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 sangrokjung The refactor-clean command finds unused code, proposes cautious deletions, and checks the test suite around every change. CX Codex +1 ★ 880repo stars refactor-engineer First Fluke refactor-engineer — a subagent that rewrites code while keeping it working. Identifies hot spots, wraps them with safety tests, and applies one atomic transformation at a time. CX Codex ★ 1,472repo stars oma-refactor First Fluke oma-refactor — a skill for Claude Code and Codex restructures existing code while preserving observable behavior. Executes targeted technical debt cleanup through small test-gated transformations. CX Codex +1 ★ 1,472repo stars code-refactor mhattingpete code-refactor is a Claude Code skill for bulk code changes across files: renaming variables and functions, replacing deprecated patterns, and updating API calls. It automatically selects a mode that saves up to 90% of tokens for 10+ files. CX Codex +1 304installs refactor-project FradSer refactor-project — a skill for Claude Code, Codex, Cursor and other agents that runs automated refactoring across every file in the project at once. Cuts duplication, normalises patterns, and strips legacy code in a single pass. CX Codex +1 122installs refactor-cleaner sangrokjung refactor-cleaner — a subagent that hunts down code nobody calls: unused files, exports and npm packages. Each hit gets a reference search before anything is deleted. CX Codex ★ 880repo stars dead-code parcadei Finds unused functions and dead code with TLDR static analysis. Runs on demand, whenever a codebase needs a cleanup pass. CX Codex +1 745installs

From the same set29

The whole set →
build-fix build-fix fixes TypeScript and build failures one at a time, rerunning the build after each change. Useful when the error list needs a controlled pass. CX Codex +1 ★ 6,739repo stars security security is a Claude Code rule that checks changes for exposed secrets, input validation, and protection against web attacks before commit. CX Codex +1 ★ 6,739repo stars code-review code-review is a Claude Code command that checks uncommitted changes for security flaws and code-quality issues. It reports findings and blocks commits when it detects CRITICAL or HIGH severity problems. CX Codex +1 ★ 6,739repo stars git-workflow The git-workflow rule defines commit formats (feat, fix, docs and five other types), PR steps, and a three-stage flow with planner, TDD-guide and code-reviewer agents. CX Codex +1 ★ 6,739repo stars patterns patterns sets standard TypeScript interfaces for APIs and repositories, provides a useDebounce hook, and defines a workflow for evaluating skeleton repos. CX Codex +1 ★ 6,739repo stars verify The verify command checks the build, types, lint, tests, logs, and Git state. Use it before a commit or pull request. CX Codex +1 ★ 6,739repo stars performance performance — a Claude Code rule that matches model to task and keeps heavy refactors away from the tail of the context window. CX Codex +1 ★ 6,739repo stars coding-style coding-style is a Claude Code rule for code structure and quality checks. It applies while an agent writes or changes code. CX Codex +1 ★ 6,739repo stars

More in the catalog

Project sponsors

Companies that keep this analytics open