/agentic-tools:remove-dead-codefrom agentic-tools
Finds genuinely dead code via dual-pass analysis (static tools + reachability from real entry points), then a zero-trust critic subagent re-derives and refutes every finding. Audit mode reports; audit-and-fix deletes confirmed-dead code and verifies the suite stays green.
Ships in agentic-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an orchestrator. Find what is genuinely dead, prove it with a separate critic, and either report it or remove-and-verify it — never trust a tool's word, never delete on doubt.
"Dead" is a reachability question, not a grep question. A symbol is dead if nothing reachable from a real entry point uses it. Static tools answer a weaker question — "does this name appear anywhere?" — so they lie in both directions: they call live framework handlers dead, and they call test-only-reachable code alive. Every finding is guilty until proven dead.
Pick the mode first. The bare command and every trigger phrase (including "remove dead code" / "prune the codebase") default to audit — never treat invocation as permission to delete. Enter audit-and-fix only on explicit authorization to delete.
Candidate set. Real source only — exclude vendored/generated/cache noise (venv/, node_modules/, dist/, build/, *.pyc, generated clients, migrations); it dwarfs the real code and poisons every count.
Find the true entry points — the only roots reachability counts from. Read them, don't guess: Dockerfile/compose CMD/ENTRYPOINT, __main__/main/cli, package.json scripts / console_scripts, serverless handlers, cron/queue workers, web route roots, README run commands. Tests are not entry points.
Library-vs-app branch (critical — skipping it flags your whole public API as dead). Is this a library/package, not an app? — a pyproject.toml/package.json/go.mod that publishes symbols, or a package imported by siblings in a monorepo. If so, every public export is an entry-point root (__all__, export, exported Go identifiers, console_scripts) — external callers you can't see reach them. "Unused within this repo" is NOT dead for a library; only truly-private symbols are candidates.
Tool bootstrap. Confirm each tool actually exists (which vulture, npx knip --version, in-venv path) before relying on it. A missing tool silently no-ops a pass and collapses the two passes into one — if you can't install it, record that the pass was skipped; never proceed as if it ran.
Run both. They disagree on purpose; the disagreement is the signal. Carry the UNION of both passes into Phase 3 — a symbol flagged by either is a candidate; never drop Pass B's feature-level hits because Pass A was easier.
Pass A — static tools (fast, local, over-reports dead lines):
# Python: vulture <src> --min-confidence 80 (then 60); ruff check <src> --select F401,F811,F841
# JS/TS: knip (config-aware; the strongest) / ts-prune / eslint no-unused-vars
# Go: staticcheck / golangci-lint (unused-symbol linters)
Reconcile the tools against each other — different blind spots, neither subsumes the other. ruff's scoped import analysis and vulture's AST module-scope reference check (vulture is AST-based — it does not count names in strings/comments, and it does flag unused imports) disagree only at the margins (a name re-referenced elsewhere); vulture also flags unused function params / loop-unpack vars that ruff F841 ignores. Where they conflict, hand-verify.
Pass B — reachability (slower, semantic, finds dead features — invisible to Pass A): Build the reference graph, don't eyeball it:
# Python: per-module importer check grep -rn 'import <mod>\|from <mod>' (or pydeps / importlab for the graph)
# JS/TS: madge / knip for the import graph
# Go: deadcode ./... # whole-program reachability FROM main; this is a Pass-B tool and it UNDER-reports (opposite of vulture)
Walk imports transitively from each entry point; mark reachable. Flag: modules never imported outside tests or by other dead code; symbols referenced only in tests; symbols referenced only by already-dead symbols (transitively dead). Pass A finds dead lines; Pass B finds the whole subsystem nobody wired in.
Dispatch a fresh subagent (Task/agent tool) on the strongest model available (/route to opus-tier if present; otherwise select the top model directly) whose only inputs are the candidate list + repo path — NOT your reasoning or first-pass conclusions. It regenerates every piece of evidence from scratch. Same zero-trust spirit as /verdict.
If you cannot spawn a separate context, say so and downgrade every verdict to UNCERTAIN. Putting on a "critic hat" and grading your own first pass is not zero-trust — it confirms your priors and silently reduces this skill to a dressed-up
vulturerun. The separation is the load-bearing part.
For each "dead" claim, hunt for a hidden caller before accepting it — default LIVE if any of these reaches it:
| Pattern | Why the tool missed it |
|---|---|
@app.route / @socketio.on / @app.before_request / Click / Celery / Django signals / pytest fixtures / DI containers | framework dispatch — invoked by name/URL/event, no static call site |
getattr / importlib / dynamic import() / string registries / decorator dispatch tables / reflection | dynamic dispatch |
dataclass fields, config schema, sqlite row_factory, @property read as a dict key, Go interface satisfaction | attribute/structural use the call-graph doesn't model |
Protocol / ABC / @runtime_checkable methods, NoOp / null-object shims mirroring an external API (e.g. an OTel stub) | interface stubs — signatures must exist with no direct caller |
serialization (to_dict/from_dict), __all__ / barrel index.ts re-exports, plugin/entry-point hooks, file-based routing (Next.js), //go:embed, build tags, init() | referenced out-of-band or by the toolchain |
| guarded by a feature flag / config / env / lazy or conditional import | dead in the profile you see, live under another — check ALL config profiles, default LIVE |
A framework pattern (@app.route present) is evidence of life, not proof — confirm the handler is actually registered on a live app object reachable from an entry point, not merely that the decorator text exists. Test-only framework hooks (pytest fixtures, conftest) are not dead — pytest injects them — but they classify to bucket 2 (test-only), not production-live. For each "live" claim, invert it: referenced only by tests, or only by other dead code → dead-in-production regardless of grep count. The critic must also sweep for misses — orphaned private helpers, initialized-but-never-consumed objects (a client/tracer built and never called), env vars wired to fields nothing reads, modules imported only by their own tests.
Emit a verdict per contested item: CONFIRMED-DEAD / REFUTED-LIVE / UNCERTAIN, each with the file:line evidence the critic regenerated itself.
Do not collapse "unused" into "delete." Sort every CONFIRMED finding:
Protocol/interface members, extension points, symmetric facade methods, test-only helpers. Reachable only from tests, by design.git log / git blame on the files — who added it, when, the commit/PR, whether it was abandoned mid-stream), pin the exact missing connection (the one call or wiring that would make it live), and judge whether it's a real unfinished capability, scaffolding, or an abandoned dead-end. Present that context, then offer three fates:
/build skill as the implementation brief; it completes and wires the work.# TODO(ref) marker or comment the block out; or leave the code untouched and track it externally (default).Keep vs decide rule: is a production path supposed to reach it? An interface member / documented extension point / symmetric facade → intentional (bucket 2). A whole feature that just needs its connecting call → unwired (bucket 3). When intent is unclear, it's bucket 3 — surface it, don't guess.
Never give one "% dead." Emit the three buckets separately:
|||DEAD-CODE|||
{
"mode": "audit" | "audit-and-fix",
"source_loc": 7873,
"truly_dead": { "loc": 45, "pct": 0.6, "fate": "delete", "items": [ ... ] },
"intentional_keep": { "loc": 300, "pct": 3.8, "fate": "keep", "note": "Protocol/API/extension surface, test-covered" },
"decisions": { "loc": 728, "pct": 9.2, "fate": "decide", "items": [ "<feature>: built+tested, unwired — finish or cut?" ] },
"false_positives_filtered": 31,
"overturned_by_critic": [ "<first-pass claim the critic reversed>" ],
"missed_by_first_pass": [ "<dead code only the critic found>" ]
}
|||DEAD-CODE|||
State the caveat plainly: static-tool headline numbers overstate dead code (framework dispatch, dynamic access, interface stubs); the only safe-to-delete number is truly_dead, post-critic.
Run ONLY in audit-and-fix mode, ONLY on truly_dead (critic-CONFIRMED):
/build with the gathered brief (feature, exact missing connection, git-history context) to implement + wire + verify; defer → create the TODO/issue with that context, and only comment out / add an in-code marker if asked (else leave the code as-is); cut → delete + verify green (same loop as bucket 1).main.)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
dead-code, code-removal, reachability-analysis, code-audit, refactoring
Other plugins' skills for the same job
npx claudepluginhub kurtlehnardt/agentic-tools --plugin agentic-tools29 skills in this plugin
/architect-reviewFull architectural review of the codebase by a senior architect subagent. Finds and fixes CRITICAL/HIGH issues, reports MEDIUM/LOW. Trigger: architect review, architecture review, full review, code review./babysitCron supervisor that checks on worker subagents every ~5 minutes, compares their progress against the original plan, and writes NUDGE.md into drifting worktrees. Trigger: babysit, supervise workers, watch agents./buildOrchestrate a spec-driven implementation pipeline: spec intake, requirements ledger, plan, architect gate, product gate, task decomposition with model tiering, parallel one-shot workers, a deterministic mechanical gate plus an opus judge, and verified merge. Trigger on "build this", "implement this", "orchestrate this", "build from this spec/contract/PRD", or whenever the user drops a spec, OpenAPI file, or requirements doc and asks for an implementation. Pass --quickly for a low-token variant that keeps subagent workers but replaces all per-phase and per-task reviews with one final opus review on a PR.