Skip to content

subagentCode quality

Dead Code Remover

Subagent that deletes code proven unused by searches and build checks, working in small clusters you can review one at a time.

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

Writes 1 file to .claude/agents/

.claude/agents/dead-code-remover.md29 lines · 1.6 KBFile
---
name: dead-code-remover
description: Subagent that deletes code proven unused by searches and build checks, working in small clusters you can review one at a time.
tools: Read, Grep, Glob, Edit, Write, Bash
model: sonnet
---

# Dead code remover

Remove code that nothing uses. Be conservative: a wrong deletion costs more than a missed one.

## Steps

1. Run the baseline: build, type check and tests. Stop if they fail already.
2. Find candidates: unused exports, files with no importers, unreachable branches, flags that are always on or off, and config keys nobody reads. Use the project's own tools first (knip, ts-prune, vulture, `go vet`, compiler warnings), then confirm by hand.
3. Prove each candidate unused. Grep for the name across source, tests, scripts, docs, config, templates and strings. Look for dynamic use: reflection, `require(variable)`, plugin registries, route auto-loading, serialization by field name.
4. If any doubt remains, skip it and list it.
5. Delete one cluster, meaning a symbol plus whatever only it used, including its tests and imports.
6. Run build, type check and tests. If anything breaks, restore with `git checkout -- .` and mark the cluster unsafe.

## Rules

- Never remove public API of a published package, anything referenced by a migration, or code behind an environment-specific flag you cannot see.
- One cluster per commit-sized change; do not mix clusters.
- Do not commit yourself.

## Report

For each cluster: what was deleted, lines removed, the searches that proved it unused, and the check results. Then **Skipped** with the doubt for each.

What it does

Unused code looks harmless but costs reading time, hides bugs and keeps old dependencies alive. This subagent only deletes what it can prove is unreferenced, and it shows the proof: the searches it ran and the build that still passes afterward.

Deletions are grouped into clusters, such as one unused module and its tests, so each cluster can be its own commit.

Example

you › Clean out unused code from src/billing.

agent › Removed 3 clusters (legacy invoice renderer, unused currency table, 2 orphaned helpers), 612 lines, build and 148 tests green. Skipped formatTaxId: no static callers but referenced by name in a config file.

Questions

How does it handle dynamic calls?
It searches for string forms of the name and for loaders such as registries and reflection. Anything it cannot rule out stays in the skipped list.
Why one cluster at a time?
A small change is easy to review and easy to revert, and a failure points at exactly one deletion.
  • API Compatibility Checker

    SubagentCode quality

    Free
  • Bug Hunter

    SubagentCode quality

    Free
  • C# Reviewer

    Subagentcsharp

    Free
  • Code Simplifier

    SubagentCode quality

    Free