Agent Upstart

Cool things people are building with agents — and practical help getting the most out of them.

Playbooks · Coding agents

Security-review your own code with Claude Code

Written October 26, 2026 · Edited November 11, 2026

For a solo developer × reviewing their own recent changes for security holes × Claude Code, ending with a fix and a regression test per real finding — and a hook that refuses to let the session end while a finding is still open.

Before you start

You need a branch with a small, reviewable diff — a feature or a fix, not a month of work — and a test runner you can actually run. Work on a branch, not on main, so a bad repair is cheap to throw away. An agent review is a second opinion, not a merge gate on its own: it can miss context you know and it can be confidently wrong about something subtle, so a human still reads the final diff before it merges.

The one discipline the whole loop rests on: a finding without a reproduction is a hypothesis, not a vulnerability. You do not repair hypotheses. You reproduce them first, and the ones that do not reproduce get dropped, not fixed.

What "done" looks like

At the end of one session you have a short findings list where every surviving item has a reproduction, a fix on the branch, and a regression test that fails without the fix and passes with it — plus a completion hook that re-scans the changed lines and sends the session back to work while anything is still open. Findings that did not reproduce are listed as dropped, with the reason, so the next session does not re-litigate them.

Steps

  1. Run the review on the diff, not the whole repo. In Claude Code, run the built-in security review command on your pending changes. The command ships with Claude Code and reviews pending changes; the GitHub Action version of the same reviewer is diff-aware for pull requests, analyzing only changed files. A whole-repo scan buries the three real findings in a hundred old ones you are not about to fix today.
  2. Triage the findings against the reviewer's own filter. The reviewer already excludes low-impact, false-positive-prone classes: denial of service, rate limiting, memory and CPU exhaustion, generic input validation without proven impact, and open redirects. Drop anything in those classes without argument, then drop anything whose explanation does not name the exact code path an attacker would take. What survives should be a short list, each item naming a vulnerability class the reviewer documents — injection, broken authentication or authorization, data exposure, weak cryptography, bad input validation, business-logic flaws, insecure configuration, supply-chain risk, code execution, or cross-site scripting.
  3. Reproduce each surviving finding before touching code. For each item, write the smallest proof that it is real: the crafted input, request, or call sequence that reaches the vulnerable code and shows the bad outcome. If you cannot produce that proof, the finding is dropped and recorded as not reproduced. This is the step that stops the loop from becoming a fix-everything-the-model-said session, and it is also what makes the regression test in step 5 possible: a reproduction is a test waiting to be written down.
  4. Repair on the branch, one finding at a time. Fix the reproduced findings one by one, smallest fix first, and keep each fix in its own commit where the change allows it. A repair that touches five findings at once cannot be reverted for one of them, and a repair you cannot revert is a repair you cannot trust.
  5. Add one regression test per finding. For each repaired finding, add a test that fails on the code before the fix and passes on the code after it. Run it both ways at least once — against the fixed code, and by temporarily reverting the fix — so you know the test actually guards the finding rather than passing regardless. A finding with no regression test will come back the next time someone refactors the same code, and nobody will notice.
  6. Re-run the review on the fix diff only. Run the review command again, scoped to the changes your repairs made. New findings introduced by the repairs themselves are the most embarrassing kind, and they are also the easiest to catch, because the diff is small and fresh. Anything new goes back through steps 3 to 5; nothing skips the reproduction step because it arrived in a repair.
  7. Gate completion with a Stop hook that scans only changed lines. Add a hook that fires when Claude Code finishes a response, scans only the lines the session changed (the diff against HEAD plus new files), and sends Claude back to work with its findings while any remain. The hook pattern is: scan changed lines, exit with code 2 and the report on stderr while findings remain, exit 0 when clean. The official hooks reference confirms the mechanics this relies on: exit code 2 on the Stop event sends Claude back to keep working instead of stopping. Put an attempt cap on it — after three blocked completions, stop blocking and write the report to a file for a human instead. A gate with no cap can loop forever on a finding nobody can fix, and a session that cannot end is worse than a session that ends with a report.
  8. Read the final diff yourself before merging. Go through the branch diff once, by eye, with the findings list beside it. Confirm every fix is one you understand, every regression test is one you believe, and nothing unrelated rode along in a repair commit. Then merge. The loop's output is a reviewed branch, not a verdict: the verdict is yours.

Check the agent's work

What can go wrong

Limits

Related playbooks

Sources

Sources: anthropics/claude-code-security-review, Claude Code hooks reference, a published Stop-hook write-up.

Back to: Coding playbooks hub · Also: Review a pull request with a coding agent