All posts
4 min read

How to Read a Diff: Reviewing What Your AI Tool Changed

A diff shows exactly what changed in your code: red lines removed, green lines added. How to read unified and side-by-side diffs, what the @@ lines mean, where to look them up in Git, VS Code, and GitHub, and a quick review routine for AI-generated changes.

getting startedtoolingAI agentsbeginner

When an AI tool changes your code, it will tell you what it did. The diff shows you what it actually did. Reading diffs is the single most useful review skill you can build when working with AI — and it's much easier than it looks.

What a diff is

A diff (short for difference) compares two versions of a file and shows only what changed. Lines that were removed are marked with - (usually red). Lines that were added are marked with + (usually green). Unchanged lines around them are shown for context.

Reading a unified diff

Here's a diff from the terminal:

diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 3f1a2c9..8b7d4e1 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -44,7 +44,10 @@ export function applyDiscount(cart: Cart, code: string) {
   const coupon = findCoupon(code)
-  const percent = coupon.percent
+  if (!coupon) {
+    throw new Error("Invalid discount code")
+  }
+  const percent = coupon.percent
   return {
     ...cart,
     total: cart.total * (1 - percent / 100),

Line by line:

  • diff --git a/… b/… — which file. a is the old version, b the new one.
  • --- / +++ — the old and new file.
  • @@ -44,7 +44,10 @@ — a hunk header: this section starts at line 44 and covered 7 lines in the old file; it starts at line 44 and covers 10 lines in the new one. The text after it is the function the change is in — a helpful hint.
  • Lines with no prefix — unchanged context.
  • - lines — removed.
  • + lines — added.

So this change adds a check: if the coupon doesn't exist, throw a clear error instead of crashing on coupon.percent. Note that const percent = coupon.percent appears as both removed and added — it moved down, and diffs show a moved line as a removal plus an addition.

Side-by-side view

Most tools can also show old and new side by side, with changes highlighted. It's easier for edits within a line. VS Code, GitHub, and most Git apps offer both views — use whichever reads better for the change.

Where to see diffs

In the terminal:

git diff              # changes not yet staged
git diff --staged     # changes staged for the next commit
git diff main         # everything different from the main branch
git show HEAD         # the last commit's changes

In Claude Code: /diff shows the changes in your working tree. (Claude Code Slash Commands.)

In VS Code: the Source Control view lists changed files; click one for a side-by-side diff. (VS Code for Beginners.)

On GitHub: a pull request's Files changed tab shows the diff for every file, and lets you comment on specific lines. (What Is a Pull Request?.)

A quick review routine for AI changes

You don't need to understand every line to review usefully. Look for these:

1. Which files changed?

Start with the list. Does it make sense for the task? If you asked for a button colour change and eight files changed — including your database schema — stop and ask why.

2. Anything deleted that shouldn't be?

Big red blocks deserve attention. AI tools sometimes "simplify" by removing code that handled an edge case, or delete a test that was failing instead of fixing the code.

3. Secrets or personal data?

Any API key, password, token, or real email address in green lines is a problem. (I Leaked an API Key. What Now?.)

4. New dependencies?

Check package.json and the lock file. Every new package should be one you recognise and need. (AI Hallucinated a Package.)

5. Security-sensitive areas?

Changes to authentication, permissions, payments, database queries, or anything with "admin" in it deserve a closer look — or a second opinion. (Review AI-Generated Pull Requests.)

6. Leftovers?

console.log lines, commented-out code, TODOs, and temporary test values.

7. Does it match the plan?

If the AI said "I added validation to the sign-up form," is that what the diff shows — and only that?

Making diffs easier to review

  • Ask for small changes. A 30-line diff is easy to review; a 3,000-line one is a leap of faith.
  • Commit often, so each diff covers one step. (How to Write Good Commit Messages.)
  • Use a formatter, so diffs show real changes, not whitespace churn. (Linters and Formatters Explained.)
  • Ask the AI to explain its diff: "Walk me through each change and why it was needed." Then check the explanation against the diff.

EasySpawn connects each workspace to GitHub, so Claude Code's changes arrive as branches and pull requests you can review as diffs — file by file, line by line — before anything goes live. See how it works or join the waitlist.

Related: Review AI-Generated Pull Requests · Git Branches Explained · Merge Conflicts Explained

Keep reading