---
description: "Safely identify and remove dead code with verification after each change"
---

# Refactor Clean

Safely identify and remove dead code with test verification at every step.

## Usage

`/refactor-clean [path]`

## Process

1. **Detect** dead code with analysis tools

   | Tool | What It Finds | Command |
   |------|--------------|---------|
   | knip | Unused exports, files, deps | `npx knip` |
   | depcheck | Unused npm deps | `npx depcheck` |
   | ts-prune | Unused TypeScript exports | `npx ts-prune` |
   | vulture | Unused Python code | `vulture src/` |

2. **Categorize**: SAFE (delete with confidence), CAUTION (verify consumers), DANGER (investigate)
3. **Safe deletion loop**: run tests → delete → re-run tests → revert if fails
4. **Handle CAUTION items**: check for dynamic imports, string refs, public API exports

## Rules

- Never delete without running tests first
- One deletion at a time
- Skip if uncertain
- Don't refactor while cleaning

## Related

- Skill: `skill://improve-codebase-architecture`
