Dead code hunt
dead-codecleanuprefactoring
Finds unused exports, files and branches — and proves they're unused before deleting.
What it does
- Triggers during cleanup or after a feature is removed.
- Looks for exports with a single mention, files nothing imports, unreachable branches and assets nothing references.
- Before deleting, checks for string-key access and dynamic imports — a text search doesn't see those.
- Deletes in a commit separate from behaviour changes, so reverting is cheap if it was wrong.
Why you'd want it
Dead code is more dangerous than it looks: people read it while investigating, orient by it, and maintain it alongside the live code. Deleting on a hunch is risky — so this demands evidence, not a guess.
Where to put it
- 1Create the folder .claude/skills/dead-code in your project
- 2Put a SKILL.md file in it with the text below
- 3That's it. Claude Code loads the skill itself when a task matches the description
To make the skill available in every project rather than one, put it in ~/.claude/skills instead of the project folder.
SKILL.md file
--- name: dead-code description: Find code that nothing uses any more. Use when the user asks to clean up, mentions dead code, or after removing a feature. --- # Finding dead code Removing code is safe only when you have shown nothing reaches it. Search before deleting, every time. ## Where to look **Unused exports.** For each exported symbol, search the repository for its name. One hit means only the definition — a candidate. ```bash rg -n "export (function|const|class|type|interface) (\w+)" -o -r '$2' src | sort -u ``` Then check each name. Beware of symbols reached dynamically, by string key or through a barrel file — grep will not see those. **Files nothing imports.** A module whose path appears in no import statement anywhere. **Branches that cannot be taken.** A condition on a value that is now always the same, a case for an enum member that no longer exists. **Assets nothing references.** Images, fonts and data files whose names appear nowhere in the source. ## Before deleting anything - Check the tests. Code used only by tests is not dead — it is either still needed or the test is stale, and those are different fixes. - Check for dynamic access: `obj[name]`, `import(path)`, string keys in a lookup table. - Check the framework's conventions. Files can be entry points by location alone and be imported nowhere. ## How to report List each finding with the path, what it is, and the evidence that nothing uses it — the search you ran and how many hits it returned. Delete in a separate commit from any behaviour change, so a revert is cheap if you were wrong.