An autonomous, real-time code review agent powered by Anthropic's Claude. This tool acts as an automated senior engineer on your team by fetching pull requests, analyzing code for bugs and anti-patterns, adhering to custom team style guides, and dropping inline code comments directly onto the GitHub PR timeline.
- Autonomous Code Analysis: Connects directly to GitHub to fetch PR diffs and analyzes them using Claude.
- Real-Time Streaming: Features a modern, minimalist local dashboard built with Server-Sent Events (NDJSON) to stream the agent's internal thought process and execution states in real-time.
- Inline GitHub Comments: Uses the GitHub PR Reviews API to attach targeted comments precisely to the offending lines of code in the "Files changed" tab.
- Idempotency: Cross-references its findings with existing PR comments to ensure it never spams your repository with duplicate issues.
- Custom Team Rules: Inject ad-hoc style guides or strict typing rules via the dashboard to enforce project-specific conventions.
- Automated CI/CD Webhooks: Fully automated background mode. Configure a GitHub webhook to automatically trigger reviews the moment a PR is opened or updated.
- Netra Observability: Fully instrumented with the Netra SDK for deep tracing of LLM tool usage and execution spans.
code-review-agent/
├── public/ # Frontend dashboard assets
│ ├── app.js # Real-time NDJSON stream parser and UI logic
│ ├── index.html # Minimalist dashboard UI
│ └── styles.css # Custom styling and animations
├── src/
│ ├── agent/
│ │ └── loop.ts # Anthropic tool-use iterative loop
│ ├── config/
│ │ └── prompt.ts # Core system prompt and idempotency rules
│ ├── tools/
│ │ ├── addLabels.ts # Tool to apply severity labels via GitHub API
│ │ ├── fetchPR.ts # Tool to fetch diffs and parse existing PR comments
│ │ ├── index.ts # Tool registry and Anthropic input schemas
│ │ └── postReview.ts # Tool to post inline review comments via GitHub API
│ ├── types/
│ │ └── index.ts # Shared TypeScript interfaces
│ └── server.ts # Express backend and CI/CD webhook endpoint
├── package.json
├── tsconfig.json
└── README.md
- Node.js (v18+)
- A GitHub Personal Access Token (PAT) with repository read/write permissions.
- An Anthropic API Key.
- A Netra API Key for observability instrumentation.
-
Clone the repository:
git clone https://github.com/Pvnn/code-review-agent.git cd code-review-agent -
Install dependencies:
npm install
-
Configure Environment Variables: Create a
.envfile in the root directory:ANTHROPIC_API_KEY=your_anthropic_api_key_here GITHUB_TOKEN=your_github_pat_here NETRA_API_KEY=your_netra_api_key_here NETRA_OTLP_ENDPOINT=your_netra_otlp_endpoint_here
This project uses netra-sdk to trace agent execution spans and monitor tool usage.
- Create an account and project on your Netra dashboard.
- Obtain your API key and add it to your
.envfile asNETRA_API_KEY. - The SDK is already initialized asynchronously in
src/server.tsviaNetra.init(). Custom spans such asreview_prandwebhook_review_prwill automatically begin syncing to your observability dashboard when the server runs.
To start the local dashboard:
npm run dev
# or manually via tsx:
npx tsx src/server.tsOpen http://localhost:3000 in your browser. Paste a Pull Request URL, optionally add custom rules (e.g., "Enforce strict TypeScript typings"), and click Generate Review.
You can set up the agent to automatically review PRs in the background using GitHub Webhooks.
Use a webhook delivery service like Smee.io or ngrok to expose your local port 3000 to the internet.
Using Smee (Recommended):
npx smee-client -u https://smee.io/your-custom-channel -p 3000 -P /api/webhook- Navigate to your target repository on GitHub.
- Go to Settings > Webhooks > Add webhook.
- Set Payload URL to your Smee or ngrok URL (e.g.,
https://smee.io/your-custom-channel). - Set Content type to
application/json. - Under events, select Let me select individual events, uncheck Pushes, and check Pull requests.
- Save the webhook.
The agent will now autonomously review any new PRs or commits pushed to your repository.
- Backend: Express.js with TypeScript (
tsxruntime). - Frontend: Vanilla HTML/JS/CSS with Server-Sent Events parsing.
- AI:
@anthropic-ai/sdkexecuting an iterative Tool Use loop. - Observability:
netra-sdkfor tracing asynchronous LLM operations.