Lesson 9 of 10 · Own the code AI writes
How to review code read the diff before you accept it
How to review code an AI wrote: read the diff, the lines it took out and the lines it put in, in Git, GitHub or Claude Code, with a checklist.
An AI tool can change twenty files in a minute. Accepting all of them because the app still loads is how almost-right code gets in. Reading the change before you accept it is how it stays out.
Developers call this code review, and on a good team nothing goes live without it. When you build with AI, you're the reviewer. This lesson is how to do it.
What is a diff?
A diff shows what changed between two versions of a file. Lines that start with - were taken out. Lines that start with + were put in. Lines with neither are there for context.
Here's an example. You asked the AI to fix a bug where some customers saw an error on their order page:
const order = await db.order.findUnique({
- where: { id, userId: user.id },
+ where: { id },
});
+ if (!order) {
+ return Response.json({ error: "Order not found" }, { status: 404 });
+ }
return Response.json(order);
The bug's fixed. Customers who saw an error now see their order. Read the line it took out, though: userId: user.id was the check that the order belonged to the person asking. It's gone. Now anyone can see anyone's order. That's lesson 5's most serious mistake, put in by a change that was meant to fix something else.
Nothing in the app would tell you. Only the diff does. The lines taken out are where the trouble hides, so read the - lines as carefully as the + ones.
Where to see a diff
In Git, on your own computer:
git status # which files changed
git diff # every changed line, not yet added
git diff --staged # the changes you've added with git add
Press Q to leave a long diff. New files don't show in git diff: git status lists them under "Untracked files", and you need to open and read each one.
In VS Code, the Source Control panel (the branching icon on the left) lists every changed file. Click one to see the old and new versions side by side. Most people find this easier than the terminal to start with.
On GitHub, a pull request has a "Files changed" tab with the same view, and you can leave comments on lines. It's worth using even if you work alone: push a branch, open a pull request, and read it there before you merge. If your site's on Vercel or Netlify, connected to GitHub, each branch can get its own preview address, so you can try the change before it goes live.
In Claude Code, there are a few ways in:
- In its Manual mode, Claude Code stops and asks before it edits files. In the VS Code extension, it shows the original and the proposed change side by side and asks for permission, and you can accept it, reject it, or tell Claude what to do instead.
- Shift+Tab cycles between permission modes. In
acceptEditsmode, Claude creates, edits, moves and deletes files in your project without asking. That's faster, and it means you review afterwards: Claude Code's docs suggest reviewing "in your editor or viagit diffafter the fact". /diffshows the changes in your project, including the edits Claude has made so far.- Plan mode asks Claude to research and propose changes without making them. For anything bigger than a small fix, read the plan before any code is written. Correcting a plan is much easier than correcting twenty files.
(Claude Code's docs on permission modes.)
How to review a change
Go through it in this order. It's quicker than reading top to bottom, and it catches more.
- Is it what you asked for? Read your request again, then read the list of changed files. Does each file belong in this change? A request to fix the order page shouldn't touch the login code.
- Is it small enough to read? If it isn't, don't read it. Throw it away (lesson 8 shows how) and ask for one part at a time. A diff you can't read is a diff you can't review.
- Check the files that matter most first. Anything to do with logins, payments, permissions or personal data. Then
package.json(new packages: are they real?),.envfiles, settings files, and tests. - Read the
-lines. What was taken out, and why? Checks, error handling and comments explaining something are the things that go missing. - Read the
+lines. For each new bit, ask what it assumes (lesson 3) and when it fails, who finds out. - Look for anything that shouldn't be there. A
console.log, a key typed into the code, a commented-out block, a "TODO". - Run it. Try the change, then try the unhappy path. Then commit, with a message that says what changed and why.
A code review checklist for AI-written changes
Keep this beside you:
- The change does what was asked, and nothing else
- Every changed file belongs in it
- No check was removed: logins, permissions, whose data it is, input checks
- No secret or key in the code, and nothing new starting
NEXT_PUBLIC_orVITE_that shouldn't - Any new package exists, is maintained and is the one you meant
- Errors are handled and someone finds out
- Tests weren't edited just to make them pass
- No leftover debugging code
- It works when you try it, including when things go wrong
Ask for a second opinion
AI is good at reviewing code, including its own, as long as you ask it to review rather than reassure. Give it the diff and ask: "Review this change as if a colleague wrote it. What could it break? What did it remove that might matter?"
Claude Code has a /code-review command that reviews your current changes for bugs. Use it, and treat what it finds as a second opinion, not the decision. You're still the person who accepts the change.
If you're on a team, the old rule still holds: nobody reviews their own code alone. Code an AI wrote for you counts as your code.
If you built something with AI
What to check
- Look at the last ten commits on your project (
git log --oneline, thengit showand a commit's ID). Can you say what each one changed? Pick the one you're least sure of and read its diff. - Check your AI tool's permission settings. Do you know when it edits without asking?
- Read the diff of the last change to anything involving logins, payments or personal data, and check no
-line removed a check. - Make sure you can see a preview of a change before it goes live, whether that's a preview address from your host or running it locally.
If you're learning the trade
Try it
Ask an AI to make three separate changes to the app you've been working on, committing after each one you accept:
- Something small: change some text and a colour.
- Something with data: add a field to a form and save it.
- Something you'd normally accept without reading: "tidy up this file" or "fix any bugs you can find".
For each one, review the diff with the checklist before you accept it. Write down anything you'd have missed if you'd just clicked accept. The third one is usually where you find something.