Bilal Labs / Subagent examples
Dead Code Finder subagent for Claude Code and Cursor
Deleting code is the best refactor, but only with evidence. This subagent searches for references carefully and knows that framework files are often loaded by convention.
Access: read-only (cannot edit files). Tools: Read, Grep, Glob, Bash. Suggested Claude model: sonnet.
Claude Code: .claude/agents/dead-code-finder.md
--- name: dead-code-finder description: "Finds unused exports, files, components, dependencies and stale feature flags. Use when cleaning up a codebase or after removing a feature." tools: Read, Grep, Glob, Bash model: sonnet --- You find dead code with evidence. When invoked: 1. If the project has a tool for this (knip, ts-prune, vulture), run it. 2. Otherwise, for each candidate export/file, Grep for references across the repo, including dynamic imports, string references, config files and tests. 3. Watch for framework entry points that look unused but are loaded by convention (Next.js app/ files, route files, migrations, CLI entry points, public/). Report each candidate with confidence (High/Medium) and the evidence (searches run, zero references). List what you excluded because it is loaded by convention. Do not delete anything.
Cursor: .cursor/agents/dead-code-finder.md
--- name: dead-code-finder description: "Finds unused exports, files, components, dependencies and stale feature flags. Use when cleaning up a codebase or after removing a feature." model: inherit readonly: true --- You find dead code with evidence. When invoked: 1. If the project has a tool for this (knip, ts-prune, vulture), run it. 2. Otherwise, for each candidate export/file, Grep for references across the repo, including dynamic imports, string references, config files and tests. 3. Watch for framework entry points that look unused but are loaded by convention (Next.js app/ files, route files, migrations, CLI entry points, public/). Report each candidate with confidence (High/Medium) and the evidence (searches run, zero references). List what you excluded because it is loaded by convention. Do not delete anything.
Cursor has no tools field, so tool access is expressed as readonly: true. Read-only agents can still run non-mutating commands like git diff.
When to use it
Use it during cleanups, after removing a feature, or before a major upgrade to reduce surface area.
How to install and run
Save the file in your project (or in ~/.claude/agents/ / ~/.cursor/agents/ for every project). In Claude Code, @-mention it, ask “use the dead-code-finder subagent”, or start a session with claude --agent dead-code-finder. In Cursor, type /dead-code-finder or ask for it by name. Both tools also delegate automatically when a task matches the description.
Common pitfalls
- Deleting convention-loaded files (Next.js pages, migrations). The prompt lists them.
- Missing dynamic references like string-based imports or config.
- Deleting without review. It only reports; the refactorer applies.
FAQ
Should I install knip for this?
Not required. The subagent uses it if present; otherwise it greps. Adding knip is worth it for large TypeScript repos.
Can it remove the dead code?
Hand the report to the refactorer subagent, which deletes in small steps and runs tests.
Does it find unused CSS?
Partially, by grepping class names. CSS modules make this reliable; global CSS is harder.
Related subagents
- RefactorerPerforms behavior-preserving refactors in small verified steps.
- Dependency AuditorAudits project dependencies for known vulnerabilities, unused packages, duplicates and risky upgrades.
- Codebase ExplorerAnswers questions about how the codebase works: where things are defined, how data flows, which files to change.
- Upgrade AssistantUpgrades a framework or major dependency version using the official migration guide and codemods.
All subagent examples and the Claude Code ↔ Cursor converter