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

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
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