InfoQ Homepage News Producing Healthy Code with Artificial Intelligence Costs Fewer Tokens.
Nov 19, 2026 4 min read.
It has been revealed that agentic AI can speed up velocity, but the gains vanish within months as code complexity grows. In his presentation on AI-friendly code at GOTO Copenhagen, Adam Tornhill highlighted that healthy code makes AI perform better and costs fewer tokens. Safeguarding means keeping code health high through agentic refactoring, with an MCP supplying code health data, so AI can maintain the code it generates.
According to recent reports, developing software with agents is significantly harder than writing code manually, Tornhill argued. But with agentic AI, they can complete tasks two to three times faster, he added. It also helps them unblock themselves and reduces coordination needs.
Tornhill mentioned a study done on 1000+ open-source projects which highlighted that with AI, velocity went up during the first few weeks, but after two months the velocity gains were fully canceled out due to a massive increase in code complexity:.
AI operates in a self-harm mode, often writing code it cannot reliably maintain later.
Code health measures how easy code is to understand, change, and maintain. Research done on human coding (before AI) highlights that if you have healthy code, you can be up to 10x faster than someone who works on similar problems in unhealthy code, Tornhill mentioned. The defect risk is reduced 15 times, and code reviews go twice as promptly, he added.
According to recent reports, building a prototype was never the hard problem in software; 95% of the costs for any software project come after the first release. This is where code quality, maintainability, and architecture start to matter, Tornhill stated.
It has been revealed that recent research demonstrates that large language models perform consistently better in healthy code. AI won’t generate perfect code; if we want to survive in the Agentic age, we need to focus on safeguarding, Tornhill noted.
Recent findings suggest that the average codebase has a code health of 5.15, where AI-friendly code starts at 9.5. Technical depth is a bottleneck for enterprise adoption of agentic coding; what’s needed is an agentic refactoring, Tornhill argued. Claude can be used to fix code health challenges, but only to a certain extent:.
As a best-case scenario, an agent can fix roughly 50% of the code health issues for lower-health code. Once the code health improves, the AI performance drops sharply, and Claude can only correctly refactor 20% of the code. AI tends to become conservative, doing small changes that don’t really move the needle on code quality.
Sources indicate that adding an MCP with code health data can lead to a 90%-100% fix rate, Tornhill said. Agentic refactoring turned out to be a predictable and mechanical process at scale, where AI was capable of doing codebase-specific refactorings.
Healthy code is also financially viable code, with healthy code, you can do things with 40% to 45% fewer tokens, Tornhill mentioned.
By refactoring code, modularizing it and making it healthy, we can also reduce organizational friction, Tornhill said. Code quality at the module level is a largely solved problem with the automation we now have. Scaling AI friendliness to the design and architectural level is the next significant challenge, he concluded.
InfoQ interviewed Adam Tornhill after his talk.
InfoQ: How can we measure code health?
According to recent reports, adam Tornhill: Code Health is a multifacetted concept, so we need to combine multiple metrics. We’ve found that it works best when combining measures from three levels of software design:.
InfoQ: How do you safeguard AI-generated code?
Tornhill: Safeguarding needs to happen at multiple levels, and all safeguards need to be completely automated in an agentic context. Examples of concrete safeguards include linting, code coverage, mutation testing to ensure your tests actually test, and higher-level metrics like Code Health. In practice, these safeguards are exposed to agents as local MCP servers or command-line tools.
InfoQ: How can we do refactoring at scale with agents?
Tornhill: The main steps are to establish a baseline, build a safety-net for behavior, and provide a feedback loop to the agents refactoring the code. The whole process is highly iterative.
Presented by: Kiran Gangadharappa - Engineering Advisor at Harness, and Scott Davis - Senior Engineering Manager at Harness.
In a recent development, A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example.
