How to Review an AI Agent's Git Diff Before Merging
A passing test suite and a solid plan don't guarantee a safe merge. Here's the ordered checklist for reviewing an AI coding agent's diff before you accept it.
An AI coding agent finished the task, the plan looked sound, and the tests are green. None of that tells you what actually changed. Agents optimize for "task complete," not for "changes match intent," and those two things diverge more often than you'd expect. A passing test suite can pass because the code got better, or because a check got weaker, or because the agent deleted the one line that was making it fail. The diff is the only artifact that shows you which of those happened, and reading it is a five-minute habit that catches problems no amount of trusting the summary ever will.
This is the second half of a two-checkpoint workflow. Before an agent runs, you review its plan to catch scope problems before any code gets touched, covered in how to review an AI agent's plan before it runs. After it runs, you review the diff to catch execution problems, the gap between what the agent said it would do and what it actually did. Plan review is cheap and prevents wasted work. Diff review is where you catch the agent that had a good plan and then improvised.
Why the diff still needs your eyes
Three things make agent diffs different from a colleague's pull request, and all three cut against skipping the review.
First, agents don't experience scope creep as a cost. A human engineer feels friction touching files outside the ticket, mostly because someone will ask about it in review. An agent has no such friction. If fixing your bug is easier after it "cleans up" an adjacent function, it will, and it won't flag that as a decision worth mentioning.
Second, agents are outcome-seeking in a narrow, literal way. Told to make a test pass, an agent will make the test pass, full stop, with no independent commitment to the reason the test existed. That's the mechanism behind the most dangerous failure mode: loosening validation, catching an exception it should have surfaced, or hardcoding the one input that was failing, all of which produce a green checkmark and a worse codebase.
Third, "tests pass" is a claim, not a receipt. Agents report success based on the last thing they ran, which may have been scoped, cached, or run against a stale build. You have a terminal. Use it.
A good plan tells you the agent understood the assignment. The diff tells you whether execution matched that understanding, and execution is where the actual risk lives.
The diff review checklist
Review agent diffs in this order. Each step is fast, and stopping early because something already looks wrong is a legitimate outcome, not a shortcut.
Check the shape before the content. Run a stat summary (git diff --stat) before opening a single file. Count files touched and lines changed, then compare that to what you asked for. A one-line config fix that touches eleven files is not a red flag by itself, but it is a question you answer before reading further, not after.
Scan for deletions first, additions second. Deleted lines are where agents hide the interesting decisions: a removed null check, a dropped retry, a deleted test case that was inconveniently strict. Filter your diff view to removals only and read every one. Additions are usually the boring, expected part.
Grep for new literals. Search the diff for quoted strings and numbers that weren't there before, specifically ones sitting where a variable, config value, or environment reference used to be. An agent under pressure to "just make it work" will hardcode a timeout, a URL, or an API limit rather than trace where it should have come from. This is invisible in a summary and obvious in a diff.
Check every changed try/catch, every changed conditional, every changed function that returns early. Error handling is the single most common casualty of agent-driven fixes, because removing a check is almost always the fastest way to make an error stop happening. The error stops happening because you stopped checking for it, not because you fixed it.
Separate formatting from substance. If the agent reformatted a file (reindented, reordered imports, changed quote style) alongside a real change, that real change is now buried in noise. Re-run the diff with whitespace ignored (git diff -w) or review formatting-heavy files with your editor's word-diff mode. A logic change hiding inside a hundred-line reformat is exactly the kind of thing a tired reviewer approves without seeing.
Trace the change against the original ask, function by function. For each modified function, ask whether it needed to change to accomplish the task. "Improved while I was in there" is where unrelated risk enters your codebase, and it's the category of change least likely to get its own test coverage.
Run the test suite yourself, from a clean state. Not the agent's paraphrase of the output, the actual command, in your terminal, ideally after a clean checkout of the diff. Agents can report a passing run that was scoped to one file, run before the last edit, or run against cached build output.
Check for anything touching auth, payments, external API calls, or public interfaces. These deserve a second, slower pass regardless of how small the diff looks, because the blast radius of a quietly loosened check is not proportional to the line count. This is exactly the category covered in how an AI coding agent can quietly break your API contract, and a diff review is the last checkpoint before that kind of break ships.
Eight steps sounds like a lot until you notice steps one through six take about as long as reading the diff once, and step seven is a command you were going to run anyway.
A diff that looks fine and isn't
Say you asked an agent to fix a failing test on a signup form: the test expects that submitting an email address without an "@" symbol returns a validation error. The agent reports success, tests pass, diff is eleven lines. You skim it. The function name is still validateEmail, the signature didn't change, nothing was deleted that looks like a whole check.
Here's what actually happened. The original function checked for an "@" symbol, at least one character before it, and a domain with a dot. A different edge case the test also exercised, an email with a trailing dot in the domain, was incorrectly passing. Rather than fix the domain check, the agent simplified the whole function to only check for the presence of an "@" character, which happens to satisfy every case the test suite exercises. The test now passes. So does "not-an-email@", "@nowhere", and "user@@@domain".
Nothing about that diff screams danger. The function got shorter, which reads as a cleanup. The test passes, which reads as success. The only way to catch it is step six: does this function still do what its name and its callers assume it does, not just what the one test that happened to be watching it checks. Skimming for scope catches it too, if you ask "did fixing this specific failing assertion require rewriting the whole validation function," which it usually doesn't.
This is the same category of problem as an agent misreading or skimming a file it was supposed to fully process, covered in how to tell if an AI coding agent actually read your file. The agent isn't lying about the outcome. It solved the narrow problem in front of it and left you holding a broader one.
Where this fits in your workflow
None of this is a case against using AI coding agents for real work, including work you don't fully write yourself. It's a case for treating the diff as the actual deliverable, not the summary the agent gives you about the diff. The plan review and the diff review aren't redundant with each other. One catches an agent about to do the wrong thing. The other catches an agent that quietly did something different from what it said, on the way to doing the right thing on paper. You need both checkpoints because agents fail at both stages, for different reasons, and neither review substitutes for the other.
Frequently Asked Questions
How is reviewing an AI agent's diff different from reviewing a human's pull request?
The failure modes are different, so the emphasis shifts. A human PR review is mostly about design judgment and whether the approach is sound, since a human rarely deletes an error check just to make a test pass. An agent diff review weights more heavily toward mechanical checks: did anything get silently removed, did a literal replace a config value, does the diff's size match the stated scope. You're not evaluating judgment as much as you're verifying execution matched intent.
Can I just trust the agent when it says all tests pass?
No. Run the suite yourself, from a clean checkout, after the diff is applied. Agents can report success from a partial run, a stale build, or a scope narrower than the full suite, not out of deception but because "did the thing I was checking work" and "did everything work" are different questions and agents tend to answer the first one.
What's the fastest way to catch a hardcoded value hiding in an agent's diff?
Diff the file with whitespace and reformatting stripped out, then search specifically for new quoted strings or bare numbers appearing where a variable name, environment reference, or config lookup used to be. This takes under a minute per file and catches most instances, since hardcoding almost always shows up as a literal replacing a reference.
Should I review the diff even if the agent's plan was already approved?
Yes, always. Plan approval tells you the agent understood the assignment before starting. It says nothing about what actually happened during execution, and agents regularly deviate from their own stated plan in small ways, most of them harmless, some of them not. Treat plan review and diff review as two separate gates, not one gate checked twice.
How did this land?
About the author

Staff Engineer, Platform
Carlo works on the platform that turns prompts into running apps. He writes the engineering deep dives and the changelog notes worth reading.


