Pro10 min

Reviewing and Securing AI-Written Code

Agents produce code fast, which means they produce mistakes fast too. The pro discipline is treating every agent diff as untrusted until reviewed, and building review into the workflow so volume never outruns judgment. You are the lead engineer accountable for what merges, no matter who typed it.

Step 1: Know what agents get wrong

  • Subtle logic errors that pass a happy-path test but fail on edge cases.
  • Invented APIs or dependencies that do not exist (hallucinated imports).
  • Secrets hardcoded, or input that reaches a query without sanitizing.
  • Over-broad changes that touch files the task never needed.

Step 2: Use an agent to review the agent

A dedicated reviewer subagent with a fresh context, separate from the one that wrote the code, catches a surprising amount. It has no attachment to the implementation and reads the diff cold. Pair it with a human on anything that touches auth, money, or data.

claude - service
$> run the reviewer subagent on the current diff
Reviewer: src/pay.ts:42 builds SQL with string concat (injection risk).
Reviewer: missing test for refund > original amount.
2 findings. Recommend fixing before PR.
$

Step 3: Gate the risky paths

Combine the tools from this level: a Stop hook that runs the test suite and a security linter, a reviewer subagent on every PR, and a human approval required before merge to main. Defense in depth means no single failure ships a bug.

Speed without review is a liability
The danger of fast agents is not that they cannot code, it is that they let you merge more than you can vet. Scale your review with your output: automate the catchable issues and reserve human attention for the consequential ones.

Trust the agent to do the work. Trust the review, not the agent, to decide what ships.

PR - review gate
PR #318 add refund endpoint
Checks: tests pass, typecheck pass, security lint pass
Reviewer subagent: 0 open findings
Required: 1 human approval -> pending
Automated checks plus a human approval before anything merges.

Hands-on tasks