CommandOpen
Refactoring (cleanup)
Find and remove dead code, unused imports, and unreachable branches.
Find and remove dead code, unused imports, and unreachable branches.
Steps
- Detect the language and available tooling:
- TypeScript/JavaScript: Use
tsc --noEmitfor unused locals,eslintwithno-unused-vars. - Python: Use
vultureorpyflakesfor dead code detection. - Go:
go vetreports unused variables;staticcheckfinds dead code. - Rust: Compiler warnings for dead code with
#[warn(dead_code)].
- Scan for unused exports:
- Find all exported symbols.
- Search the codebase for imports of each symbol.
- Flag exports with zero import references (excluding entry points).
- Detect unreachable code:
- Code after unconditional return/throw/break statements.
- Branches with impossible conditions (always true/false guards).
- Feature flags that are permanently enabled or disabled.
- Find unused dependencies:
- Compare
package.jsondependencies against actual imports. - Check for packages used only in removed code.
- Present findings grouped by category with confidence levels.
- Apply removals only for high-confidence dead code (no dynamic references).
- Run tests after each removal batch to catch false positives.
Format
Dead Code Analysis
==================
Unused imports: <N>
- <file>:<line> - import { <symbol> } from '<module>'
Unused exports: <N>
- <file>:<line> - export <symbol> (0 references)
Unreachable code: <N>
- <file>:<lines> - <reason>
Unused dependencies: <N>
- <package> (last used: never / removed in <commit>)
Safe to remove: <N> items
Needs review: <N> itemsRules
- Never remove code that might be used via dynamic imports, reflection, or string references.
- Preserve exports that are part of a public API or SDK.
- Skip test utilities, fixtures, and development-only code.
- Run the full test suite after removing each batch to catch false positives.
- Log removed code with git commit messages for easy reversal.
Source: https://github.com/rohitg00/awesome-claude-code-toolkit/blob/main/commands/refactoring/cleanup.md
Author: rohitg00, Claude Code toolkit (rohitg00). License: Apache-2.0.
Shown here with formatting for the web. Keep the author and license notice when you reuse it.
Related entries
There are more like this in the members library
The Codex library holds 7,009 entries. Members can search all of them by meaning and read every one in full.