Delete dead code with agents safely

Deleting dead code is high value and high regret when the code is only “seemingly” unused. Agents help with reachability search and staged removals.

Published 2026-11-09 · Translation: VI

Deleting dead code is high value and high regret when the code is only “seemingly” unused. Agents help with reachability search and staged removals. Proof comes first. Confident annihilation comes last, if at all.

The trap is trusting one static analyzer. Feature-flag paths, reflection targets, string routes, and ops entrypoints look unused until production hits them.

Prove reachability, stage, then delete small

Workflow

Workflow

  1. Build a candidate list. Coverage gaps, knip/ts-prune/deadcode tools, plus human suspicion lists.
  2. Search dynamic entrypoints. Reflection, string routes, CI scripts, IaC, docs examples, CMS and deep links.
  3. Stage when unsure. Deprecation warnings, feature flags, or hide behind a kill switch and monitor.
  4. Delete in small PRs. Adjust tests honestly. Do not delete tests only to make deletion easy.
  5. Deploy and watch. Look for 404s and exceptions tied to removed paths.
  6. Changelog public APIs. External users care even when the team forgot.

Stop gates: when not to delete yet

Stop gates before you ship

Stop gates before you ship

  • Single-signal trust. One tool said unused. Keep searching dynamic refs.
  • Mega deletion. Large trees across many packages in one PR. Split by package and risk.
  • Mid-rollout flags. Code behind an active feature flag is not dead. Wait for the rollout to finish or abort.
  • Half-deleted modules. Broken imports left behind. Finish the cut or revert.

Checklist for a safe deletion PR

Ship checklist

Ship checklist

Practical defaults:

  • Agents propose queues and raise confidence with search evidence. Humans prioritize and approve high-risk cuts.
  • Private helpers can go faster; public APIs need a stated deprecation window.
  • Search docs, CMS, and mobile deep links, not only code references.

Bottom line

Dead-code deletion with agents is a proof job. Search dynamic refs, stage when unsure, delete small, and watch. For related hygiene on unused surfaces after upgrades, see dependency upgrades with agents.

Share

X Facebook LinkedIn
Educational content only. Rankings reflect stated criteria at the update date—not investment advice or permanent performance guarantees.