Engineering teams rarely get stuck for lack of code. They get stuck because the codebase, the account list and the service catalogue have all grown faster than anyone’s ability to hold them in their head. The usual response to slow delivery or brittle releases is to add: another pipeline stage, another review gate, another wrapper library. A less popular response is to remove. This FAQ works through the questions teams most often ask when they consider deleting dead code and other unused parts of a system, and answers them with an analytical eye on risk, evidence and reversibility.
The answers are general engineering practice, not a prescription for your environment. Always validate against your own tests, logs and change process before removing anything in production.
Why would deleting help more than adding another safeguard?
Because every component has a carrying cost that never shows on an invoice. Code that is never executed still has to be read during reviews, compiled in builds, scanned by security tools and understood by each new hire. An unused service account still has credentials that can leak. An unused feature flag still creates branches in tests. When delivery slows, the cost of this idle weight is spread across every task, so no single change appears to be the problem.
A new safeguard addresses a specific risk but also adds its own carrying cost. If the underlying complexity is untouched, the safeguard sits on top of it and often makes the system harder to reason about. Removal attacks the cause rather than adding a layer around it.
How do we know code is really dead?
Evidence beats intuition. Start with static signals: functions with no callers, modules never imported, configuration keys nothing reads. Static analysis tools and a simple search will surface candidates quickly. Then look at runtime evidence. Coverage reports from production-like traffic, logging added temporarily around suspicious paths, and request records over a long window can confirm whether anything still reaches a given path.
Be careful with code that runs rarely. A quarterly billing job or an annual reporting export may look dead in a one-week sample. Extend the observation window to cover your longest business cycle, and ask the people who run the calendar, not only the people who read the repository.
What should we remove first?
Rank candidates by two factors: how confident you are that they are unused, and how bad it would be if you were wrong. Begin with the high-confidence, low-impact group.
- Commented-out blocks and abandoned branches. Version control already remembers them.
- Feature flags that have been permanently on or off for months. Fold the winning path in and delete the loser.
- Unused dependencies. Each one is an update stream and a potential vulnerability.
- Stale accounts and tokens. People who left and integrations that were retired should lose access.
- Environments nobody deploys to. Old test stacks cost money and attract attention from attackers.
Leave data stores, shared libraries and anything touching payments or personal data until your process is established.
Is there a safe way to remove something we are unsure about?
Yes, and it is worth using even when you feel fairly sure. The common pattern is staged removal. First, disable or hide the item behind a switch, with logging that records any attempt to use it. Wait through a full cycle. If nothing calls it, delete the code in a separate, clearly labelled change that can be reverted with one command. For accounts, suspend before deleting. For services, scale to zero before decommissioning. Each stage is reversible, and each gives you a chance to be corrected by reality at low cost.
Won’t deleting code make us lose knowledge?
Less than you might expect, provided you record the decision. Version history preserves the code itself. What disappears is the reason it existed, so write a short note with each removal: what it did, why you believe it is unused, what evidence you checked, and the date. A plain list in the repository is enough. The same logic applies to the discipline of questioning scope before a build, which the guide to queries worth raising before commissioning a bespoke web app approaches from the front end of a project.
How does this relate to rebuilding or redesigning a system?
Teams sometimes jump to a rewrite when the real problem is accumulated weight. A rewrite carries large risk and tends to reproduce the same clutter in new syntax, because nobody decided what to leave behind. A deliberate clean-up of the existing system is often cheaper and can show whether a rebuild is truly needed. The trade-offs between those paths are laid out in this comparison of refreshing a site versus engineering a full application. If you do proceed to a build, treat requirements as a filter: the article on drafting solid requirements for a web project shows how to define what stays out as clearly as what goes in.
Do tests help or get in the way?
They help, with one caveat. A solid suite tells you quickly if a removal breaks a known behaviour, which is exactly the safety net you want. The caveat is that tests can themselves be dead weight: checks for code paths that no longer exist, or assertions that pass regardless. When you delete a function, delete its tests in the same change and confirm the suite still protects the behaviour that remains. A suite that shrinks alongside the code is a sign of a healthy clean-up, not a lost safeguard.
How do we measure whether the clean-up worked?
Pick a small set of observable outcomes before you start. Typical choices are build time, size of the deployable artefact, number of dependencies flagged by scanners, count of active accounts per system, and the time a new engineer takes to make a first confident change. Compare before and after across a reasonable period. Resist the urge to claim large gains from a single run; a modest, consistent improvement across several indicators is more credible than one dramatic number.
Equally important, watch for regressions, because a cut that looked safe on paper can still surprise you in practice. Track incident reports and support tickets linked to the removed items for a few weeks. Zero is the expected figure, and anything else is information about a missing safeguard in your evidence-gathering.
Who should approve a removal?
The owner of the component, plus anyone who depends on it. If there is no owner, that is itself a finding. Establish one before deleting, because orphaned items are the ones most likely to hide a surprise. For small teams, a short written proposal and a day for objections is enough. For larger organisations, include the security and operations contacts, since credentials and runtime behaviour are in their domain.
What if people resist deletion?
A few teams hold back for a reason that deserves respect: they have been burned before by a removal that broke something unexpected.
Resistance usually comes from fear of blame, not from attachment to the code. Make removal low-stakes by emphasising reversibility and by crediting the people who raise candidates. Treat a successful clean-up as a shared achievement. It also helps to attach a time limit: “if nobody claims this by the end of the month, we suspend it” is a fair rule that respects owners while preventing indefinite limbo.
Where does writing fit into this?
More than most engineers expect. Explaining why something can go forces you to test your own reasoning, and a public or team-wide write-up spreads the habit. A blogging network called BlogOrbix presents itself as a quiet, distraction-free space for people who write, so it can host that kind of reflective post, and several contributors can share one blog if the clean-up was a team effort.
How often should we do this?
Little and often beats occasional purges. A monthly slot of an hour or two, with a standing list of candidates, keeps accumulation under control and avoids the heroic clean-up that nobody wants to own. Pair it with a rule that any significant addition names something to retire, or at least states why nothing can be. Over time, that rule changes the culture from collecting to curating.
What is the one thing to remember?
Complexity is a cost you pay continuously, and deletion is the only change that reduces it permanently. Gather evidence, stage the removal, record the reason and measure the result. Do that repeatedly and you will have a system that is easier to run, cheaper to secure and kinder to the next person who has to understand it.

