Refactor Cleaner
Use this skill to remove dead code and duplicate clutter without turning the task into a broad refactor.
1. Detect dead code
Prefer project-native analysis tools when they exist. Use the analyzer that fits the stack, then fall back to text search when no analyzer is available.
| Stack |
Prefer |
What it finds |
| JavaScript / TypeScript |
npx knip, npx depcheck, npx ts-prune |
Unused exports, files, dependencies, and TypeScript symbols |
| Python |
vulture src/ |
Unused functions, classes, and variables |
| Go |
deadcode ./... |
Unused Go code |
| Rust |
cargo +nightly udeps |
Unused dependencies |
| Any stack |
rg / ripgrep |
Export, import, and reference traces when no analyzer fits |
If a command is unavailable, do not invent a wrapper. Use the strongest local search you can run.
2. Categorize findings
Sort every candidate before deleting it.
- SAFE: unused utilities, helper functions, dead branches, and test-only helpers with no external consumers.
- CAUTION: components, API routes, middleware, generated code, and symbols that could be reached dynamically.
- DANGER: config files, entry points, public exports, type definitions, and anything that may be part of a package contract.
Treat CAUTION and DANGER as "prove it first" work. If you cannot prove the item is unused, leave it alone.
3. Clean one item at a time
For each SAFE item:
- Run the relevant baseline verification target first.
- Delete exactly one item.
- Re-run the same verification target immediately.
- If verification fails, restore the tracked file and skip the item.
- If verification passes, move to the next item.
Keep the deletions atomic. Do not batch several removals into one change unless they are the same dead symbol in the same file.
4. Handle caution items
Before touching CAUTION or DANGER items, search for:
import() / require() / __import__
- string references to route names, component names, command names, or config keys
- public package exports and re-export chains
- external consumers or generated entrypoints
- test fixtures or build scripts that load the symbol indirectly
If the item might be reachable dynamically, stop and report the uncertainty instead of deleting it.
5. Consolidate duplicates after cleanup
After the dead-code pass is stable, look for duplicate code that can be merged safely.
- Merge near-duplicate functions only when behavior is clearly the same.
- Consolidate redundant type definitions.
- Remove wrapper functions that add no value.
- Drop re-exports that only add indirection.
Do not refactor first and clean later. Remove dead code before you simplify surviving code.
6. Report the cleanup
End with a concise cleanup summary.
Include:
- what was deleted
- what was skipped and why
- what verification command(s) ran
- whether the cleanup introduced any failures
- any remaining uncertainty
Use a format like:
Dead Code Cleanup
Deleted: ...
Skipped: ...
Verified: ...
Remaining: ...
If nothing was deleted, say why and name the blocker.
1---2name: refactor-cleaner3description: Use this skill when the user invokes `/refactor-clean` or asks to find and remove dead code, unused imports, orphaned files, duplicate logic, dead branches, or unused dependencies. It keeps cleanup cautious: classify risk, delete one item at a time, verify after each change, and stop when uncertainty appears.4---56# Refactor Cleaner78Use this skill to remove dead code and duplicate clutter without turning the task into a broad refactor.910## 1. Detect dead code1112Prefer project-native analysis tools when they exist. Use the analyzer that fits the stack, then fall back to text search when no analyzer is available.1314| Stack | Prefer | What it finds |15| --- | --- | --- |16| JavaScript / TypeScript | `npx knip`, `npx depcheck`, `npx ts-prune` | Unused exports, files, dependencies, and TypeScript symbols |17| Python | `vulture src/` | Unused functions, classes, and variables |18| Go | `deadcode ./...` | Unused Go code |19| Rust | `cargo +nightly udeps` | Unused dependencies |20| Any stack | `rg` / `ripgrep` | Export, import, and reference traces when no analyzer fits |2122If a command is unavailable, do not invent a wrapper. Use the strongest local search you can run.2324## 2. Categorize findings2526Sort every candidate before deleting it.2728- SAFE: unused utilities, helper functions, dead branches, and test-only helpers with no external consumers.29- CAUTION: components, API routes, middleware, generated code, and symbols that could be reached dynamically.30- DANGER: config files, entry points, public exports, type definitions, and anything that may be part of a package contract.3132Treat CAUTION and DANGER as "prove it first" work. If you cannot prove the item is unused, leave it alone.3334## 3. Clean one item at a time3536For each SAFE item:37381. Run the relevant baseline verification target first.392. Delete exactly one item.403. Re-run the same verification target immediately.414. If verification fails, restore the tracked file and skip the item.425. If verification passes, move to the next item.4344Keep the deletions atomic. Do not batch several removals into one change unless they are the same dead symbol in the same file.4546## 4. Handle caution items4748Before touching CAUTION or DANGER items, search for:4950- `import()` / `require()` / `__import__`51- string references to route names, component names, command names, or config keys52- public package exports and re-export chains53- external consumers or generated entrypoints54- test fixtures or build scripts that load the symbol indirectly5556If the item might be reachable dynamically, stop and report the uncertainty instead of deleting it.5758## 5. Consolidate duplicates after cleanup5960After the dead-code pass is stable, look for duplicate code that can be merged safely.6162- Merge near-duplicate functions only when behavior is clearly the same.63- Consolidate redundant type definitions.64- Remove wrapper functions that add no value.65- Drop re-exports that only add indirection.6667Do not refactor first and clean later. Remove dead code before you simplify surviving code.6869## 6. Report the cleanup7071End with a concise cleanup summary.7273Include:7475- what was deleted76- what was skipped and why77- what verification command(s) ran78- whether the cleanup introduced any failures79- any remaining uncertainty8081Use a format like:8283```text84Dead Code Cleanup85Deleted: ...86Skipped: ...87Verified: ...88Remaining: ...89```9091If nothing was deleted, say why and name the blocker.