By NHI Mgmt Group Editorial TeamBased on Sonar: “The context tax: why your coding agent reads the same 600 lines 400 times” (September 1, 2026)

TL;DR: AI coding agents in large repositories can burn 156 million context tokens and peak at 459k tokens on a single ~800-line pull request, according to Sonar’s analysis, because every blind read is re-billed across hundreds of turns. The key implication is that graph-based code navigation, not grep, becomes the control that limits cost and missed call sites.


At a glance

What this is: Sonar argues that AI coding agents in large repositories incur a heavy navigation tax, with one ordinary pull request reaching 156 million context tokens because text search and repeated file reads stay in the conversation.

Why it matters: IAM and security teams using coding agents need to think about how access to code, docs, and call sites is discovered, because poor navigation increases cost and raises the chance of missed dependencies, broken changes, and rework.

By the numbers:

  • One ordinary ~800-line pull request reached 156 million context tokens in Sonar's analysis.
  • The same session peaked at 459k context tokens, close to the window limit Sonar described.
  • Sonar measured 512 model round-trips in the session behind the pull request.
  • The analysis says 152.8 million of the billed tokens were cache reads.

Context

AI coding agents run into a governance and efficiency problem when the repository is larger than the model window: they have to keep re-reading the same material just to answer ordinary navigation questions. In practice, that means file reads, grep output, and broad code slices become durable conversation state, so the cost of looking up a symbol or call site keeps compounding.

The identity angle is indirect but real. When an agent is acting on repository content, its effective authority depends on what it can discover, not only what it can edit, and that makes code navigation a control surface. For teams governing AI-enabled development, the issue is whether the agent is operating with precise, bounded context or with a growing pile of stale text that inflates both cost and error rates.


Key questions

Q: What breaks when coding agents rely on grep in multi-language codebases?

A: They miss semantic relationships that text search cannot express, such as owner types, return types, cross-language equivalents, and indirect callers. That leads to broader reads, missed dependencies, and extra CI cycles, all of which increase cost and delay safe delivery.

Q: Why do AI coding agents become expensive in long-running sessions?

A: Because each new turn re-sends prior conversation state, so earlier file reads are paid for again and again. A single over-read can become millions of re-billed tokens if it remains in the session for hundreds of turns, which is why navigation efficiency matters as much as model quality.

Q: How can security and engineering teams tell whether agent navigation is failing?

A: Look for broad searches, repeated widening of file slices, high cache-read volume, and builds that fail because the agent missed an indirect reference. Those symptoms show that the agent is discovering code by trial and error rather than by precise semantic lookup. If the same questions keep forcing new reads, the navigation layer is the problem.

Q: Should teams prefer semantic code graphs over text search for AI coding agents?

A: Yes, when correctness depends on knowing the owner type, the bound definition, or the return path of a symbol. Semantic graphs reduce context bloat and lower the risk of missing call sites that grep cannot express. Text search still has a role for rough discovery, but it is not a reliable control for agentic code navigation.


Technical breakdown

Why context windows turn code navigation into a tax

A coding agent in a large repository cannot hold the whole codebase in memory, so it searches with grep, opens files, and widens the read when the first slice is not enough. Every one of those tool results becomes part of the conversation and is sent back into later turns, so the agent pays again for earlier mistakes. This is not a reasoning failure. It is a retrieval and context-retention problem caused by treating raw text as the navigation layer for code. The larger the repository and the longer the session, the more expensive each blind read becomes.

Practical implication: Measure navigation cost as a first-class agent-control metric, not just model output quality.

Why grep misses call sites and semantic relationships

grep is a string matcher, not a code-understanding system. It can find a function name in many files, but it cannot tell which definition a call actually binds to, which type owns the method, or how another language names the same contract. That is why a simple search often forces broader reads and still leaves uncertainty about the correct call path. The technical problem is semantic ambiguity: code behaviour is expressed through relationships, not only substrings. In large repos, missed indirect calls and cross-language equivalents are exactly where regex-based navigation breaks down.

Practical implication: Use semantic indexing for code lookups where correctness depends on ownership, return type, or cross-language binding.

Why graph-based navigation reduces both tokens and misses

A unified dependency graph changes the question from 'which files mention this string' to 'which node does this call bind to, and what relationships surround it'. Typed edges such as calls, references, returns, and documented_by let the agent retrieve only the relevant node and its immediate neighbourhood. That cuts context load, but it also reduces false negatives because the lookup follows meaning instead of spelling. For codebase-scale tasks, the value is not just less prompt bloat. It is fewer wasted turns, fewer widened reads, and fewer missed call sites that would otherwise surface later in CI or review.

Practical implication: Prefer graph-backed navigation for agents that must operate reliably across large, changing codebases.


NHI Mgmt Group analysis

Navigation, not model intelligence, is the limiting factor in large-codebase coding agents. The article shows that the expensive part of the workflow is not generating code, but repeatedly rediscovering code. Once context has to persist across hundreds of turns, every unnecessary read becomes a compounding cost and a compounding failure surface. Practitioners should treat retrieval quality as an agent governance issue, not a convenience feature.

Graph-native code access is the more durable control pattern than text search for AI-assisted development. A unified dependency graph is better aligned to how code actually behaves because it exposes ownership, call direction, and return relationships directly. That matters for agentic AI security as well: the agent's effective scope is defined by what it can precisely locate and reason over, not by how much raw text it can ingest. Practitioners should favour semantic context over broad file exposure.

Context persistence creates an invisible tax that scales faster than the change itself. The article's key finding is that a small diff can still trigger a huge context bill when the agent keeps carrying old reads forward. That is a governance problem because it changes how teams should assess agent cost, quality, and risk in large repositories. Practitioners should monitor token persistence as carefully as they monitor build time or review latency.

Call-site resolution is the right named concept for this problem space. The article makes clear that the agent needed to know which type owned a method, where it was defined, and what it returned. That is precisely the navigation capability missing from grep-driven workflows and exactly what semantic graph traversal provides. Practitioners should design AI development workflows around call-site resolution rather than file discovery.

AI coding agents expose a new identity-like boundary inside the software supply chain. The agent is only as accurate as the context it is handed, and in a large repository the wrong lookup path can become an operational dependency. That does not make the agent a human identity issue, but it does mean its discovery and authorisation boundaries deserve governance. Practitioners should align agent access paths with least-context principles.

What this signals

Call-site resolution: AI coding agents need navigation that resolves meaning, not just text matches, because large repositories make broad search both costly and incomplete. Teams that let agents operate on raw file reads will keep paying a context tax on every turn, while graph-backed lookup reduces both misses and token waste.

For practitioners, the practical question is no longer whether agents can write code, but whether they can find the right code fast enough to stay inside operational budgets. That makes repository indexing, context budgeting, and semantic retrieval part of the AI governance stack rather than an optional optimisation.


For practitioners

  • Instrument context-token usage per task Track fresh input, cache-read, and total billed tokens for each agent session so you can see when navigation overhead is driving cost.
  • Replace blind grep with semantic code lookup Route symbol, ownership, and call-site questions through a graph or dependency index instead of broad text searches that widen the context window.
  • Set navigation budgets for agent workflows Define a maximum acceptable context footprint for routine changes and flag sessions that keep re-reading the same files across many turns.
  • Link code to the governing documentation Attach the exact design note, ADR, or implementation guide to the code node so the agent can retrieve the right explanation without scraping the whole wiki.
  • Review missed-call-site failures after agent commits Use CI rework, repeated build failures, and late-discovered indirect references as signals that navigation quality is weak.

Key takeaways

  • Large-repository coding agents can accumulate massive token bills because every exploratory read survives across later turns and gets re-billed.
  • String search is a weak control for code navigation when correctness depends on ownership, call sites, and cross-language relationships.
  • Semantic graph lookup changes the economics of AI coding agents by reducing context bloat, missed references, and rework.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Agentic AI Top 10 and MITRE ATT&CK address the attack and risk surface, while NIST AI RMF and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Agentic AI Top 10ASI03 — Identity & Privilege AbuseAgent navigation and call-site discovery shape the practical scope of agent authority.
Recommendation — Constrain agent lookup paths so code access stays bounded to the task context.
MITRE ATT&CKTA0007 — DiscoveryThe article centres on how agents discover code paths and dependencies in a repository.
Recommendation — Map agent search behaviour to Discovery and monitor for broad, repeated repository traversal.
NIST AI RMFMAP — Map Context and RisksThe article is about understanding where AI agents consume context inefficiently and unreliably.
Recommendation — Map agent navigation and retrieval failure modes before deploying them in large repos.
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsRepository access and discovery boundaries are part of the control plane for coding agents.
Recommendation — Apply least-privilege access to the repositories, docs, and symbols agents can traverse.

Key terms

  • Context Window: The context window is the text a model receives at one time, including prompts, retrieved documents, and conversation history. Security teams care about it because it becomes the practical boundary between trusted instructions and untrusted content, especially when the application assembles that text automatically.
  • Call-site resolution: The process of determining which definition a function call actually binds to, along with the owning type and returned value. In large codebases, this is a semantic lookup problem, not a string-matching problem.
  • Semantic Navigation: Semantic navigation is the use of code relationships such as call stacks, hierarchies, references, and source locations to help an AI agent understand a codebase. It is more reliable than simple string search because it reflects how the software actually connects, not just how text appears in files.
  • Cache-read tokens: Tokens from earlier conversation content that are re-sent into later turns and charged again at a reduced rate. They are still part of the bill and can become the dominant cost in long-running agent sessions.

Deepen your knowledge

NHI Mgmt Group covers identity security, NHI governance, and agentic AI through independent research, practitioner guides, and the NHI Foundation Level course. It is suitable for security and identity practitioners who need to govern machine identities, AI agents, and access boundaries with more precision.
NHIMG Editorial Note
Published by the NHIMG editorial team on September 2, 2026.
Updated on October 11, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org