By NHI Mgmt Group Editorial TeamBased on Sonar: “Claude Fable 5's pricing makes Sonar Context Augmentation a potent cost lever” (June 15, 2026)

TL;DR: AI coding agents can cut review failures and token spend when they receive architectural, semantic, and dependency context before writing code, according to Sonar. The economic shift from first-pass success to repeated PR retries makes context delivery a governance issue, not just a productivity feature.


At a glance

What this is: Sonar argues that AI coding agents perform better when they receive project architecture, semantic navigation, guidelines, and dependency context before generating code, reducing failed PRs and retry churn.

Why it matters: This matters because agentic coding programmes now have a measurable context and review cost, and IAM-style governance for AI tools increasingly depends on pre-issuance controls, not just post-hoc validation.

By the numbers:

  • The study measured 660 Claude Code trials across 33 tasks, showing how codebase quality affects agent token use and file revisits.
  • Agents working in cleaner codebases used 7 to 8% fewer tokens per run and revisited files 34% less than agents in messier ones.
  • A team merging 200 AI-generated PRs a week can swing between roughly $200 and $800 in output tokens depending on first-pass rate.

Context

AI coding agents create a governance problem that looks like productivity until repeated retries expose the real cost. When the agent lacks project-specific context, it has to rediscover architecture, rules, and dependency posture by reading more code, which raises token spend and increases the chance of PR failure.

That problem is especially relevant to identity and access governance because the agent is operating as a non-human identity with delegated development authority. The key control question is no longer just what the agent can access, but what context it receives before it acts, and whether that context is sufficient to keep it inside policy and code-quality boundaries.

For teams running AI-assisted software delivery, this is a typical emerging pattern rather than an edge case. The same governance gap appears wherever agents can write, revise, and resubmit code without first being grounded in the project’s actual constraints.


Key questions

Q: What breaks when AI code generation lacks project context?

A: Code usually breaks at the integration layer. Imports, types, dependency choices, and local design patterns no longer line up cleanly, so developers must manually repair output before it can be trusted. In practice, the tool becomes a drafting aid rather than a production workflow component.

Q: Why does repeated PR rework become so expensive with coding agents?

A: Each failed attempt adds another output pass and expands the next prompt with failure context, rewritten files, and fresh instructions. That compounding makes agentic development more expensive than single-pass coding because the system pays again to recover from the earlier miss.

Q: What do security and engineering teams get wrong about long context windows?

A: They often assume that more context means better judgement, but a long window does not tell the agent which boundaries matter or which rules apply to a specific file. Without project-aware guidance, the model still has to infer the environment and can choose the wrong path.

Q: How should teams govern AI agents that can install dependencies?

A: Treat dependency installation as a privileged action that requires scoped authority, logging, and explicit approval for new packages. The agent should not inherit broad secrets or unrestricted registry access just because it can generate code. If the workflow must install, do it in a constrained environment with secret minimisation and dependency review before merge.


Technical breakdown

Why context windows do not equal codebase understanding

A large context window gives an AI coding agent more text to process, but it does not give it judgement about which rules matter, which modules are in scope, or which dependencies are allowed. Without semantic guidance, the agent compensates by reading more files, re-reading the same files, and inferring structure from fragments. That behaviour increases both input tokens and the chance of an incorrect first draft. In practical terms, long context is a capacity feature, while project context is a control input. They solve different problems, and only one of them reduces governance friction in agentic development.

Practical implication: Treat context delivery as a pre-write control, not as a substitute for model capacity.

How quality gates turn retries into an economic issue

Quality gates are designed to catch unreliable, insecure, or non-compliant code before merge, but with AI coding agents every failed pass creates another round of prompts, file reads, and output generation. The retry loop compounds because each attempt carries the previous failure context forward, so the prompt grows as the process continues. That means the cost of remediation is not linear. It rises with every pass through the loop, especially when the agent lacks the architectural or semantic context needed to clear the gate on the first attempt.

Practical implication: Measure PR iteration count alongside defect count, because repeated rework is now a budget signal as well as a quality signal.

Why third-party dependency guidance belongs in the agent workflow

AI coding agents often reach for libraries, snippets, or transitive dependencies without understanding the security or licensing posture of what they are introducing. Dependency guidance closes that gap by surfacing known vulnerability data and policy constraints before the agent writes code. In NHI terms, this is a delegated decision boundary: the agent is not merely generating text, it is proposing supply-chain changes on behalf of the development team. That makes dependency approval part of the trust model, not a separate review after the fact.

Practical implication: Require dependency policy checks before code generation if agents can introduce or modify third-party packages.


Threat narrative

Attacker objective: The operational objective is not data theft but uncontrolled, costly code change production that bypasses team intent and drives repeated remediation.

  1. Entry occurs when an AI coding agent receives a task with incomplete architectural, semantic, or dependency context and begins making code changes by inference rather than by policy-aware guidance.
  2. Credential or authority abuse emerges when the agent uses its delegated development access to open pull requests, modify files, or select dependencies without a full understanding of the guardrails it is meant to respect.
  3. Impact appears as repeated PR failures, extra review cycles, and avoidable token consumption, which turn code generation into an expensive rework loop instead of a controlled delivery process.

Read and download The State of NHI & AI Agent Breach Report 2026, covering 200+ breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

Context augmentation is becoming a governance control, not just a developer convenience. AI coding agents are effectively non-human identities with delegated write authority, so the question is whether they receive enough project context to act safely before they touch code. When guidance arrives before generation, the control boundary shifts from review-time rejection to issuance-time direction, which is where modern agent governance has to live.

The iteration tax is the clearest signal that agentic development has crossed into cost governance. Every failed PR adds not only another output pass but also more input context, because the previous failure must be carried forward. That compounding means teams should manage agent loops the way they manage other high-volume control failures: by reducing avoidable retries at the source.

Semantic navigation is the real differentiator, not raw model scale. The article shows that agents waste tokens when they have to rediscover call sites, architecture, and constraints that the platform already knows. That makes the core control problem one of context fidelity, not model intelligence, and it is exactly where governance teams should focus their standards.

Third-party dependency guidance is a supply-chain control hidden inside an AI workflow. If an agent can propose libraries without policy-aware vetting, the development pipeline has allowed a non-human actor to influence the software bill of materials. That is a trust boundary problem, not just a coding-efficiency problem, and it should be treated as part of AI agent authorisation.

Loop engineering is the named concept practitioners should carry forward. The article makes clear that repeated write-fail-revise cycles are not incidental; they are a measurable control weakness in agentic coding programmes. Teams that do not design for loop containment will keep paying for the same decision twice, first in tokens and then in remediation.

From our research library:

What this signals

Loop engineering is the next governance layer for agentic coding. When a model can retry, every unnecessary review cycle becomes a budget and assurance problem, not just a developer inconvenience. Teams need controls that reduce the number of loops an agent enters, because repeated prompts and reruns are where cost and risk accumulate.

As agentic development matures, the strongest programmes will treat context delivery as part of authorisation rather than as a productivity add-on. That shift matters because an AI coding agent is acting as a non-human identity with delegated authority, and delegated authority without the right preconditions creates predictable governance debt.


For practitioners

  • Define pre-write context requirements for coding agents Require architectural, semantic, and policy context to be delivered before an agent generates code, rather than after the first failed review.
  • Instrument PR retry cost and failure loops Track first-pass merge rate, retry count, and token consumption per pull request so repeated rework becomes visible in programme reporting.
  • Constrain third-party dependency selection Route library and package choices through dependency guidance so an agent cannot introduce unvetted or disallowed components by default.
  • Use repository-specific guidance for high-change files Prioritise context augmentation for modules with fragile abstractions, wide fan-out, or heavy review failure history, because those files benefit most from pre-emptive orientation.

Key takeaways

  • AI coding agents fail more often when they have to infer architecture, dependency rules, and file boundaries from scratch, which turns code review into a rework loop.
  • The article’s central signal is economic as much as technical: repeated PR retries increase token consumption and make first-pass success the key control metric.
  • Pre-write context, dependency vetting, and semantic navigation are the controls that reduce avoidable loops and keep agentic development inside governance boundaries.

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 ATLAS 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 AbuseThe article centers on delegated agent authority and misuse risk in coding workflows.
ASI02 — Tool MisuseContext-poor agents misuse search, edit, and dependency tools while trying to infer codebase state.
Recommendation — Apply ASI03 controls to bound what coding agents can access, modify, and delegate during code generation. Restrict tool use to approved paths and pre-authorised actions for code-writing agents.
MITRE ATLASTA0007 — DiscoveryThe agent spends much of its effort discovering codebase structure and call sites before writing code.
Recommendation — Map agent discovery-heavy behaviour to ATT&CK-style hunting for unnecessary file traversal and repeated lookups.
NIST AI RMFMANAGE — AI Risk Management and MonitoringThe article is about managing AI workflow risk through pre-write context and retry containment.
Recommendation — Build controls that monitor, limit, and govern agent retry loops before they become cost and quality failures.
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsCoding agents act with delegated access that must be scoped to their actual task boundaries.
Recommendation — Align agent permissions to PR.AA-05 so non-human identities only act within task-scoped authorisation.

Key terms

  • Context Augmentation: A pattern for injecting only the most relevant information into an AI agent’s working context before it acts. In security workflows, it is used to reduce noise, constrain tool use, and make the agent’s next step more efficient and more predictable.
  • Iteration Tax: Iteration tax is the extra time, token spend, and operational friction created when an AI agent fails a review or quality gate and must rewrite its output. The cost grows as each retry carries the previous failure context forward, making poor initial orientation expensive as well as slow.
  • 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.
  • Loop Engineering: Loop engineering is the practice of designing autonomous AI workflows as closed systems with explicit triggers, sub-agents, review steps, and stop conditions. The goal is not to make the model smarter in isolation, but to make the full work loop bounded, auditable, and safe to run repeatedly.

Deepen your knowledge

The NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, agentic AI identity, and machine identity security. It helps practitioners design controls for delegated access, lifecycle oversight, and policy enforcement across modern identity programmes.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 19, 2026.
Updated on October 12, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org