Write a custom SQL reviewer agent for Claude Code

Claude Code has built-in agents for exploring and planning. A custom agent adds a reviewer that reads your SQL changes in its own context, with read-only tools, and answers in a fixed format. The file, the fields, and how to call it.

Short answer: create .claude/agents/sql-reviewer.md with a name, a description that says when to use it, a tools line limited to reading (Read, Grep, Glob), and the review instructions below. Call it by typing @ and picking it, or let Claude hand it the job when you ask for a review. It works in its own context window, so a long review does not crowd your main conversation.

Claude Code already has three built-in agents: Explore (searches code, read-only), Plan (researches for plan mode) and general-purpose. None of them knows your team's rules for SQL. A custom agent does, and it reviews the same way every time.

Nothing loads from YouTube until you press play. Then Google receives your IP address and may set its own storage. Narrated with an AI-generated voice. Privacy

How is an agent different from a skill?

|SkillAgent
Where it runsIn your main conversationIn its own context window
ToolsWhatever the session hasOnly the ones you list
Good forA checklist on one queryReviewing many changed files
Called by/name, or a matching request@name, or a matching request
Skill or agent for a SQL review?

What does the agent file look like?

---
name: sql-reviewer
description: Use after SQL files change, to review them before commit. Read-only.
tools: Read, Grep, Glob
---
You review SQL changes in this repository.
For each changed .sql file:
- Check joins for keys that are not unique (rows that repeat).
- Check date filters and NULL handling.
- Flag UPDATE or DELETE without WHERE.
- Compare column names with the files in schema/.
Answer as a table: file, line, problem, suggested fix.
If everything is fine, say so in one line.

Because the tools are read-only, the reviewer can never "fix" a file on its own; it reports, and you decide.

When do you call it?

After a change and before the commit: "@sql-reviewer review the SQL I changed today". On a big pull request, it reads every file in its own context and returns one table.

Where can you check this?

Where do you start?

For a lighter check on one query, see a skill that checks SQL. For a searching agent, see subagents for big schemas.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.