---
title: "Delete commented-out code · Agent Wranglers"
url: https://agentwranglers.se/playbook/architecture/comments/no-commented-out-code
updated: 2026-10-20
licence: "All rights reserved"
---

# Delete commented-out code

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Comments](https://agentwranglers.se/playbook/architecture/comments)
- Rule: Never commit code that is commented out. Delete it, because version control already keeps every old line.
- How: Remove dead blocks when you stop using them. If you might need them later, the commit history has them. To switch a feature off, use a setting or a feature flag, not a comment.
- Check: A linter rule or a script fails the build on commented-out code. Examples are `eslint-plugin-no-commented-code`, SonarQube's commented-out code rule and Ruff's `ERA001` for Python.

Example:

```php
// 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);
```

```sh
# A quick check in any repository: lines that look like commented-out code
grep -rnE '^\s*(//|#)\s*[a-zA-Z_$][\w.$]*\s*(\(.*\)|=[^=]).*;?\s*$' src/ && exit 1 || exit 0
```

```python
# Bad
# total = apply_legacy_discount(total)
total = apply_discount(total)

# Good
total = apply_discount(total)
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/comments/no-commented-out-code`.

- Previous: [Refactor clever code instead of explaining it](https://agentwranglers.se/playbook/architecture/comments/refactor-clever-code)
- Next: [Keep change history out of comments](https://agentwranglers.se/playbook/architecture/comments/no-journal-comments)
- [Comments](https://agentwranglers.se/playbook/architecture/comments)
