What It Builds
A code review agent that:- Reads a git diff from the local repo
- Optionally reads full file contents for context
- Produces structured review comments with severity levels
- Ends the run with a summary and approve/reject decision
Prerequisites
- Node.js 22+
- An Anthropic API key
- A git repository with at least one commit
Get the Code
How It Works
Defining Tools with Zod Schemas
The bot usescreateTool with zod schemas for type-safe tool definitions. Here’s the review comment tool:
z.enumconstrains severity to valid values, which improves model accuracy.describe()on each field tells the model what to provide- The tool accumulates results in an array for post-run processing
Completion Tools
Thesubmit_review tool uses lifecycle: { completesRun: true } to signal that the agent’s work is done:
maxIterations. With it, the agent calls submit_review when it’s done and the run ends cleanly.
System Prompt
The system prompt gives the agent a structured workflow to follow:Event Streaming
The bot subscribes to events to show progress as the agent works:Post-Run Processing
After the run, the bot groups comments by severity and prints a summary:Run It
Extending Further
From here, you could:- Add a tool that posts review comments back to GitHub via the API
- Use
continue()for follow-up questions about specific findings - Add a
checkstyletool that runs linters on the changed files - Connect it to a webhook for automatic PR reviews
More Examples
CLI Agent
Interactive terminal chat with tools and multi-turn conversation.
Multi-Agent
Parallel agents streaming to a web UI.

