𝛥LOC <= 𝑁 Will Fix All the Agentic Slop in Your Software

AI coding agents hate deleting code. If you’ve worked on production code with AI for some time, you’ll know that they tend to increase entropy at a fast pace. Regardless of instructions to keep the implementation surface minimal and to remove dead code, agents still tend to add rather than remove, even when the latter is objectively the best option. This has already been proved empirically[1].
After quite some time working with agents on production code, this is the best method I’ve developed so far to mitigate the problem.
Computed Coding Meta-Rules Checks #
The practical method is to introduce what I call computed coding meta-rules checks.[2] These are automatic measurements over the actual source files of the codebase. They can be encoded as specific rules. You get the agent to run them at the end of every turn and let it use them as feedback loops.
The Rule #
A practical example of one specific meta-rule I use to keep the codebase from growing out of control — due to the tendency of agents to not delete code that is no longer needed — is the following:
Where
LOC(added) − LOC(removed)
and 𝑁 is an arbitrary number that you define.
The logic is straightforward. If you want your agent to keep changes as small as they should be and make sure it removes unnecessary code when it’s right to do so, you choose an N of ~300 or ~600–700 for bigger implementations.
At the end of every turn, the agent runs the tool that measures the meta-value of
Practical Effectiveness #
This creates at least a couple of good side effects:
(1) The agent will naturally think harder about what the best solution is to solve the problem or implement the feature, rather than jumping straight to the obvious path from its training data or given context.
(2) More importantly, the agent will implicitly understand that if a certain feature or refactoring cannot be implemented within N lines, the only way to reduce ΔLOC is to actually remove lines of code — since
And since the agent is extremely allergic to breaking things — to the point of normally avoiding deleting code at all costs — it will make its best effort to identify and delete only obsolete code that won’t break the codebase or introduce regression.
Footnotes
See To Add Is Machine, To Delete Is Human: Measuring and Mitigating Deletion Avoidance in LLM Code Editing. ↩︎
I call them meta-values because they do not measure code performance or, more generally, what the code does. Instead, they are measurements over the source of that code — hence the word “meta.” See https://dictionary.cambridge.org/dictionary/english/meta. ↩︎
New posts land in the RSS feed. If you'd rather talk than subscribe, reply by email.