Why Code Review Is the Right Governance Layer for AI Agent Behavior Changes
Pull requests make agent prompts, permissions, and budgets inspectable before they run.

Agents-as-code means that AI agents are defined in YAML configuration files kept in a version-controlled repository, and changes are approved through pull requests. Those files describe prompts, tool permissions, model routing, budget caps, and retry limits. Code review is the right governance layer for agent behavior changes because it makes those changes inspectable, attributable, and subject to approval before they take effect, provided the execution infrastructure enforces the reviewed policy.
How AI coding agents turned the pull request into a governance artifact
AI coding agents read repositories, call tools, modify files across multiple paths, run tests, and open pull requests with minimal human direction. The resulting PR records the output of autonomous action, rather than only a human author's proposed implementation. That changes what approval needs to cover. A reviewer must assess both the proposed code and the authority under which the agent produced it.
The distinction is between suggestion and action. An agent that suggests code presents a review-quality problem, while one that calls shell commands, uses MCP tools, or changes cloud settings operates as a software actor with permissions. Its file accesses, commands, and API calls need to be attributable to a person or trigger. The PR becomes the first natural inspection point for its proposed changes and the record that connects those changes to the originating session.
Why agent behavior is expressed as code — and why that matters for governance
An agent's instructions, permissions, and proposed changes are expressed in artifacts that reviewers can inspect, including source files, CI/CD YAML, agent configuration, and tool permission manifests. A changed workflow trigger affects what runs, while a changed agent configuration can affect what the agent does in future sessions.
Configuration therefore needs to be checked as closely as executable code. StepSecurity described a .claude/settings.json SessionStart hook used in the 2026 supply-chain campaign as “effectively a postinstall for your editor”. The campaign put startup commands in hidden .claude/ and .vscode/ directories, so repository configuration became a way to run code. The Cloud Security Alliance called Mini Shai-Hulud the first supply-chain attack to weaponize AI coding agent configuration files as a persistence mechanism.
The relevant change was already a text artifact. A PR diff can expose a new hook, altered permission, or modified instruction without additional instrumentation to make that file change inspectable. Code review already has the right structure for governing behavior expressed through repository changes, while session telemetry supplies the evidence about execution.
What the incident record shows happens when no review gate exists on agent actions
In the PocketOS incident, an AI coding agent deleted the production database and all volume-level backups through a single API call to Railway. The data was later recovered, but the agent had credentials capable of destroying both production data and its backups. No review gate stood before that action. A reviewable representation of the planned tool call would have exposed its scope before execution, provided execution depended on approval.
Mini Shai-Hulud illustrates a different missing control. The attack propagated primarily through malicious npm and PyPI packages, while agent configuration files supplied persistence. Those files were not treated as artifacts requiring diff review, allowing the payload to move across repositories undetected. A mandatory policy applying secret scanning, static analysis, and human review to agent-modified configuration would have intersected that path, rather than treating configuration as incidental metadata.
Agent PRs need tool and session identifiers so security operations can trace a change to its originating session in the SIEM, and policy gates need to apply without pilot exemptions. GitGuardian's State of Secrets Sprawl 2026 found that Claude Code-assisted public commits leaked credentials more often than the baseline across public commits, reinforcing the need for mandatory secret scanning. Reconstructing a failure's blast radius comes too late. The review gate is the checkpoint before a proposed change or governed action takes effect.
The seven controls that code review enforces at the PR boundary
Attribution prevents autonomous changes from becoming ownerless records. Labeling every agent PR with its tool name and session ID connects file changes to a specific session and named human trigger. Without that connection, access reviews and offboarding cannot reliably establish whose authority the agent exercised.
Secret scanning keeps exposed credentials out of merged code. The infrastructure uses pre-receive hooks or required status checks to block changes when secrets are found. The agent cannot be its own enforcement mechanism.
SAST and license scanning prevent generated code from bypassing established security and legal policy. Agent-authored changes require the same static analysis as human-authored changes, together with checks against the organization's acceptable-license policy.
Configuration diff review prevents behavior changes from hiding in files treated as metadata. AGENTS.md, CLAUDE.md, settings.json, and CI/CD YAML are first-class governed artifacts because they influence instructions, execution, and permissions. Their filenames do not make their effects less consequential.
Reviewers need to see the budget and permission scope before they approve work, so they know its stated limits on resources and access. YAML budget caps and tool permission manifests expose those limits in the same diff as the behavior change. Reviewers can then judge whether the authority being requested fits the task.
Sandbox validation gives reviewers more than a reading of generated code to base their approval on. The PR provides a discrete event for provisioning an isolated preview environment and validating the proposed changes end-to-end before production.
The audit trail anchor prevents exceptions from becoming unaccountable bypasses. Every policy-gate override must be tied to a named role and logged against the PR. The approval record then connects the human decision to the agent session that produced the change.
How to manage agent YAML configuration in Git through pull requests
In the agents-as-code pattern, YAML or equivalent declarative files define prompts, tool permissions, model routing, budget caps, and retry limits beside the code they govern. A proposed change becomes a diff, the diff passes through PR review, and approval establishes the version permitted to run. The repository is therefore part of the control architecture.
Teams already use this pattern for CI/CD configuration. Workflow triggers, job definitions, and environment references go through review because changes to them change what runs. Agent definitions require the same treatment for the same reason. The configuration attacks described earlier showed the cost of leaving those files out of the usual engineering checks, which could cover them without a separate approval system.
A vendor dashboard or local configuration file sits outside that repository review loop. It may define the agent's behavior, but it does not provide a repository diff, review event, approval record, or standard version-control rollback for that change. The relevant platform criterion is therefore whether agent definitions can live as version-controlled files, as with Ellipsis, a managed cloud platform for running Claude Code and Codex in production that executes YAML agents checked into a repo in isolated sandboxes, and pass through mandatory review before execution. That criterion extends directly to cost, because a budget cap can be part of the same reviewed YAML definition.
Spend control as a reviewable artifact, not a post-hoc monitor
Agent spending needs a constraint before execution begins. Token consumption can expand as an agent broadens a task, enters recursive loops, over-queries connected systems, or re-sends conversation history on successive turns. A monitoring system can reveal the resulting spend, but it cannot reverse consumption that has already occurred. An alert is not an authorization boundary.
Uber illustrates the organizational consequence of that distinction. After access to Claude Code expanded across a large engineering population in December 2025, usage nearly doubled by February 2026. By April, the company had consumed its entire 2026 AI budget. Without pre-declared session or period caps, monitoring could detect the spend curve but could not constrain the consumption that produced it.
The engineering control is a set of YAML-declared limits. Separate caps cover tokens, model calls, tool calls, retries, and dollars, with checks at the run, step, and tool levels. A gateway enforces those constraints through pre-execution reservation. This separates the decision about acceptable spending from the agent's decisions while carrying out a task.
When that YAML lives in a version-controlled repository, a reviewer can compare the proposed limits with the task's scope before approving the change. A budget increase becomes a policy decision that is made openly and tracked by version, so it is visible when the budget changes. Caps held only in a dashboard or untracked environment variables cannot be inspected or audited at the PR boundary. Spend approval thus belongs in the engineering review that authorizes the agent's behavior.
What observability must feed back into the review process
Pre-merge review establishes what is permitted, but session evidence shows what happened. Every tool call, diff, and recorded reasoning step needs to be attributable to a person or trigger so reviewers can evaluate whether the approved policy held during execution. Outputs alone do not explain the path an agent took. Without that path, an approval record cannot support a complete account of the agent's conduct.
Records used for governance must be tamper-evident, hash-chained, and kept within the organization's own perimeter, so it has more than vendor-controlled logs to rely on. This supports defensible reconstruction when regulated data is involved. EU AI Act Article 12 addresses record-keeping for high-risk AI systems, including the technical ability to record events automatically over the system's lifetime.
Inventory methods built for server-side agents can miss coding agents on developer machines, even as they load tools and change configuration. OpenTelemetry stream listeners and network-layer analysis are needed to detect those agents and their activity.
Reviewers of future PRs from the same agent class need access to the tools called, files touched, and permissions exercised in earlier sessions alongside the current diff.
Running agents on managed infrastructure makes code review governance enforceable, not aspirational
A reviewed configuration has authority only if execution obeys it. Scoped credentials, mandatory PR gates, isolated sandboxes, budget enforcement, and tamper-evident logging need managed infrastructure that applies those controls consistently. Developer laptops and ungoverned CI cannot reliably provide that guarantee at scale. Otherwise, the repository records a policy that an agent may execute outside.
Enterprise infrastructure combines microVM sandbox isolation with a dedicated kernel per workload, SSO-mapped session identity, SIEM-connected audit logging, mandatory PR gates without pilot exemptions, and BYOC options for data residency. These controls connect the reviewed definition to an identifiable, isolated run. They also establish where records remain and how security operations can investigate them.
Credential scope is a decisive part of that connection. Managed infrastructure mints credentials for each session and revokes them on completion, rather than allowing the agent to inherit a developer's persistent access. Even a carefully maintained server-side inventory can miss what local agents do when they load MCP servers and call APIs with personal credentials. A later PR cannot retroactively authorize or contain those actions.
The practical test is whether an organization can reconstruct any session in its audit window. Its records must identify who triggered the run, which tools it called, which files it touched, what it spent, and which PR it produced, using logs retained within its own perimeter. That is the chain of custody behind a defensible approval. Code review becomes a governance layer when the approved diff governs execution and the execution record can be traced back to that approval.


