Dev.to AI 🤖 Ai 👁 0 📖 4 min read

How to Review Claude Code's Work With a Subagent (Under 20 Lines, Copy-Paste)

You ask Claude Code to build a feature. It writes the code, runs the tests, and says it's done. Then you type the obvious follow-up: "Now review what you just wrote." It reviews it in the same conversation, with the sa

You ask Claude Code to build a feature. It writes the code, runs the tests, and says it's done.

Then you type the obvious follow-up: "Now review what you just wrote."

It reviews it in the same conversation, with the same context, holding the same assumptions that produced the code. If it misunderstood the requirement an hour ago, it will misunderstand it again now. A review by the author, in the author's head, is a re-read.

Human teams solved this a long time ago: the reviewer is someone else. Claude Code lets you do the same thing with a subagent.

What you'll build: a code-reviewer subagent that runs in its own context window, can read and search your code, and cannot edit files or run commands.

Code: the file is in the ops-ai repo, inside a starter .claude/ folder you can copy whole.

Why a subagent, not a second prompt

A subagent is a helper Claude Code can hand work to. Two properties make it a good reviewer.

  1. It has its own context window. It doesn't see the conversation that produced the code: the false starts, the "let's just hard-code this for now", the assumptions. It sees the files. Only its final report comes back to your main conversation.
  2. You choose its tools. A reviewer that can edit stops being a reviewer. The moment it "fixes" something as it goes, you're back to reviewing its changes yourself.

The whole subagent

Save this as .claude/agents/code-reviewer.md in your repo:

---
name: code-reviewer
description: "Reviews changed files for bugs, missing tests and security issues. Use after finishing a feature or before a commit. Pass it the list of changed files."
tools: Read, Grep, Glob
model: sonnet
---

You are a careful senior reviewer seeing this code for the first time.
You were given a list of changed files. Read each one, and any file it
depends on that you need to understand it.

Report, in order of severity:
1. Bugs or logic errors
2. Missing or weak tests
3. Security issues (secrets, injection, unchecked input)

For each finding: file, line, what's wrong, and the fix in one or two lines.
Skip style nitpicks. If you find nothing serious, say so plainly.

You can read and search but not edit or run commands. Report; don't fix.

What each line is doing

description is how Claude Code decides when to use the subagent, so it's written as a trigger: what it does, then when to use it. It also tells the main conversation what to hand over: the list of changed files.

tools: Read, Grep, Glob is the important line. Without it, a subagent inherits every tool the main session has, including Edit, Write and Bash. With it, the reviewer can open files and search the codebase, and that's all. It can't edit anything, and it can't run commands.

That last part has a consequence worth knowing. The reviewer can't run git diff itself, because that needs Bash. That's deliberate. Letting it have Bash "just for git diff" isn't something the tools field can express: as far as Anthropic's docs describe it, the field takes tool names, not command patterns. Give it Bash and it gets all of Bash. So the main conversation, which can run git, does that part and passes the result along.

model: sonnet picks the model for the review. You can also set opus, haiku, a full model ID, or inherit to match the main session.

The prompt body is the reviewer's whole job description. "Seeing this code for the first time" isn't decoration. It sets the stance you want: no benefit of the doubt.

Using it

Ask in plain words:

Run git diff --name-only, then use the code-reviewer subagent
to review those files.

Or mention it directly with @agent-code-reviewer. Claude Code runs git diff in the main session, hands the file list to the reviewer, and the reviewer works in its own context. What comes back is a short, ranked list of findings. Then you decide, in the main conversation, which ones to fix.

Two habits make it more useful. First, review before you commit, not after you push. It's cheapest when the change is still fresh and small. Second, tell it what the change was for. "Review these files; the goal was to add refund support without changing the invoice totals" gives the reviewer a requirement to check against, not just code to read.

When this is the wrong choice

  • Tiny changes. A one-line fix doesn't need a second opinion. The subagent costs a separate model call and a few seconds.
  • As a replacement for tests. A reviewer reads; it doesn't execute. It can tell you a test is missing. It can't tell you the code works.
  • As a replacement for a human on risky changes. Authentication, payments, data migrations: let the subagent do the first pass, then have a person look.

The real point

The interesting thing about this subagent isn't what it's told to do. It's what it's not able to do.

Most of the ways people try to make AI behave are instructions: "be careful", "don't change anything", "only report". Instructions are requests. The tools line isn't a request. It's the set of things that physically exist for the reviewer, and Edit isn't in it.

So here's the question for your own setup: for each helper you've given your coding agent, which rules are written in its prompt, and which ones are written in what it can actually do?

The reviewer, plus a CLAUDE.md template, hooks and a permissions file, is in the starter folder of the ops-ai repo. Copy the .claude/ folder into your project and edit from there.

References

  1. Claude Code docs, Subagents
  2. Claude Code docs, Permissions

Originally published on Level Up Coding.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.