ARC-59Recommended
Delete code that nothing uses
Remove unused functions, classes, exports, parameters, routes and files as soon as they stop being used. Never commit code that is commented out, because version control already keeps every old line.
How to do it
Run a dead code finder in the build. Delete what it reports, or mark an entry point it missed. Dead code misleads readers and agents, who copy it and keep it alive. Old code in comments goes too. To switch a feature off, use a setting or a feature flag, not a comment.
Examples
TypeScript example
// Bad: kept "just in case", and an agent will copy it
export function legacyPriceWithVat(price: number) { return price * 1.25; }
// Good: deleted, with the history in version control
Python example
# Bad: kept "just in case", and vulture reports it as unused
def legacy_price_with_vat(price):
return price * 1.25
# Good: deleted, with the history in version control
PHP example
// Bad: nobody knows if this still matters
// $total = $this->applyLegacyDiscount($total);
$total = $this->applyDiscount($total);
// Good: the old line lives in the history, not in the file
$total = $this->applyDiscount($total);
How to check
A tool fails the build on new unused code. Examples are knip, vulture, and PHPStan with a dead code extension such as shipmonk/dead-code-detector. A linter fails the build on commented-out code, such as Ruff ERA001 for Python, SonarQube's commented-out code rule or eslint-plugin-no-commented-code.
Sources
Related rules
- ARC-22 Keep change history out of comments in Clean code and architecture
- ARC-60 Remove flags that never change in Clean code and architecture
- TKO-19 Switch off the builder app on a set date in Codebase takeover
- DEN-4 Give every table an owner and a description in Data engineering
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/structure/delete-unused-code">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.