
In the last 30 days, 70% of the pull requests merged into our main codebase came from our software factory: agents that take a ticket, write the code and see the change through review. Most of the rest were written by engineers working with their own coding agents. . Now it is a question: what is all that agent-written code doing to the codebase underneath it?
Research suggests the answer is not great. SlopCodeBench (Orlanski et al., 2026) followed coding agents as they kept extending the same programs and found two patterns. Complexity piles up in a small number of functions, and duplicated code grows. Neither breaks a build. Both make the next change harder, for people and for agents.
We wanted to know if the same thing was happening to us, so we measured five of our own codebases every week. The headline: left alone, agent-written code drifts toward complexity, and the usual average hides it.
What is code erosion? Erosion is the share of a codebase’s complexity that sits in its overly complex functions. Each function gets a score: the number of decision points in it (each if, loop or case) times the square root of its length, so long, branchy functions score highest. A function counts as overly complex when it has ten or more decision points. When erosion rises, complexity is piling up in a few functions that get harder and harder to change.
How we measured AI-generated code complexity
We tracked five codebases: our backend, frontend and CLI, an internal metrics dashboard, and an internal service that agents have maintained almost entirely on their own, with very little human attention. We adapted the measures from SlopCodeBench and track three things in each codebase:
- Erosion, as defined above.
- Overly complex functions per 1,000 functions.
- Duplicated lines: the share of code that is copied from elsewhere in the same project.
The service agents maintain on their own have seen the steepest climb and now have the most overly complex functions of any codebase we track. It is the closest thing we have to a control group: what happens when agents decide for themselves what good code looks like.
Duplication tells a subtler story. Duplicated lines rose in every codebase, and in the backend they went from about 17,000 to 79,000. But the code grew even faster, so in three of the five codebases the share of duplicated code actually fell. The copies are piling up; they are just being outpaced.
The average said nothing was wrong
We were not starting from zero. Since July we have tracked average complexity per function, file size and duplication. Those numbers looked calm. Between 6 September and 26 October, average complexity in the backend barely moved, from 2.34 to 2.36 paths per function.
Over the same weeks, the share of backend complexity held by overly complex functions rose from 51% to 54%.
Both numbers are true. Most functions are small, so a handful of functions growing barely moves the mean. And that is exactly the pattern agents tend to produce: they add to existing functions far more readily than they tidy them up. A few functions keep getting longer and more tangled while everything else looks fine.
That gives us a simple rule: watch the tail, not the mean. If your code health dashboard reports averages, it can stay flat right up until a few critical functions are too tangled for anyone, human or agent, to change safely. Measures of concentration, like erosion and the count of overly complex functions, show the drift while it is still cheap to fix.
Complexity fell when people paid attention
The charts are not all heading the wrong way. Backend complexity peaked around mid-October and has eased since, and the frontend dipped too. When we looked at every change merged in the weeks around then, the share of new complexity landing in already overly complex functions fell from 65% to 40%.
Two things probably drove it. First, we moved our agents to a different model. The same agent, working on the same codebase, piled roughly half as much new complexity into tangled functions after the switch as before it. Second, the team was cleaning up ahead of a release. Changes that mainly deleted code, such as old features and the flags that switched them on, nearly doubled. And the changes engineers made themselves improved by about a third, which a model switch alone can’t explain.
The implication is uncomfortable. If we stop paying attention and let everything auto-merge, we expect the curves to head back up. Agents today are good at making change work. They are not yet good at deciding, unprompted, what a simple codebase looks like.
Cleaning up and keeping it clean
Attention does not scale, so we are trying to turn it into tooling.
Cleaning up existing code
Small daily fixes. Our first attempt was a maintenance loop. Every day, an agent picked one small simplification, such as deleting code nothing used, merging two copies, or untangling a condition, and our software factory made the change. We ran it on two external codebases. It was good at removing copied code: in one codebase, copied code fell by more than 20% over 63 changes. But erosion barely moved. It fell by 4% of where it started in one codebase and by 0.1% in the other. Small, local fixes don’t reach the few big tangled functions where the complexity actually sits.
A concentrated push. So we built a second mode. Instead of one small fix, an agent reads the whole codebase, finds what is causing the complexity, and plans a larger change across many files, such as replacing a tangle of special cases with a single shared structure. On the same two codebases, about 20 of these changes cut erosion by 9% and 18% of where it started, far more than maintenance mode managed in two or three times as many changes. In the codebase where we run the tests, they all kept passing.
Keeping new code clean
We also added a complexity check to Tessl Verify, which flags pull requests that add branching a simpler structure would avoid. It warns and never blocks. In its first two weeks it flagged about one in five of the pull requests it checked, and on about a third of those the warning was gone by the time the change merged.
We are not done. We’re testing other ways to bring complexity down faster and keep it down, and we’ll report on what works.
Does simpler code help agents?
The strongest pushback is one we put to ourselves: does simpler code actually help agents?
Our data gives a first indication that it does. In the tasks our agents worked on, changes that touched an overly complex function cost about twice as much as other changes. A potential reason for this difference is that the required code changes happened to be generally bigger. Whether that is because of complexity or not remains an open question. But even comparing changes of the same size, they cost about 16% more for changes to more complex functions.
But it raises a bigger question. Are we still writing code for people to read, or for agents? The answer changes which kind of complexity we should be cutting. Code that is easy for an agent to work with may not be what we would call good code, and what “readable” means for an agent is an open question that deserves its own investigation.
That is next. In the meantime, we would rather measure the drift than discover it later.
So here is the question to take back to your own team: if agents wrote most of your code last month, do you know where your complexity is concentrating, or only its average?
If you want to run your own code complexity benchmark, sign up for a free Tessl account and follow our step-by-step guide.
AI Trends