By NHI Mgmt Group Editorial TeamDomain: AI SecuritySource: SonarPublished 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 giving AI coding agents architectural, semantic, and dependency context before they write code reduces quality-gate failures and expensive retry loops.

Why it matters: For IAM and security teams, the lesson is that agent behaviour must be governed with context, policy, and verification before code reaches runtime or review gates.

By the numbers:

👉 Read Sonar's analysis of context augmentation for AI coding agents


Context

AI coding agents are only as useful as the context they receive before they act. In this case, the governance gap is not raw model capability but the absence of project-specific boundaries, rules, and dependency awareness at the moment decisions are made. That is why context augmentation matters for AI agentic workflows and for identity teams that need to control what software entities can do.

Sonar frames the problem around AI coding agents that can iterate quickly, but still burn time and tokens when they have to rediscover architecture, conventions, and call sites on each pass. The security implication is broader than software quality: if an agent cannot reliably distinguish permitted from disallowed action, the organisation is effectively delegating decisions without sufficient guardrails.

The starting position described here is typical of teams adopting AI coding tools quickly and then discovering that review gates and prompt loops become the real bottleneck.


Key questions

Q: How should security teams control AI coding agents that keep failing review gates?

A: Treat the agent's first prompt as a control point. Give it architecture, policy, and dependency context before it writes code, then measure whether failures are caused by missing context or by genuinely flawed changes. If the agent keeps iterating on the same issues, the workflow is under-governed, not just inefficient.

Q: Why do AI coding agents create governance risk even when they improve productivity?

A: They create risk because faster output does not guarantee safer output. If review criteria, training, and accountability lag behind adoption, agents can introduce inconsistent code, hidden instructions, and unreviewed changes. Productivity only counts when quality, auditability, and policy compliance improve at the same time.

Q: What breaks when AI agents lack semantic understanding of a codebase?

A: They fall back to expensive exploration. That means more file reads, missed call sites, and more prompt rounds before the agent lands on the right change. The result is higher token spend and a greater chance that the first revision will still fail the gate because the agent never saw the full dependency picture.

Q: How do teams know whether context augmentation is actually working?

A: Look for fewer retries, fewer file revisits, and a higher first-pass gate-clear rate. If output tokens rise only because the work itself is larger, that is normal. If input tokens keep growing across small tasks, the agent is still rediscovering context that should already be supplied up front.


Technical breakdown

Why AI coding agents need architecture-aware context

AI coding agents can generate plausible changes from a single file, but large codebases are governed by constraints that are only visible across repositories, modules, and interfaces. Architecture-aware context tells the agent which boundaries exist, which services are allowed to interact, and where hidden dependencies sit. Without that, the agent wastes tokens rediscovering the system and often proposes changes that fail policy or quality gates. This is less about model intelligence than about decision locality: the agent needs the same structural view a senior engineer would use before editing production code.

Practical implication: provide architecture context before generation so the agent does not learn boundaries by failing them.

Semantic navigation and intelligent guidelines reduce retry loops

Semantic navigation uses call stacks, class hierarchies, references, and source locations to orient the agent more accurately than string search or file-by-file scanning. Intelligent guidelines narrow policy to what actually matters in the files being changed, instead of dumping every rule into the prompt. Together, they reduce the iteration tax created when an agent writes, fails a gate, and rewrites with even more context. In a multi-loop workflow, each retry expands the prompt and drives up both input and output cost. That makes context selection a cost-control mechanism as much as a code-quality mechanism.

Practical implication: feed the agent targeted rules and semantic references so it can clear review gates on the first pass more often.

Third-party dependency guidance is now part of coding governance

Modern AI coding agents do not only create internal code paths. They also choose libraries, packages, and dependencies, which means they can introduce vulnerability, licensing, and supply-chain risk at generation time. Third-party dependency guidance closes that gap by vetting what the agent is about to pull in before the code is written. This is important because the failure mode is not simply a bad dependency version, but an agent making a convenience-driven choice that later becomes a security, legal, or maintenance problem. Governance needs to move upstream into the agent's planning stage.

Practical implication: inspect dependency choices before generation, not after merge, because remediation cost rises once the agent has propagated them.


Threat narrative

Attacker objective: The practical objective in this pattern is not theft but inefficiency, where poor context turns AI-assisted development into an expensive, failure-prone workflow.

  1. Entry begins when the AI coding agent receives a task with insufficient project context and starts exploring the codebase by itself.
  2. Escalation occurs as repeated quality-gate failures force the agent into additional prompt and PR iterations, compounding token spend and widening the context window.
  3. Impact is a higher-cost, less reliable development loop in which teams pay to rediscover codebase knowledge that should have been supplied up front.

NHI Mgmt Group analysis

Context augmentation is becoming a governance control, not a productivity feature. AI coding agents now make decisions that affect code quality, dependency exposure, and release velocity. If the agent lacks project-specific context, the organisation is not just slower, it is delegating software decisions without a reliable control layer. In practice, context must be treated as part of the security model, not a convenience add-on.

Iteration cost is the visible symptom of a deeper trust problem. The article's core insight is that failed PR loops are not simply wasteful, they are evidence that the agent was trusted to act before it was properly oriented. That creates a named risk we can call iteration tax exposure: the cost and drift caused when every retry rebuilds context that should have been supplied once. Practitioners should read this as a sign that agent governance is moving from review-stage control to pre-generation control.

Third-party dependency choices are now an AI supply-chain issue. When an agent selects libraries or packages, it is participating in software supply-chain risk management whether the team has formalised that or not. That intersects directly with IAM-style governance because the agent is acting as a software identity with bounded authority. The control question is no longer only what code was written, but what external trust was implicitly granted by the agent's plan.

Semantic awareness helps enforce least surprise for autonomous code changes. A coding agent that understands call graphs, architecture boundaries, and actual references is less likely to surprise reviewers with changes outside intended scope. That makes the control problem similar to privilege scoping in identity programmes: authority should match the task, and nothing more. Teams should use this pattern to align agent permissions with narrow, observable change scopes.

Loop engineering should become part of AI governance design. The article shows that runtime economics and governance are now linked, because every retry increases both cost and the chance of drift from intended behaviour. Organisations need to design agent workflows so that verification, context, and remediation are staged deliberately. The practitioner conclusion is straightforward: if you do not govern the loop, the loop will govern your bill and your risk.

What this signals

AI coding agents are beginning to behave like governed software identities: they need scoped authority, observable context, and enforced boundaries before they write anything. That means the practical question for security leaders is not whether to adopt agents, but how to prevent their autonomy from outrunning the controls that define acceptable action.

Iteration tax exposure: when AI agents repeatedly fail gates, the organisation pays twice, once in tokens and again in governance drift. Teams should expect context-rich workflows to become a measurable control objective, not an optimisation side project.

Where code generation touches credentials, secrets, or deployment pipelines, the identity boundary matters even more. Agent access should be treated as a privileged workflow with explicit ownership, narrow scope, and auditable context, especially where changes can affect production trust chains.


For practitioners

  • Define pre-generation context packages Assemble architecture graphs, repository constraints, and project-specific coding rules before the agent writes code, so it does not infer boundaries from a single file. Link the package to the files and services the agent is allowed to touch.
  • Narrow prompts to semantic references Use call stacks, class hierarchies, and source references rather than broad text search to orient the agent. That reduces unnecessary file reads and makes first-pass review more likely to succeed.
  • Gate dependency selection before merge Require the agent to justify any new library or package against vulnerability, licence, and supply-chain checks before code generation completes. Do not allow dependency review to wait until after the PR is open.
  • Measure retry-driven token waste Track output tokens, input-token growth, and PR iteration counts together so you can see where failed gates are creating cost escalation. Use the metrics to identify which projects need stronger context augmentation first.

Key takeaways

  • AI coding agents become materially easier to govern when they receive architectural and semantic context before they act.
  • Repeated PR failures are not just a cost problem, they are a signal that the agent's decision boundary is too loose.
  • Security teams should treat agent context, dependency choice, and review gating as a single control plane.

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, NIST CSF 2.0 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Agentic AI Top 10NHI-03Agent context and tool use are central to prompt and action governance.
NIST AI RMFGOVERNAI governance must define accountability for agentic coding decisions.
NIST CSF 2.0PR.AC-4Scoped access and least privilege apply when agents touch code and dependencies.
MITRE ATT&CKTA0002 , Execution; TA0006 , Credential AccessThe workflow can expose tool-use abuse and downstream compromise of trusted automation.
NIST SP 800-53 Rev 5AC-6Least privilege is relevant when AI agents are allowed to modify source and dependencies.

Map agent misuse scenarios to execution and credential access behaviours during threat modelling.


Key terms

  • Context Augmentation: Context augmentation is the practice of supplying an AI agent with the architectural, semantic, and policy information it needs before it acts. In coding workflows, that context reduces guesswork, lowers rework, and makes the agent's decisions more aligned with the codebase and governance rules already in place.
  • 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.
  • Agent-centric development cycle: A development pattern in which agents generate code while an independent layer verifies it before release. The model shifts trust from the author to the gate, which is especially important in environments where systems of record cannot absorb silent behavioural changes.

What's in the full article

Sonar's full analysis covers the operational detail this post intentionally leaves for the source:

  • A step-by-step look at Sonar Context Augmentation in Claude Code and the SonarQube CLI skill.
  • The exact quality-gate conditions used in SonarQube Cloud for reliability, security, maintainability, coverage, and duplication.
  • The full AC/DC framing for guide, verify, and solve stages in agentic development.
  • The token-cost math behind first-pass failures, retries, and annual spend across multiple teams.

👉 The full Sonar article covers the AC/DC workflow, token-cost calculations, and setup details for Claude Code and MCP-based use.

Deepen your knowledge

The NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, secrets management, and workload identity. It helps practitioners connect identity control principles to emerging agentic workflows and broader access governance.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 19, 2026.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org