Remove Dead Code

Referenced by patterns
Compare
Symptom
Human

Functions, branches, fields, or imports that no static analysis or human reader can reach — last commented out, last touched years ago, or referenced only by code that itself was removed.

Agent

The agent finds code (functions, branches, fields) with no inbound references the type system or grep can locate; reasoning about reachability requires assuming static analysis is complete.

Goal
Human

Every line in the codebase is reachable and used; readers don't waste cycles on phantom branches.

Agent

Every definition the agent encounters is reachable; reasoning about behavior doesn't have to consider phantom paths.

Before the refactoring

function legacyDiscount(order) { /* unused since 2018 */ }
function modernDiscount(order) { /* the real one */ }

After the refactoring

function discount(order) { /* the real one */ }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Readers spend cycles understanding code that never runs; debuggers stop in places that look meaningful but aren't; refactoring proposals have to consider phantom users.

Agent

The agent's plan-and-execute loop has to consider dead branches as live until proven otherwise; tests pass while code-walking analyses include dead surface area.

Tradeoff
Human

The team gives up the option to revive without a git dive — and 'dead' under static analysis can still be reachable via reflection, dynamic dispatch, or external callers.

Agent

Deletion is one-way under static analysis but reachability can hide in reflection, dynamic dispatch, external callers, or runtime config — the agent that deletes without checking risks a regression nothing catches.

Relief
Human

Smaller surface, faster reading, fewer false leads when debugging.

Agent

Dead tokens no longer load with the surrounding code; static analysis returns a complete picture because every branch in the window represents code that runs, and the agent edits against the reachable shape instead of paying tokens for paths that fire never.

Trap
Human

Deleting code that looks dead but is reached via reflection, dynamic dispatch, external callers, or test fixtures — the cleanup ships a regression because static analysis lied.

Agent

Aggressive deletion based purely on grep/static-analysis evidence misses reflection-reachable, plugin-loaded, or externally-referenced code — the cleanup ships a silent regression the agent's tests don't catch.