Dead code finder subagent with verification before deletion
A read-only Claude Code subagent that finds unused files, exports, dependencies and functions using knip, vulture or staticcheck where available, verifies each candidate against dynamic and framework-convention usage, and reports a ranked removal list.
Agent in Engineering by AISkillHub Library
What it does
Unused-code tools produce false positives: a file loaded by naming convention, a function referenced from a config string, a public API used by another repository. This subagent combines tool output with manual verification so the list you act on is trustworthy.
**What it does** - Runs a static analyzer suited to the stack if it is available: `knip` for JavaScript and TypeScript projects, `vulture` for Python, `staticcheck` for Go (its unused-code check), or the compiler's own unused warnings. If none is available, it falls back to search-based analysis. - For each candidate, checks the common reasons a tool misses a reference: framework conventions (Next.js `app/` and `pages/` files, Laravel controllers referenced from routes, Django apps listed in settings, Rails autoloading), string-based references (dependency injection containers, event names, `getattr`, reflection, dynamic imports), config files, build scripts, tests, and public package exports. - Classifies each item as **Safe to remove**, **Probably unused** (verify), or **Keep** (with the reason), and estimates the lines removed.
**What it will not do** It does not delete anything. Its tool list excludes Edit and Write, so it can only report. Once you choose items from the report, ask the main Claude Code session to remove them and run the tests. It does not treat exports of a published library as unused, because consumers outside the repository may use them.
How to use it
1. Save the file below as `.claude/agents/dead-code-finder.md`. 2. Optional but recommended: make the analyzer available for your stack, for example `npx knip` works without installing for most JS/TS projects; `pip install vulture`; `go install honnef.co/go/tools/cmd/staticcheck@latest`. 3. Ask Claude Code: "Use dead-code-finder on src/" or "find unused code in this repo". 4. Pick items from the "Safe to remove" list and ask the main session to delete them and run tests.
Files
Save each file at the path shown, relative to your project root.