How to Review AI-Generated Code Before It Ships
Reviewing AI-generated code starts with the intended behavior, the actual diff, and evidence that the two match. A confident agent summary is useful navigation, but it is not proof. The practical challenge is allocating human attention: an authorization change deserves different scrutiny from a label correction. This guide proposes a review sequence that catches expensive mistakes early and leaves a clear decision record for the next developer.
AI-assisted technical guide with linked primary sources. Examples are illustrative unless stated otherwise. How these guides are made.
Start with a review contract and a stable revision
Before opening individual files, write down the trigger, expected result, prohibited side effects, and revision being reviewed. For a password-reset change, that might mean: an expired link cannot reset a password, valid links still work, tokens never appear in logs, and the session policy stays unchanged. These statements create something you can challenge with evidence.
Ask the agent for changed files, commands actually run, failures encountered, and remaining uncertainties. Separate reported facts from proposals. “Added coverage” means a test exists; “the new regression test failed before the fix and passed afterward” describes stronger evidence, if the run can be inspected. Require the relevant revision or commit for each result. A test run against yesterday’s diff cannot certify today’s changes.
GitHub’s responsible-use guidance for Copilot agents emphasizes human oversight and review of outputs. Apply that principle to the whole workflow: an additional automated reviewer can find candidates for investigation, while a person owns the release decision.
Map the diff before reviewing individual lines
Begin with the shape of the change. Which subsystems moved? Were dependencies, migrations, configuration, generated files, or permission rules changed unexpectedly? A short bug fix with a large formatting sweep makes the meaningful changes harder to identify. Ask for a focused revision when unrelated churn blocks understanding.
git status --short
git diff --stat main...HEAD
git diff --name-status main...HEAD
git diff --check main...HEAD
git diff main...HEAD -- src/auth
These example commands assume the target branch is main and the proposed changes are committed. In Git’s diff documentation, the three-dot form compares the merge base with the second endpoint. That is useful for branch changes; it does not include uncommitted edits. Inspect those separately with git diff, git diff --cached, and the untracked-file list from status.
Also compare the proposed result with the current target branch when it has advanced. The integration result can differ from the branch-only diff. A clean merge says Git reconciled text; it says nothing about two features agreeing on an API contract.
Order the review by failure impact
Use the following order as a suggested triage pattern. Adjust it for your system rather than treating it as a universal severity score.
| Change area | Question to answer first | Evidence to request |
|---|---|---|
| Identity and permissions | Can one actor affect another actor’s data? | Negative authorization cases |
| Data mutations | Can retries duplicate or corrupt a write? | Transaction and retry behavior |
| External effects | Can a failure send, charge, or delete twice? | Idempotency and recovery design |
| Concurrency | Can two valid requests violate an invariant? | Interleaving analysis and targeted checks |
| Presentation | Can a user understand and complete the task? | Rendered interaction checks |
Read the surrounding implementation and its callers. Generated code can look locally reasonable while violating a repository convention: bypassing an established transaction helper, swallowing cancellation, or returning an error shape that callers cannot interpret. When the change crosses a specialist boundary, bring in an appropriate reviewer. Do not convert lack of expertise into an approval.
Worked example: an export endpoint that passes the happy path
Suppose an agent adds GET /projects/:id/export. The implementation fetches a project by identifier, serializes its records, and returns a file. A test creates a project and checks that its owner receives a download. Everything passes.
The review starts with the invariant: a caller must have export permission for the requested project. Trace where the caller identity originates and where that identity constrains the database query or authorization decision. Checking only that a user is logged in does not establish access to the requested project.
Build a small behavior matrix: owner allowed; unrelated authenticated user denied; anonymous request denied; deleted project handled consistently; user with read access but no export permission handled according to policy. Use the application’s defined error contract rather than inventing whether every denial must be 403 or 404. Confirm the denied response contains no project records or sensitive metadata.
Then inspect serialization: does the export include internal notes, tokens, or fields excluded from the ordinary API? Check that permission is evaluated before expensive data retrieval or external effects where practical. Finally, examine a second request arriving while permissions change. The appropriate consistency guarantees depend on your architecture; make the assumption explicit. This scenario is an illustrative review exercise, not a reported vulnerability or a tested result.
Check whether tests could catch the intended mistake
A test can mirror an implementation so closely that both share the same wrong assumption. For the export example, mocking the authorization function to always return true proves little about tenant separation. Prefer at least one check that exercises the actual permission boundary with two distinct users and projects.
Google’s code-review guidance asks reviewers to assess design, edge cases, and whether tests will fail when behavior breaks. Turn that into concrete questions: what assertion fails if the permission check is removed? Does the fixture contain data that would expose a leak? Is the expected result computed independently of the production helper?
Read the test command and output. Distinguish a targeted regression check from the full relevant suite, and a skipped test from a passing test. Investigate flaky failures instead of rerunning until green and omitting the history. For user-facing changes, exercise the rendered interaction; a snapshot alone cannot establish keyboard behavior or a successful download.
Review dependency changes before installing or running them
Treat new packages and lockfile churn as part of the implementation. Why is the dependency needed? Does the project already have a suitable utility? Check the package identity, selected version, license requirements, transitive additions, and install scripts. An unfamiliar command in an agent summary deserves inspection before execution.
GitHub’s dependency review documentation explains how pull-request review can expose direct and indirect dependency changes and known vulnerability information. Such signals complement code review; absence of a known advisory does not prove a package is trustworthy.
For an npm project, the npm ci documentation describes a clean install that requires a lockfile and fails on a manifest/lockfile mismatch rather than updating the lockfile. Use it in an appropriate isolated review environment after inspecting scripts and configuration. It can execute lifecycle scripts and replace the existing dependency directory, so it is not a harmless read-only inspection command.
Finish with an explicit decision and verification record
Use this checklist before approval:
- The diff matches the agreed behavior and scope.
- Authorization, mutations, retries, and external effects have been considered where relevant.
- Regression checks exercise the meaningful boundary.
- Dependencies and configuration changes are explained.
- Verification results identify the reviewed revision and remaining limits.
- Any migration, rollout, and recovery assumptions have an owner.
Describe blocking findings with a trigger and consequence: “An unrelated signed-in user can request another project’s export because the query only filters by project ID.” That is more actionable than “security issue.” After a fix, inspect the new diff and rerun the affected checks. An earlier approval should not silently cover later material changes.
Keep optional style suggestions separate from behavior blockers. Small, focused changes are easier to understand, but line count alone is a poor risk measure: one changed permission condition can matter more than hundreds of mechanical edits.
Keep waiting agent sessions visible while you review
When several local coding agents run at once, visibility helps you notice which session needs a decision. Purrvio’s Mac preview shows supported local agent sessions from the notch, with the richest support for Claude Code and Codex. It can help you return to the relevant session instead of searching terminal tabs.
Use that signal to start a review, then inspect the diff and verification evidence yourself. Purrvio is a session companion, not a code-quality gate or a substitute for CI. The free preview supports macOS 13 or later on Intel and Apple silicon; it is locally signed and is not Apple-notarized. Download Purrvio and read the installation notes if local session visibility fits your workflow.
Frequently asked questions
Should a second AI agent review the first agent’s code?
It can provide an additional pass, especially when given explicit invariants and a focused diff. Treat its findings as claims to verify. Two agents can share the same assumptions, so an independent human decision and meaningful behavioral checks remain necessary.
Is a passing test suite enough to approve generated code?
No single signal establishes correctness. Check that relevant tests ran against the reviewed revision, that assertions cover the intended behavior, and that risk areas outside the suite have been examined. A suite can pass while missing an authorization case or migration failure.
How much review does a small generated change need?
Scale review to consequences and uncertainty. A copy edit may need a rendered check; a small authorization edit can need negative cases and specialist review. Keep the scope focused so the required evidence is easy to assess.
Sources and further reading
Primary references checked for this guide on 10 November 2026. Documentation can change; confirm version-specific behavior before using commands in a production workflow.
- Git diff documentation
Primary reference for branch comparison syntax and diff inspection options.
- Google: What to look for in a code review
Primary engineering guidance on design, behavior, context, and test quality.
- GitHub Copilot Agents responsible use
Primary product guidance on human oversight and reviewing agent outputs.
- GitHub dependency review
Primary documentation for dependency-change visibility and known vulnerability information.
- npm ci documentation
Primary reference for clean installs, lockfile mismatch behavior, and lifecycle script configuration.