How to review AI-generated code: a practical routine
Six steps, in the same order every time, to catch what AI coding agents get wrong before it reaches your main branch.

Key takeaways
- Compare the change to a one-sentence statement of what you asked for.
- Check which files changed before reading any of them; edited tests are a red flag.
- Read the real diff for invented APIs, swallowed errors and leftover stubs.
- Run it yourself and break a test on purpose to see whether the tests catch it.
- Finish with a five-minute security pass on secrets, input, access and new packages.
To review AI-generated code, treat it like a pull request from a fast, confident new teammate: check that it does what you asked and nothing more, read every changed line, run it, test the edges, and do a short security pass before you commit. The routine below takes ten to twenty minutes for a typical change and catches the mistakes AI agents make most often.
AI coding tools are good at producing code that looks finished. That is exactly why a fixed review order helps: it stops you from approving something because it reads well.
1. Restate what you asked for
Before you open a single file, write one sentence: what should be different after this change? "The sign-up form rejects emails without a dot in the domain, and there is a test for it." Then ask the agent for its own summary of what it did and compare the two.
Gaps show up fast. The agent may have solved a neighbouring problem, added a feature you never asked for, or quietly decided part of the task was out of scope. Catching that now saves reading code that should not exist.
2. Check the scope of the change
Next, see which files changed and by how much. In a Git project:
git status
git diff --stat
Look for surprises:
- Files you did not expect. A one-line bug fix that touches eleven files deserves a question.
- Changed lockfiles or config. A new dependency, a changed build setting or an edited
.env.exampleneeds a reason. - Deleted or edited tests. An agent under pressure to make tests pass sometimes changes the test instead of the code. Treat any change to a test file as a red flag until you have read it.
- Generated files. Build output or minified bundles in the diff usually mean something should be in
.gitignore.
3. Read the diff, line by line
Read the actual change with git diff or your editor's diff view, not the agent's description of it. These are the patterns that show up again and again in AI-written code:
- Invented APIs. A method, option or package that does not exist, written with total confidence. If you do not recognise a call, look it up in the library's docs.
- Swallowed errors. A
tryblock with an empty or logging-onlycatch, which makes failures silent. - Hard-coded values. Test data, sample URLs, magic numbers or a fixed date that only works today.
- Stubs left behind.
TODO, placeholder text, or a function that returns a fixed value "for now". - Duplicates. A new helper that does what an existing one already does, under a slightly different name.
- Over-building. Extra abstraction layers, options and settings nobody asked for. Smaller is easier to maintain.
Leave comments as you go, then send them back in one message. Concrete notes ("line 42: this catches the error and returns null, the caller never finds out") get much better fixes than "please clean this up".

4. Run it, then try to break it
An agent saying "I tested it" is a claim, not evidence. Run the app or the script yourself and use the feature the way a real person would. Then do what a real person does by accident:
- Submit an empty form, a very long value, emoji, or text pasted with line breaks.
- Click the button twice quickly. Refresh in the middle of a save.
- Open the page at phone width.
- Turn off the network and see what the user is told.
For web projects, also open the browser console. New warnings or errors after a change are worth a look even when the page seems fine.
5. Check that the tests actually test something
AI agents write tests readily, and a green test run feels reassuring. Read at least one new test fully. Common weak spots:
- Assertions that would pass no matter what, such as checking that a function returned "something".
- Mocks so broad that the real code never runs.
- Only the happy path, with no test for bad input or a failed request.
A quick check that works well: break the code on purpose (flip a condition, return early) and run the tests. If they still pass, they are not protecting you. When you ask for a bug fix, ask for a failing test first, then the fix that makes it pass.
6. Do a short security pass
You do not need to be a security expert to catch the common problems. Five minutes on these questions covers most of them:
| Check | What to look for |
|---|---|
| Secrets | API keys, tokens or passwords in code, config or test files |
| Input | User input that reaches a database query, a shell command or a page without validation or escaping |
| Access | New routes or functions that skip the existing sign-in or permission check |
| Dependencies | New packages: confirm each one exists, is the one you meant, and is maintained |
| Data exposure | Error messages or logs that print personal data or internal details |
The dependency check matters more with AI than with human code. Models sometimes suggest package names that sound right but do not exist, and an attacker can register such a name. Run your package manager's audit (for example npm audit) and look each new package up on its registry page. Our security checklist for AI-built apps covers the pre-launch version of this.
Get a second opinion from a different model
One cheap upgrade: ask a different model to review the diff, with no access to the original chat. A fresh reviewer has no stake in the code it is reading and tends to catch things the author's context hides. Give it the diff and your one-sentence goal from step 1, and ask for problems only, ordered by severity. Still read its findings critically; a reviewer model can be wrong too.
Commit with a message a person can use
Once it passes, commit in a small unit with a message that says what changed and why. If the change turns out to be wrong next week, a clean commit is what lets you take it back in one step; see how to undo AI code changes.
Reviewing in Ninja Builder
In Ninja Builder, every reply that changed files ends with a small card such as "3 files changed +42 −7 · Review". It opens exactly what that reply did, file by file, with the changed words highlighted. You can keep or undo each file, click a line to leave a comment, and send all your comments back to the agent as one message. A Second-AI check has a different model re-check important claims before work is reported as done, and the Git panel handles staging and commits; see the Git panel docs and chatting with the builder.

It runs on Mac, Windows and Linux with Claude, ChatGPT, Gemini, GitHub Copilot, Cursor or a local model. Download Ninja Builder to try it free for 14 days.
Frequently asked questions
Should I trust tests written by the AI?
Read at least one of them fully. Break the code on purpose and run the suite; if the tests still pass, they are not checking the behaviour you care about.
How long should reviewing an AI change take?
For a typical small feature or fix, ten to twenty minutes with a fixed routine. Large changes are a sign the task should have been split into smaller pieces.
Can another AI review the code for me?
A different model reviewing the diff without the original chat often finds real problems, so it is a useful extra step. It does not replace running the code and reading the risky parts yourself.
What are the most common mistakes in AI-generated code?
Calls to functions or packages that do not exist, errors caught and ignored, hard-coded test values, leftover placeholders, duplicated helpers, and tests edited to pass.
Keep reading

How to undo AI code changes: checkpoints, rewind and Git
Three layers of undo for AI edits, from one file to a full Git restore, with the exact commands.

Security Checklist for AI-Built Apps: What to Check Before Launch
Six checks that catch the usual leaks in AI-written apps, written so you can run them without reading code.

How to prompt AI coding agents: examples that work
The four parts of a prompt a coding agent can act on, with before-and-after examples for a bug fix and a feature.