Devlery
Blog/MCP

One PR Cost This Coding Agent $41, and Only 106K Tokens Were New Code

Sonar instrumented its own coding-agent session traces. An 800-line PR took 512 model round trips, 152.8M cache-read tokens, and roughly $41, while newly read code accounted for only 106K tokens.

One PR Cost This Coding Agent $41, and Only 106K Tokens Were New Code
AI 요약
  • One 800-line PR cost about $41, and only 106K tokens of it were newly read code.
  • The rest was 152.8M cache-read tokens: files read once, then rebilled every single turn.
  • The numbers are Sonar's own traces, unreproducible, and free MCP tools do the same trick.

On September 1, 2026, Sonar, the company behind the static analysis tool SonarQube, published the token bill for one of its own coding-agent sessions. A single PR that changed 800 lines took 512 model round trips. The context window peaked at 458,700 tokens, and the session billed roughly $41.

The composition of that $41 is the part worth reading. Code the agent newly read: 106,000 tokens. Content rebilled as cache reads: 152.8 million tokens. That is a ratio of roughly 1,440 to 1. Almost the entire invoice was not new work but files already read and sitting in the conversation history.

Sonar calls this the context tax.

Why this cost never showed up as a line item

When an agent reads a file, the contents enter the conversation history. From then on, every single model response re-sends the entire history. A human sees one file read; the meter charges for it once per remaining turn.

Sonar's example is concrete. The agent opened a 618-line file at turn 42, when all it needed was one function inside it. The immediate waste was about 5,770 tokens. But that read stayed in the conversation history for the remaining 470 turns and was rebilled as a cache read on every one of them.

5,770
tokens wasted on the single read
470 turns
that read stayed in the history
2.7M
cumulative rebilled tokens (about $0.54)

Sonar puts it this way: read a 600-line file at turn 40 of a 512-turn session, and what you paid for is not 600 lines. It is 600 lines times the 470 turns that follow.

The price of opening the wrong file is not charged at that moment; it is amortized across the rest of the session. The invoice shows a single "cache read" line, so which file read produced which share of the bill is invisible until you open the trace yourself. Reasonix's 99.82% prefix cache case is the same mechanism viewed from the other side: what you gain when the cache hits.

The measurements, and their limits

Alongside the single session, Sonar published averages across 18 PRs of similar size.

MetricSingle PR (800 lines changed)Average of 18 PRs
Model round trips512about 700
Total context tokens152.8M (cache reads)mean about 234M, median 178M
Peak context window458,700 tokens450K to 975K tokens
Session costabout $41mean about $65, median about $52

Context tokens billed across 18 PRs, with a median of 178 million and a mean of 234 million

A median of $52 per PR. A team of ten each landing one PR a day puts that on the order of $10,000 a month. The spread is wide too: in the chart above the smallest PR finished at 13 million tokens, and the largest consumed close to 760 million.

That said, every one of these numbers is self-reported by Sonar from its own codebase. Sonar states only that it kept full traces while building SemSitter as a coding agent, which is what made precise measurement possible. It does not disclose which agent or which model was used. The target repository is identified only as "our own codebase" and "the SemSitter repo." There is no way for a third party to reproduce the conditions.

Token prices are also still falling. Claude Fable 5.1 cut cache reads to $0.25 per million tokens. The same 152.8 million tokens produce a very different figure depending on whose price list you apply, so $41 is a snapshot, not a constant.

The cause Sonar names: grep-style exploration

Sonar points at how agents locate code. Most coding agents today search filenames and text (grep, ripgrep, and friends) to find candidate files, then read those files whole.

Sonar lists four limits of text search.

  1. It returns results across multiple backends at once with no way to tell what is relevant.
  2. It cannot tell which call binds to which definition. Three functions share a name, so all three are candidates.
  3. It does not know function boundaries, so needing one function means opening the whole file.
  4. It misses indirect callers, aliases, and the same implementation written in another language.

Sonar's alternative is a code indexing engine called SemSitter. It turns every function, method, class, field, and parameter in a repository into a node, then connects them with typed edges for the relationships between them: calls, references, returns, parameter ownership, types, containment, and inheritance. Sonar calls the result a UDG (Unified Dependency Graph), and it updates as soon as the repository changes.

The question you ask changes shape.

Text search

“Which files mention resolve_return_type?”

Result: several candidate files. Each one has to be opened whole to check.

Code graph

“Give me the resolve_return_type definition this call binds to, the type that owns it, its return type, and its callers.”

Result: that node and its edges. No surrounding files, no six-way search, no widening the scope.

The effect shows up in an A/B experiment Sonar published on June 30. Running Claude Opus 4.8 at high effort with subagents enabled, it reproduced six real merge commits from open-source projects, ten runs per condition. Only runs that compiled and passed the target tests were counted.

TaskLanguageInput tokensCost (median)
BloomFilter self-typingJava-31%-34%
SQLAlchemy compiler kwargsPython-24%-29%
BloomFilter package renameJava-11%-25%
QuartzNET return typeC#-25%-20%
AssertJ argument reorderJava-18%-15%
TanStack mutation contextTypeScript-21%-6%

Tokens loaded into context for a single question: 6,472 when grep reads the whole file, 700 when the graph returns one function

Handling one identical question loaded 6,472 tokens the grep way and 700 tokens through a graph query, roughly a ninth. Applied to the 618-line example above, the grep path generated about 2.7 million rebilled tokens across 470 turns; the graph query would have generated about 330,000.

The largest saving moved a baseline median of $14.29 down to $9.38. The other end is the 6% on the TanStack task. Sonar states the condition itself: savings appear when finding and understanding code is the actual work. They are largest on tasks where text search cannot cleanly enumerate the target sites, such as refactoring a widely implemented abstraction. On work that touches two or three files, wiring up a graph changes little.

Can you use it today

SemSitter is not sold on its own; it ships inside Sonar Vortex, which reached GA on June 30, 2026 by merging two former beta products, Sonar Context Augmentation and SonarQube Agentic Analysis. The biggest barrier to entry is that it is paid enterprise-tier only.

ItemCondition
Required planSonarQube Cloud Team (annual billing) or Enterprise
Additional purchaseSonar Agent Essentials, a separate subscription. Price undisclosed, contact sales
Free tierFree up to 50k LOC, but Vortex is not included
Team planFrom $34/month at 100k LOC, 14-day free trial
Availability outside the US and EUNo regional blocking, but the only region choices are EU and US. There is no Asia region
RequirementsDocker Desktop, Podman, or Nerdctl running; SonarQube CLI 1.3.0 or later; the target project already analyzed on a long-lived branch such as main
Supported agentsClaude Code, Cursor, GitHub Copilot, Windsurf, Google Gemini CLI, OpenAI Codex CLI, and other MCP-compatible agents
Languages with semantic navigationJava, C#, JavaScript, TypeScript, Python, Rust

The Claude Code setup is documented. Install the SonarQube plugin with /plugin, then run /sonarqube:sonar-integrate in the project folder. That registers the MCP server in .mcp.json and creates three hooks in .claude/settings.json: secret detection on file reads, credential scanning on prompt submission, and analysis on edits. Context augmentation is not automatic, though. You have to invoke /sonar-context-augmentation per task.

If you want to change how your agent explores without paying for it, open source has tools built on the same idea. Serena is an MCP server that uses a language server (LSP) to look up definitions and references at the symbol level. mcpls is a general-purpose bridge that exposes language-server capabilities as MCP tools. Both run locally for free. Neither gives you the quality and security rule injection or the real-time validation Sonar sells alongside. The overlap is exactly the part that replaces text search with symbol queries.

Whether Sonar's $41 describes your team is faster to measure than to take on faith. If you are running agents against a large repository, open the usage log for one session from this week and compare cache-read tokens against new input tokens. If that ratio lands anywhere near the 1,440x Sonar saw, you have a reason to try a graph navigation tool. If it stays in the double digits, adopting one puts you closer to the 6% end of the TanStack task.