AI-Friendly Code: The Missing Link for Speed with Quality • Adam Tornhill • GOTO Copenhagen 2026
Adam Tornhill examines why AI coding agents deliver early speed gains that often vanish under growing complexity, production incidents, and technical debt. Drawing on large-scale research, he introduces the code health metric as an objective measure of AI-friendliness, shows how agents can safeguard and refactor code within an agentic loop, and describes a Street Fighter 3 case study where agents uplifted 300,000 lines of legacy C code to a perfect score. He closes with how behavioral code analysis reveals architectural hotspots behind recurring merge conflicts.
Speed gains that erode under complexity
AI coding agents produce an early productivity boost, but without attention to code quality that advantage erodes. Adam Tornhill’s team completed tasks two to three times faster after going agentic, yet he argues the real value lies in what that speed enables: taking on work that was previously out of reach and removing coordination bottlenecks. Agents let him handle GitHub Actions himself without interrupting colleagues, which keeps him in flow.
The risks are just as concrete. Research on production data from late 2025 found 41% more defects after developers adopted AI coding tools. A study of more than 1,000 open source projects saw velocity jump roughly 200% in the first weeks, only for those gains to be fully canceled out within two months, leaving projects slower than before adopting AI. The cause was a sharp rise in code complexity. Tornhill describes this as AI operating in a kind of self-harm mode, writing code it cannot safely modify later.
Code health as an objective measure
To manage accidental complexity, Tornhill uses the code health metric from CodeScene, which predates generative AI. Its scale runs from 10.0 down to 1.0. In a study drawing on the research paper Code Red, healthy code allowed developers to finish tasks up to 10x faster than on unhealthy code, and reduced defect risk by up to 15x. The example shown is a tangled function with nested conditionals and no discernible domain, refactored into an agentic loop whose intent is immediately visible. Healthy code also narrows the blast radius of a change, which helps both humans and agents find the right place to edit.
Do AI agents care about code quality?
The follow-up study, Code for Machines, asked whether the same patterns that confuse humans also confuse coding agents. Using an open competitive programming dataset with strong automated tests, the team measured how often an agent broke a passing program. Code health of 9, the threshold considered humanly readable, already corresponded to a defect risk nearly 60% higher for the AI. The implication is that agents need code at 9.5 or even a perfect 10 to keep defect risk in check, making them more sensitive to quality than humans.
What AI-generated code looks like
A C++ extension generated by an agent to send keypress statistics to an analytics service illustrates the problem. The code worked on first test, but it packed many responsibilities into a single function, relied on deeply nested logic (research links roughly 20% of programming mistakes to deep nesting), ignored resource cleanup on exceptions, and included a catch-all clause that silently swallowed errors. When something fails, it fails badly and invisibly. Tornhill’s verdict is that AI frequently generates unhealthy code that the AI itself cannot safely iterate on, creating a self-reinforcing defect loop.
The illusion of instant software
Building a first prototype was never the hard part of software. Tornhill cites the claim that around 95% of a project’s cost comes after the first release, where maintainability and architecture start to matter. An Alibaba research team simulated six months of real software maintenance and found agents performed well on isolated tasks but degraded over time, as the consequences of past decisions accumulated. Production telemetry in the AI Engineer report, the so-called AI whiplash, points the same way: bugs up 54% and incidents up 242%.
Safeguarding every change
The proposed fix is to safeguard all AI-generated and AI-edited code. The team packaged the code health metric as an MCP server connected to Claude, so each generated or modified piece of code gets a health review and the agent is instructed to act on the findings. In the payment validation example, the first attempt scored poorly, the second improved, and the third reached healthy code. The human reviewer only sees the final result, starting from code that is already healthy.
The average codebase is far from ready
The average codebase scores about 5.15 on the 10-point scale, far below the 9.5 threshold for AI-friendly code. Tornhill interprets this gap as a bottleneck for enterprise adoption: many organizations will need to uplift legacy code before agents can accelerate them without quality loss. The good news is that the uplift can itself be agentic.
Earlier experiments showed that agents could fix roughly 50% of code health issues in the best case, but performance dropped to around 20% as code improved, and the agent became overly conservative, making trivial changes like renaming variables. Adding the code health data as a goal and feedback mechanism changed the outcome, because the agent could form a plan and measure its progress toward healthy code.
Case study: uplifting Street Fighter 3
The team applied this to Street Fighter 3, a 25-year-old C codebase of about 300,000 lines. The goal was a code health of 10.0 with functional correctness maintained. Correctness was verified with a replay trace harness that hashed frames before and after each refactoring, plus human play testing. The agent was instructed to build a refactoring playbook as it worked, documenting the conditions, constraints, and mechanisms behind each successful refactoring so that later refactorings became more effective.
Two colleagues worked on the side, spending about two weeks on process setup. GPT models were good at refactoring but poor at documenting it, so the team settled on Claude Opus 5.5, which captured the playbook better. The actual uplift took a couple of days. After one week of agentic refactoring, every file scored 10.0. Tornhill estimates a manual effort of 12 to 18 months with a team of five or six senior experts and a high risk of failure.
Codebase-specific refactoring recipes
The most interesting finding was in the playbook. Alongside generic refactorings such as extract function and extract class, the agent had invented codebase-specific recipes with precise constraints, such as the action parameter pattern. Two near-identical functions, differing only in whether they operated on the X or Y coordinate space, were collapsed into one internal function that accepts the varying behavior as a parameter, with the originals reduced to one-line dispatchers. This resembles the strategy pattern implemented with function pointers, but the AI-driven innovation is the narrow, local recipe. Such recipes bridge problems specific to a codebase to general design knowledge the model already holds, which makes refactoring at scale predictable and mechanical. Broad instructions to ‘apply strategy’ would not have worked.
Engineering outcomes
Healthy code is also token-efficient. On average, features in healthy code required 40 to 45% fewer tokens than in unhealthy code, varying by language. For the 300,000-line uplift, the team measured a 17% reduction in AI-induced defects and projected that new features would cost 45% less in token spend. The API cost for the full uplift was roughly $4,000, which gives a concrete basis for a business case.
Merge conflicts as a design signal
As agent-driven development accelerates, recurring merge conflicts appear at enterprise scale, and the industry response has been better PR tooling such as stacked PRs and intelligent conflict resolution. Tornhill argues these patch symptoms. Recurring conflicts point to a social-technical disconnect between what agents are doing and what the architecture supports.
Using behavioral code analysis on a Meta codebase (Folly), he visualized hotspots by the number of agents modifying the same code over the past month, rather than developers over six months. One asynchronous socket communication file had been modified by 58 different authors over six months. Its code showed deeply nested conditionals, lengthy comment blocks signaling a separate responsibility, and hundreds of similar functions spanning a thousand lines. This is a god class: a module that collects too many responsibilities, forcing unrelated features and agents into the same code. Refactoring such modules reduces organizational friction as well as technical debt.
Module-level code quality is largely solved by the automation discussed, Tornhill says. The next frontier is scaling AI friendliness to design and architecture, a problem he has begun exploring. Organizations with strong existing engineering practices are thriving in the agentic age, while others struggle to gain benefits, and focusing on engineering fundamentals is a prerequisite for both speed and quality.