Skip to content

commandCode quality

Find Dead Code

Finds unused exports, files and dependencies and shows the evidence for each, so you can delete with confidence.

npx workspacetemplates add find-dead-code --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/find-dead-code.md14 lines · 1.2 KBFile
---
description: Finds unused exports, files and dependencies and shows the evidence for each, so you can delete with confidence.
argument-hint: "[folder, default whole project]"
---

Find dead code in: $ARGUMENTS (whole project if empty).

1. Use the project's own tools first if present (knip, ts-prune, depcheck, vulture, deadcode, `go vet`). Otherwise search by hand.
2. For each candidate export, file or dependency, search the whole repository, including tests, scripts, config, templates and docs, for the name and its string forms.
3. Check dynamic use before calling anything dead: route or plugin auto-loading, dependency injection, reflection, `require(variable)`, framework conventions such as pages and migrations, and exports meant for outside consumers.
4. Rate each: **certain** (no reference anywhere), **likely** (referenced only by other dead code or tests), **unsure** (dynamic or public use possible).
5. Never delete anything in this step.

Report a table with item, location, evidence (the searches run and their results), and confidence. List unused dependencies separately with the file that last imported them. Then ask which group to remove, and run the tests after removal.

What it does

Dead code costs reading time and hides real structure, but deleting it by guess breaks things that load code dynamically. This command looks for unused exports, orphan files and unused packages, then proves each claim with searches.

Every result carries its evidence and a confidence level. Anything reached by reflection, string imports or a public package interface is flagged instead of listed as safe.

Example

you › /find-dead-code src/

agent › certain: src/utils/legacyDate.ts, no imports (searched "legacyDate", "utils/legacy"), last touched 2023.
likely: export formatPhone in src/lib/format.ts, used only in format.test.ts.
unsure: src/plugins/csv.ts, loaded by name from config/plugins.json.
Unused dependencies: moment, lodash.debounce.
Remove the certain group?

Questions

Can it delete files on its own?
No. It reports first and removes only the group you choose, then runs the tests.
Why mark some items unsure?
Dynamic loading and public exports hide real usage. Those items need your knowledge of the system.
  • Add Error Handling

    CommandCode quality

    Free
  • Add Logging

    CommandCode quality

    Free
  • Add Types

    CommandCode quality

    Free
  • Extract Function

    CommandCode quality

    Free