Skip to content
stacks

How to review code a coding agent wrote

Review AI-generated code in four passes: what ran and what it counted, files outside the feature, new dependencies, then the logic. Commands included.

Published 5 min read

To review AI-generated code, check the evidence before you read the logic: which commands ran and how many checks they counted, then which files changed outside the feature, then any new dependency, and only then the code itself. A skipped test, an edited config and an unwanted package can all hide outside the diff's main hunk, and a tidy diff doesn't show them.

How do I review AI-generated code? Pass 1: what ran, and how many checks counted

Ask the agent for the exact command it ran and the pass, fail and skip counts. Then read the counts. An exit code of 0 is compatible with nothing having run: a -t filter that matches no test in Vitest exits 0 with every test skipped, and some runners finish with zero tests and no error when they're pointed at the wrong directory.

The count is what separates a real pass from an empty one. Compare the number of tests with the last run on the base branch. A suite that went from 212 tests to 190 needs an explanation before you review anything else, even when every remaining test passes.

stacks prints the counts on its first line, which makes this pass quick when a project uses it:

stacks verify --all, trimmed
verify: failed (full run; 2 passed, 2 failed, 0 skipped; 0.4s)

  failed   check     agents-md-filled          (exit 1, 0.0s)  exited with status 1
  failed   check     claude-readme-filled      (exit 1, 0.0s)  exited with status 1

The same output shows what ran, what failed and what was skipped. If a run reports 0 passed or a nonzero skip count you didn't expect, find out why before you accept a green result.

Pass 2: which files changed that the feature didn't need?

List every changed file, including new ones, which a plain git diff leaves out:

Terminal
git status --short
git diff --stat main...HEAD

Replace main with your base branch. Then read the changes to the files that define what passing means, whatever the feature was:

Terminal
git diff main...HEAD -- package.json '*.config.*' '.github/**' 'tests/**'

A changed test script, a lowered coverage threshold, a new lint ignore, a test that gained .skip, or an edited CI workflow each change what "green" means. An agent working toward a passing run has every reason to touch them, and sometimes the change is legitimate. What you need is an explanation tied to the task. How to stop Claude Code from changing tests covers blocking those edits up front.

Pass 3: is every new dependency real and wanted?

Check that each new package exists and is the one you meant. Models sometimes invent plausible package names, and an attacker can register a name an agent is likely to guess. Look at each new entry in the manifest diff, and at the lockfile diff for what came along with it.

Terminal
npm view some-package version time.created

That prints the latest version and when the package was first published. A package created last month with a name resembling a well-known one deserves a look at its repository and publisher. A package that exists can still be one you don't want, such as a second HTTP client in a project that already has one. Prefer what the project already uses, and ask the agent why it added the new one.

Pass 4: read the logic where tests can't see

Spend your attention on the code where a mistake costs the most and a test is least likely to notice: input parsing, authorization checks, anything that deletes or sends money, retry and error paths, and code that runs concurrently. Skim the rest. For security, look for secrets written into files, user input that reaches a query or a shell command unescaped, and permission checks that were skipped.

Agents also call functions that don't exist, or that existed in an older release of a library. A typechecker catches many of these, so confirm the type check ran. Calls into untyped code and shell commands need a manual look.

Read the tests the agent wrote with the same suspicion. A test that builds its expected value by calling the function under test can't fail. To see whether a test checks anything, break the implementation on purpose, run it, and confirm it goes red before you restore the code. A test that stays green is decoration.

Make the first pass automatic

Passes 1 and 2 are mechanical, so write the definition of done down before the agent starts and let a tool check it. That means a list of commands that must pass, recorded somewhere a change gets noticed.

That's what stacks records. stacks new writes .stacks/manifest.json, which lists the project's verify steps. stacks verify runs those steps and reports green, partial, failed or changed. It compares the steps with a copy recorded outside the project and refuses to run when they differ, so an agent that edited a step to get a pass gets changed and an exit code of 5 instead of a green result. stacks runs summarizes the history: the number of verify runs, the last outcome, the minutes to the first green run, and the interventions, which counts the questions the agent asked you along the way. The verify documentation explains the outcomes and the tamper check.

A green verify proves that the declared checks pass and doesn't judge whether the code is good. Passes 3 and 4 need your judgment. A pull request template can hold the human half:

.github/pull_request_template.md
- [ ] Paste the verify or test command and its counts
- [ ] Changes to test, CI or lint config are explained
- [ ] Every new dependency was checked on the registry
- [ ] I read the code that handles input, auth, deletes and errors
Agent + stacks
Demo

You: Check the greeting change before you call it done.

Agent: I’ll run the full recorded checks.

●Bash(stacks verify)
verify: failed (full run; 8 passed, 1 failed, 0 skipped; 10.9s)
failed check test (exit 2, 1.2s) exited with status 2
| expected: "Hello, world!"
| actual : "Hi!"
Output abbreviated
●Bash(cat internal/config/config.go)
v := viper.New()
v.SetDefault("greeting", "Hi!")
v.SetDefault("json", false)
Output abbreviated

Agent: The tests expect Hello, world!, but the default is Hi!. I’ll restore the default in the code.

●Bash(sed -i '' 's/SetDefault("greeting", "Hi!")/SetDefault("greeting", "Hello, world!")/' internal/config/config.go)
●Bash(stacks verify)
verify: green (full run; 9 passed, 0 failed, 0 skipped; 5.7s)
Output abbreviated

Agent: All nine recorded checks passed in the full run. The greeting default is restored.

Example agent conversation. Playback can be paused.

A test fails, the agent restores the greeting in the code, and the full verify run comes back green.