How to Read a Diff from an AI Agent: First Review Habits
The diff is the only honest summary of what an agent did. The agent's own message says what it intended; the diff shows what actually changed. Reading it well takes a few minutes and catches most problems: edits to the wrong files, deleted code, stray debugging output and logic that does not match what you asked. Make the diff your first stop every time, before you run anything else.
Start with the shape, not the lines
Before reading any code, look at which files changed and how much. Unexpected files are the fastest warning sign.
git status --short
git diff --stat
A typical output looks like this:
M src/users.js
M test/users.test.js
?? src/utils/validate.js
src/users.js | 14 ++++++++++++--
test/users.test.js | 31 +++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 2 deletions(-)
Ask: is this the set of files I expected? Does the size fit the task? A one-line request that touched twelve files deserves suspicion. Note that git diff does not show new untracked files; the ?? line in git status reveals them, so read those files separately or run git add -N on them first so they appear in the diff.
git add -N . # mark new files so git diff includes them (intent to add)
git diff
Then read for four things
1. Does it do what I asked?
Hold your original prompt next to the code. Check each requirement, including the edge cases you mentioned. Agents sometimes solve a slightly different problem that is easier.
2. What was removed?
Look at the red lines as carefully as the green ones. Deleted checks, removed error handling or a deleted test are the most dangerous changes, and they are easy to skim past.
3. What was added that I did not ask for?
Extra helpers, new dependencies, reformatting of untouched code, renamed variables and added comments all inflate review work. Ask the agent to revert unrelated changes, or revert them yourself with git restore -p which lets you choose hunks interactively.
git restore -p src/users.js # step through each hunk: y = discard, n = keep
4. Is anything left behind?
Search the diff for leftovers: console.log, print(, debugger, commented-out code, task-marker comments, hard-coded paths and test-only values.
git diff | grep -nE "console\.log|debugger|HACK|FIXME|print\("
Read tests with extra care
When tests are in the diff, check that they assert real behaviour. A test that only checks the function does not throw, or one that compares the output to itself, passes but proves nothing. Temporarily break the implementation and confirm the new test fails. A later post covers reviewing agent-written tests in depth.
Run the checks yourself
Even if the agent says tests passed, run them. It costs seconds and removes doubt about what ran, in what order and against what state.
Review in small pieces
If the diff is too large to hold in your head, that is a signal about the task, not about your attention. Ask the agent to split the work into smaller commits, or revert and redo it in steps. Reviewing three small diffs is faster and safer than one big one.
Reviewing agent output is a different skill from reviewing a colleague's pull request. A colleague usually works from shared context and tends to make mistakes you can predict. An agent can be brilliant in one hunk and subtly wrong in the next, with the same confident tone throughout. Do not let a clean, well-commented diff lower your guard. Fluent code is not the same as correct code. Review the logic as if you were the one who had to debug it at night, and pay extra attention to boundary conditions such as empty lists, null values, time zones and off-by-one errors, which are common places for small mistakes to hide.
A five-minute review routine
- Run
git statusandgit diff --stat; confirm the files and size. - Read the diff top to bottom; compare to your prompt.
- Look at deletions; justify each one.
- Search for debug leftovers.
- Run the full check command yourself.
- Ask the agent to explain anything you do not understand. If it cannot explain it clearly, do not merge it.
That last rule is the most important. You own the code that you commit, however it was written.
Comments
No comments yet. Have a question or a tip? Be the first to share it.