Same feature, two diffs: 100 vs 57. I built a gate that scores AI code changes.
Ask an AI coding agent to fix a one-line greeting bug and you know what comes back: it works — and it brings friends. A new module, a framework, four abstractions, a fresh dependency. The fix is correct. The codebase pays for it forever. That bloat is the failure mode nobody's CI checks for. Tests pass, lint passes, and the reviewer's eyes glaze over at line 40 of a diff that should have been 5…
AI coding agents often produce code that is bloated and inefficient, filled with unnecessary abstractions and dependencies. This can make code reviews tedious and mask the true complexity of the changes. To address this issue, I created "diffdiet," a tool that enforces a limit on how much code AI agents can add to a single pull request.
diffdiet consists of two main components:
1. A set of rules (in the rules/ directory) that guides agents on how to edit code: no single-use abstractions, no new dependencies for standard library jobs, and deletion of dead code instead of commenting it out.
2. A Python CLI tool that parses unified diffs, assigns a diet score (on a 0-100 scale), and enforces a budget gate in the continuous integration (CI) process.
The CLI tool takes a diff file as input and outputs a diet score. In the example given, a "lean" diff with a score of 100/100 passes the gate, while a "bloated" diff with a score of 57/100 fails the gate. The bloated diff incurs deductions for added lines, new files, new dependencies, and a high number of abstraction suspects (functions or classes defined only once in the diff).
The default budget in diffdiet is a maximum of 300 added lines, 3 new files, 0 new dependencies, and a minimum diet score of 60. These budget thresholds can be customized in a .diffdiet.json file.
The primary goal of diffdiet is not to punish big changes, but to require justification for the size of the change. This encourages both AI agents and human reviewers to carefully evaluate the necessity of each modification. The tool is MIT-licensed, has zero dependencies, and is compatible with Python 3.10 and above.
You can try diffdiet on your own AI coding agent pull requests by visiting the repository at https://github.com/jacelovehaha/diffdiet.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.