Skip to content
01Home 02Capability Matrix 03Tools 04Benchmark Rankings 05Tracks 06About Us
Code Under Repair · AI coverage organised as a matrix of capability × stage. Not sorted by tool, but by where you are right now.
Updated every Wednesday

How to Review and Verify Code Written by an AI Coding Agent

Learn how to review and verify AI-generated code with practical Git diff checks, logic reviews, edge-case tests, and security checks before merging.

Nov 12, 2026
How to Review and Verify Code Written by an AI Coding Agent Debugging & Code Review

AI-generated code can look clean, follow the project's formatting rules, and even pass a basic test while still containing bugs. That is why I would never treat an AI coding agent's final message as proof that a change is ready to merge.

A reliable review has to answer three questions: Did the agent change the right things? Does the code behave correctly? Have the important failure cases been checked? You need to inspect the actual diff, trace the logic, run relevant tests, and verify that the change has not broken existing behavior.

This guide walks through that process using a small JavaScript example. The same principles apply when reviewing Python, TypeScript, backend APIs, frontend components, and larger changes made by tools such as Claude Code, Codex, or Cursor.


Table of Contents

  • Why AI-Generated Code Needs a Real Review

  • Step 1: Inspect the Git Diff Before Reading the Explanation

  • Step 2: Check Whether the Code Actually Does What You Asked

  • Step 3: Test Edge Cases, Not Just the Happy Path

  • Step 4: Run the Project's Existing Checks

  • Step 5: Review Security, Dependencies, and Side Effects

  • A Practical AI Code Review Checklist


Why AI-Generated Code Needs a Real Review

An AI coding agent can produce a plausible implementation very quickly. But plausible is not the same as correct.

For example, imagine asking an agent to add a discount calculation function to an online store. It might generate a function that works for a normal order total of $100 and a 10% discount. But what happens if the total is negative, the discount is greater than 100%, or the input is missing?

These cases matter because real applications receive unexpected input. A function that works only with the example in the prompt is not necessarily ready for production.

I use five review layers:

  1. Scope: Did the agent modify only the files needed for the task?

  2. Logic: Does the implementation satisfy the actual requirements?

  3. Testing: Have normal, boundary, and failure cases been checked?

  4. Compatibility: Does the change fit the existing application?

  5. Safety: Did it introduce security, dependency, or data-handling risks?

You do not need an elaborate review process for every one-line change. But when an agent touches shared services, authentication, payments, database operations, or public APIs, skipping these checks is an expensive shortcut.


Step 1: Inspect the Git Diff Before Reading the Explanation

Start with the actual changes, not the agent's summary. A summary tells you what the agent believes it did. The diff shows what it really changed.

If you use Git, run:

git status --short
git diff --stat
git diff

These commands answer three basic questions:

  • git status --short shows which files have changed.

  • git diff --stat gives you a quick overview of the size of the changes.

  • git diff shows the actual line-by-line modifications.

For a new file that Git has not started tracking, inspect it separately. Also check staged changes with git diff --cached if the agent or your workflow has already staged files.

Git diff showing AI-generated code changes

When reading the diff, look for changes that do not belong to the task. Did the agent reformat an unrelated file? Did it update a package version? Did it modify environment configuration? Did it replace an existing helper instead of reusing it?

A large diff is not automatically bad, but every additional change increases the amount of code you need to understand. If you find unrelated modifications, ask the agent to explain them before accepting the work.

Practical rule: Never approve a change just because the agent says it modified only two files. Confirm that statement in Git.


Step 2: Check Whether the Code Actually Does What You Asked

Next, trace the implementation against the original requirement. Do not review code only by asking whether it looks reasonable. Ask whether it produces the required behavior.

Consider this example of a discount function:

function calculateDiscount(total, discountPercent) {
  return total - total * discountPercent / 100;
}

For a total of 100 and a discount of 10, the result is 90. That looks correct. But the function does not define what should happen with invalid inputs or an excessive discount.

A more defensive implementation might be:

function calculateDiscount(total, discountPercent) {
  if (!Number.isFinite(total) || total < 0) {
    throw new Error("Invalid order total");
  }

  if (
    !Number.isFinite(discountPercent) ||
    discountPercent < 0 ||
    discountPercent > 100
  ) {
    throw new Error("Invalid discount percentage");
  }

  const discountedTotal =
    total * (1 - discountPercent / 100);

  return Math.round((discountedTotal + Number.EPSILON) * 100) / 100;
}

This version defines input boundaries and rounds the result to two decimal places. Whether this is the right implementation still depends on the application. A store may have specific currency, tax, and rounding rules that should be followed instead of introducing a new convention.

That is the point of reviewing the surrounding code: the correct implementation is the one that satisfies the requirement and fits the project's existing rules, not simply the one that looks more sophisticated.

While reading a changed function, ask:

  • Are all inputs validated at the correct boundary?

  • Are return values in the format expected by callers?

  • Are errors handled consistently with the rest of the project?

  • Does the code duplicate logic that already exists elsewhere?

  • Could this change break another function that depends on it?


Step 3: Test Edge Cases, Not Just the Happy Path

A common weakness in AI-generated code is that the implementation and its tests focus on the same obvious example. If both are based on the same incomplete assumption, the tests may pass without proving much.

For the discount function, start with a small test matrix:

Input

Expected result

What it checks

(100, 10)

90

Normal calculation

(100, 0)

100

No discount

(100, 100)

0

Maximum discount

(-10, 10)

Error

Negative total

(100, 120)

Error

Invalid percentage

(100, NaN)

Error

Non-finite input

Then turn those cases into automated tests. Here is a simple example using Jest:

describe("calculateDiscount", () => {
  test("calculates a normal discount", () => {
    expect(calculateDiscount(100, 10)).toBe(90);
  });

  test("returns the original total for zero discount", () => {
    expect(calculateDiscount(100, 0)).toBe(100);
  });

  test("rejects a negative total", () => {
    expect(() => calculateDiscount(-10, 10))
      .toThrow("Invalid order total");
  });

  test("rejects a discount above 100 percent", () => {
    expect(() => calculateDiscount(100, 120))
      .toThrow("Invalid discount percentage");
  });
});

Adapt the syntax to the test framework already used by your project. Also add tests for important decimal and rounding cases if the function handles real currency.

JavaScript unit tests for AI-generated code

For larger features, test both sides of the behavior. If an API endpoint should allow an authorized user and reject an unauthorized one, test both requests. If a form should accept valid input, also test missing and malformed input.

Do not let the agent choose only the easiest test cases. Compare its tests with the acceptance criteria you defined before implementation.


Step 4: Run the Project's Existing Checks

Unit tests are only one part of verification. A change can pass its own tests and still fail type checking, linting, integration tests, or the production build.

First, inspect the project's available scripts. In a Node.js project, you can check:

cat package.json

Then run the relevant commands. A project might use:

npm run test
npm run lint
npm run typecheck
npm run build

These commands are examples, not universal requirements. Use the scripts defined by the repository. If a command does not exist, do not report it as passed.

Pay attention to the difference between a successful command and a successful feature. A build proves that the application can be built under that environment. It does not prove that the new behavior is correct.

Record what actually ran, what passed, and what could not be tested. If a test fails, determine whether the failure was introduced by the change or already existed. Do not ask the agent to silence a failing test simply to get a green result.


Step 5: Review Security, Dependencies, and Side Effects

Before accepting the change, look beyond the main function. AI-generated code can introduce risks that ordinary happy-path tests will not catch.

For example, check whether the agent:

  • Added a package that the feature does not really need.

  • Exposed API keys, tokens, or other secrets in source code.

  • Trusted user input without appropriate validation.

  • Changed database queries or permissions in an unsafe way.

  • Logged personal information or sensitive request data.

  • Changed shared configuration or environment assumptions.

Review dependency changes in particular:

git diff -- package.json package-lock.json

Ask why each new dependency is necessary, whether the project already has an equivalent library, and whether the package is appropriate for the application's environment.

For database or API changes, also consider backward compatibility. Existing clients, stored records, and background jobs may depend on the old behavior even if the new implementation works in isolation.


A Practical AI Code Review Checklist

Before merging an AI-generated change, use this checklist:

  • Inspect all changed and untracked files.

  • Confirm that every modification belongs to the requested task.

  • Compare the implementation with the original acceptance criteria.

  • Check input validation, error handling, and boundary conditions.

  • Review tests for normal, edge, and failure cases.

  • Run relevant tests, linting, type checks, and build commands.

  • Review dependency, configuration, security, and data changes.

  • Confirm that unresolved failures and limitations are documented.

You can also ask the agent to provide a review report, but treat it as a second opinion rather than independent proof. You still need to inspect the code and test results yourself.


Conclusion: Verify the Code, Not the Agent's Confidence

The most important habit when working with AI coding agents is to separate implementation from verification. An agent can write the code and explain its decisions, but those explanations do not replace a Git diff, meaningful tests, or a review of the surrounding application.

Start with the changed files, trace the logic against the requirements, test boundary conditions, and run the checks your project actually supports. For sensitive or high-impact changes, spend extra time on security, compatibility, and side effects.

AI can make implementation faster. A disciplined review process is what makes those faster changes dependable.

Build it. Break it. Understand it. Fix it.

Reader responses

No responses on this piece yet.

Write what you observed