From clarc
Safely identifies and removes dead code using analysis tools like knip and ts-prune, with test verification at every deletion step and safety tier categorization.
How this command is triggered — by the user, by Claude, or both
Slash command
/clarc:refactorThe summary Claude sees in its command listing — used to decide when to auto-load this command
# Refactor Clean Safely identify and remove dead code with test verification at every step. ## Agent Delegation This command delegates to the **refactor-cleaner** agent, which runs analysis tools (knip, depcheck, ts-prune, vulture) to identify dead code, presents a dry-run plan for confirmation, and only then removes code with test verification at every step. ## Step 1: Detect Dead Code Run analysis tools based on project type: | Tool | What It Finds | Command | |------|--------------|---------| | knip | Unused exports, files, dependencies | `npx knip` | | depcheck | Unused npm depend...
Safely identify and remove dead code with test verification at every step.
This command delegates to the refactor-cleaner agent, which runs analysis tools (knip, depcheck, ts-prune, vulture) to identify dead code, presents a dry-run plan for confirmation, and only then removes code with test verification at every step.
Run analysis tools based on project type:
| Tool | What It Finds | Command |
|---|---|---|
| knip | Unused exports, files, dependencies | npx knip |
| depcheck | Unused npm dependencies | npx depcheck |
| ts-prune | Unused TypeScript exports | npx ts-prune |
| vulture | Unused Python code | vulture src/ |
| deadcode | Unused Go code | deadcode ./... |
| cargo-udeps | Unused Rust dependencies | cargo +nightly udeps |
If no tool is available, use Grep to find exports with zero imports:
# Find exports, then check if they're imported anywhere
Sort findings into safety tiers:
| Tier | Examples | Action |
|---|---|---|
| SAFE | Unused utilities, test helpers, internal functions | Delete with confidence |
| CAUTION | Components, API routes, middleware | Verify no dynamic imports or external consumers |
| DANGER | Config files, entry points, type definitions | Investigate before touching |
For each SAFE item:
git checkout -- <file> and skip this itemBefore deleting CAUTION items:
import(), require(), __import__After removing dead code, look for:
Report results:
Dead Code Cleanup
──────────────────────────────
Deleted: 12 unused functions
3 unused files
5 unused dependencies
Skipped: 2 items (tests failed)
Saved: ~450 lines removed
──────────────────────────────
All tests passing ✅
/tdd — add or update tests after refactoring/code-review — review refactored code/verify — confirm build + tests pass after refactornpx claudepluginhub marvinrichter/clarc --plugin clarc/refactorOrchestrates refactoring for specified scope: assesses architecture and issues, plans incremental transformations with risk mitigation, provides code change guides with examples, validation tests, and monitoring plan.
/refactorSystematically refactors target code area: identifies smells like long functions and duplicates, verifies/adds tests, plans atomic steps, executes with verification, preserves behavior.
/refactorSafely refactors code gradually, quantitatively scores SOLID principles adherence (0-100 per principle), detects smells and debt, and prioritizes improvements with techniques like Extract Method.
/refactorPerforms safe incremental refactoring on code, scores SOLID principles compliance (0-100 total), detects smells via grep/bash, visualizes technical debt, and prioritizes fixes with examples.
/refactorRefactors code step-by-step using techniques like Extract Method and polymorphism, scores SOLID principles quantitatively, visualizes technical debt, and prioritizes improvements.
/refactorSafely refactors code progressively using techniques like Extract Method, quantitatively scores SOLID principle adherence (0-100), visualizes technical debt, and prioritizes improvements.