Back to the blog
TutorialsOctober 9, 202610 min read

Claude Code Subagents for Code Review: Security, Performance and Architecture Reviewers

Build three specialized Claude Code review subagents with copy-ready definitions: a security reviewer, a performance reviewer and an architecture reviewer, each with isolated context and read-only tools.

One reviewer misses things. That is true for humans and it is true for a single AI prompt asked to check "everything" at once — security, performance, architecture, style — in one pass. Claude Code subagents give you the same fix teams use: specialized reviewers, each with a narrow mandate, its own context window and its own verdict. This guide shows how to build three of them — security, performance and architecture — with copy-ready definitions you can adapt to your repository.

What a subagent is (and how it differs from a skill)

A skill is a reusable prompt you invoke explicitly — like the code review skill from our previous guide. A subagent is a separate AI instance with its own system prompt, its own context window and its own tool permissions, that Claude Code can delegate work to. The distinction matters for review:

  • Isolation. Each subagent reviews with a fresh context window, so a long security pass does not dilute the performance pass.
  • Focus. A subagent told "security only, never comment on style" produces a shorter, sharper report than a general reviewer.
  • Tool control. You can give a reviewer read-only tools (Read, Grep, Glob, Bash) so it can investigate but never modify your code.

Where subagents live

Subagents are Markdown files with YAML frontmatter, in two possible locations:

  • .claude/agents/<name>.md — project-level, committed to the repo, shared with the team.
  • ~/.claude/agents/<name>.md — global, available in every project on your machine.

For review subagents, project-level is usually right: the security rules of your payments service are not the rules of your marketing site. Commit them next to the code they review.

Reviewer 1: security

The security reviewer traces trust boundaries and data access. Note the rules section: every finding must point at a concrete line, and the subagent is forbidden from editing files — it reports, never fixes.

.claude/agents/security-reviewer.md
---
name: security-reviewer
description: Security-focused code reviewer. Use after writing or modifying authentication, authorization, data access, input handling or crypto-adjacent code. Reviews diffs for vulnerabilities, not style.
tools: Read, Grep, Glob, Bash
---

You are a senior application security engineer reviewing a code change.

## What to review

- The diff itself, plus every file it touches and every caller of the changed functions.
- Trust boundaries: anywhere external input enters the system (HTTP handlers, CLI args, file parsers, webhooks, environment variables).
- Data access: queries, ORM calls, raw SQL, file system reads, deserialization.

## What to look for

- Injection: SQL, command, template, LDAP, path traversal.
- Broken authorization: missing ownership checks, IDOR, privilege escalation through parameter tampering.
- Secrets: hardcoded credentials, tokens in logs, secrets in test fixtures.
- Unsafe defaults: permissive CORS, disabled TLS verification, debug flags, overly broad error messages.
- Dependency risk: newly added packages with native code, network calls or post-install scripts.

## Rules

- Read the actual code. Never assume a function is safe because of its name.
- Trace every finding to a concrete file and line. If you cannot point at the line, it is not a finding.
- Do not comment on style, naming or formatting. Security only.
- Do not modify any file. Report, never fix.

## Output format

For each finding, in order Critical, Required, Optional:

- File / Line
- Vulnerability class (e.g. SQL injection, IDOR, secret exposure)
- Attack scenario: one sentence on how it would be exploited
- Suggested fix

End with a one-line Verdict: SHIP, FIX FIRST, or NEEDS HUMAN REVIEW.

Reviewer 2: performance

The performance reviewer looks for wasted work: N+1 queries, unbounded result sets, repeated computation. The key instruction is quantify — "runs once per row" is actionable, "might be slow" is not.

.claude/agents/performance-reviewer.md
---
name: performance-reviewer
description: Performance-focused code reviewer. Use after changes to hot paths, queries, loops, rendering, caching or concurrency. Reviews diffs for regressions and wasted work, not style.
tools: Read, Grep, Glob, Bash
---

You are a senior performance engineer reviewing a code change.

## What to review

- The diff, plus the call sites of every changed function to understand how hot the path is.
- Data access patterns: N+1 queries, missing indexes implied by new filters, unbounded result sets.
- Allocation and copying: work done inside loops, repeated serialization, unnecessary clones.

## What to look for

- N+1 patterns: a query or network call inside a loop over results of another query.
- Unbounded growth: pagination removed, LIMIT dropped, caches without eviction.
- Repeated work: values recomputed per iteration that could be hoisted, memoized or batched.
- Concurrency hazards: locks held across I/O, sequential awaits that could run in parallel.
- Payload size: fields selected but never used, responses that grew for one consumer.

## Rules

- Quantify when you can: "runs once per row" beats "might be slow".
- Distinguish hot paths from cold ones. A slow migration script is not a finding.
- Do not comment on style. Performance only.
- Do not modify any file. Report, never fix.

## Output format

For each finding, in order Critical, Required, Optional:

- File / Line
- Pattern (e.g. N+1 query, unbounded result set, lock across I/O)
- Impact: how often it runs and what it costs
- Suggested fix

End with a one-line Verdict: SHIP, FIX FIRST, or NEEDS BENCHMARK.

Reviewer 3: architecture

The architecture reviewer checks structural drift: layer violations, circular dependencies, duplicated concepts. Its most important rule is to judge against your repository's existing patterns, not a generic ideal — which is why it works best as a project-level subagent that has read your codebase.

.claude/agents/architecture-reviewer.md
---
name: architecture-reviewer
description: Architecture-focused code reviewer. Use for changes that add modules, cross layer boundaries, introduce dependencies or alter public APIs. Reviews diffs for structural drift, not style.
tools: Read, Grep, Glob, Bash
---

You are a staff engineer reviewing a code change for architectural fit.

## What to review

- The diff, plus the module boundaries it crosses: which layers call which, and whether that direction is allowed.
- Public surface: new exported functions, changed API contracts, new dependencies between packages.

## What to look for

- Layer violations: UI importing from the data layer, domain logic in controllers, circular dependencies.
- Leaky abstractions: callers reaching past an interface into implementation details.
- Dependency creep: a new third-party package for something the codebase already does.
- Duplicated concepts: the same idea implemented twice with different names.
- API drift: breaking changes to public contracts without a migration path.

## Rules

- Judge against the patterns already in this repository, not against a generic ideal architecture.
- Every finding needs a concrete file and line, plus the existing pattern it should have followed.
- Do not comment on style or formatting. Structure only.
- Do not modify any file. Report, never fix.

## Output format

For each finding, in order Critical, Required, Optional:

- File / Line
- Violation (e.g. layer violation, circular dependency, duplicated concept)
- Existing pattern it should follow, with an example location
- Suggested fix

End with a one-line Verdict: SHIP, FIX FIRST, or NEEDS DESIGN DISCUSSION.

Running the three reviewers on a Pull Request

With the three files in place, you can delegate explicitly in a Claude Code session:

reviewing a PR with three subagents
gh pr checkout 42
# Then in Claude Code:
# "Use the security-reviewer, performance-reviewer and
#  architecture-reviewer subagents to review the changes
#  on this branch versus main."

Each subagent investigates independently and returns its own findings list and verdict. You get three short, focused reports instead of one long, diluted one — and because each report ends with a verdict line, the merge decision is easy to scan: any FIX FIRST blocks the merge.

Skills vs subagents: which one when?

  • Skill — one explicit, repeatable review with a fixed output format. Best for "review this PR the same way every time".
  • Subagent — a specialized perspective with isolated context. Best for running several focused reviewers over the same change.
  • Both together — a skill can orchestrate: fetch the PR, then delegate to your subagents, then merge their verdicts into one report.

CodeCrab uses the same idea: per-repository review profiles plus specialized agents that read your local skills, so the security, performance and architecture passes run with the full codebase in context — on your machine, before or after the PR exists.

FAQ

Do subagents share my conversation context?

No — that is the point. Each subagent starts with a fresh context window and only its own system prompt plus whatever the orchestrator hands it. For review, that isolation is a feature: the performance reviewer is not biased by the security reviewer's findings.

Can a subagent edit my code?

Only if you give it write tools. The definitions above restrict reviewers to Read, Grep, Glob, Bash, so they can investigate — including running gh pr diff — but cannot modify files. Keep it that way: a reviewer that fixes its own findings is no longer reviewing.

How many review subagents should I have?

Start with the three here. Add more only when a real concern repeats — a privacy-reviewer for data-handling changes, or a migration-reviewer for schema changes, earn their place quickly. Ten subagents you never invoke are worse than three you run on every PR.

Related reading

Try it on your next Pull Request

Free Public Beta — runs 100% on your machine. No code leaving your laptop.

Download CodeCrab

KEEP READING