If your agentic code review pipeline is burning cash, stop looking only at diff sizes. A new study led by PhD student Lo Gullstrand Heander from Lund University, in collaboration with CodeScene, reveals that the health of the code itself is a massive, independent cost driver. Across 465 agent-authored pull requests, researchers found that every single point of improvement in 'Code Health'β€”a metric for code qualityβ€”correlates with a 3.5% to 6.1% reduction in token usage. For engineering leaders running AI agents, this means your refactoring backlog is directly impacting your monthly cloud bill.

The Data: Three LLMs, One Conclusion

The study utilized a five-agent review-and-fix pipeline tested against three distinct models: deepseek-v4-flash, qwen3.6, and claude-sonnet-5. The results were consistent across the board, though the magnitude varied. deepseek-v4-flash showed the steepest savings, with a 6.1% token reduction per Code Health point, translating to a 35.0% total saving when comparing a typical unhealthy pull request (score 2.8) to a healthy one (score 9.7). claude-sonnet-5, often regarded as the most capable of the trio, still demonstrated a significant 3.5% reduction per point, totaling 21.8% across the same contrast. The researchers pre-registered their hypotheses on OSF in August 2026 to ensure statistical rigor.

It’s Not Just About Small Pull Requests

A common assumption in the AI engineering community is that token costs are primarily driven by the size of the diff. While the study confirms that pull request size is indeed the strongest single driver of cost, it explicitly decouples this from code health. The sampling strategy ensured that Code Health scores were unrelated to the physical size of the changes. This proves that keeping pull requests small does not substitute for maintaining healthy code; they are two separate levers. Unhealthy code forces agents to perform more iterations and retrieve more context, even when the number of lines changed remains constant. The agents write a similar number of comments on healthy and unhealthy code, but reaching those comments costs significantly more on the unhealthy side.

Where the Money Burns: Complex Control Flow

The research identified specific code smells that act as primary cost drivers. Complex Method and Complex Conditional structures were found to predict higher fix-stage token usage across all three LLMs. Conversely, Code Duplication did not show a consistent correlation, and for claude-sonnet-5, the sign even reversed. This suggests that tangled control flow is the true enemy of efficient agentic review. The review stage alone accounted for a median of 84.7% to 86.2% of total tokens per pull request. In one illustrative example, an unhealthy pull request with a Code Health of 2.77 consumed 715,716 tokens, while a healthy pull request with a score of 9.02 consumed only 325,612 tokens, despite both having similar line counts.

Key Takeaways

  • Code Health is an independent cost driver: Improving code quality reduces token spend even if pull request size remains unchanged.
  • Complex control flow is expensive: Complex Methods and Conditionals are the primary code smells driving up agent token usage.
  • One-pass fixes don’t refactor: A single batch fix pass by an agent left the median Code Health score unchanged for nearly half of the tested pull requests.
  • Model capability doesn’t negate the need for clean code: Even the most capable models (claude-sonnet-5) showed significant token savings on healthier code.

The Bottom Line

Stop treating code quality as a 'nice-to-have' for maintainability. In the era of agentic coding, it’s a direct line item in your AI infrastructure budget. If you aren't gating your agentic workflows on Code Health, you’re effectively subsidizing your technical debt with every token you spend.

Recommendation for CTOs

Engineering leaders should integrate Code Health metrics directly into their AI cost models. The study recommends implementing a quality gate on incoming changes that touch files frequently reviewed by agents. Since Code Health is determined by deterministic static analysis, it is cheap to run. By enforcing a minimum health score before allowing agents to review, you can cap the token explosion caused by complex, tangled logic. Additionally, plan refactoring as its own distinct work stream; the data shows that automated agent fixes are not a substitute for intentional structural improvement.