Skip to content

diggerhq/claude-agent-sdk-test

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PR Review Agent

An automated GitHub PR review agent powered by the Claude Agent SDK, running in isolated E2B sandboxes with a real-time analytics dashboard.

Dashboard

What it does

  1. Receives GitHub webhooks when a PR is opened or updated
  2. Spins up an isolated E2B sandbox for each review
  3. Runs Claude Agent SDK to analyze the code - it can read files, search the codebase, and run commands
  4. Posts a review comment back to the GitHub PR
  5. Tracks analytics - cost, tokens, duration, tool usage

Architecture

┌─────────────────┐      ┌──────────────────┐      ┌─────────────────┐
│  GitHub Webhook │─────▶│  Orchestrator    │─────▶│  E2B Sandbox    │
│  (PR opened)    │      │  (Local Express) │      │  (Claude Agent) │
└─────────────────┘      └────────┬─────────┘      └────────┬────────┘
                                  │                         │
                                  ▼                         │
                         ┌──────────────────┐               │
                         │  SQLite + Web UI │◀──────────────┘
                         │  (Analytics)     │
                         └──────────────────┘

Tech Stack

Component Technology
Runtime Node.js + TypeScript
Server Express.js
Agent @anthropic-ai/claude-agent-sdk
Sandbox E2B
Database SQLite (better-sqlite3)
GitHub API Octokit
Dashboard Vanilla HTML/JS + Chart.js

Quick Start

1. Install dependencies

npm install

2. Configure environment

cp .env.example .env

Edit .env with your API keys:

ANTHROPIC_API_KEY=sk-ant-...
GITHUB_TOKEN=ghp_...
GITHUB_WEBHOOK_SECRET=your-secret
E2B_API_KEY=e2b_...
PORT=3001

3. Run the server

npm run dev

4. Open the dashboard

Visit http://localhost:3001

5. Trigger a review

Either:

  • Use the "Manual Trigger" form in the dashboard with any GitHub PR URL
  • Or set up a GitHub webhook (see below)

Setting up GitHub Webhooks

  1. Expose your local server with ngrok:

    ngrok http 3001
  2. In your GitHub repo, go to Settings → Webhooks → Add webhook

  3. Configure:

    • Payload URL: https://your-ngrok-url.ngrok.io/webhook/github
    • Content type: application/json
    • Secret: Same as GITHUB_WEBHOOK_SECRET in your .env
    • Events: Select "Pull requests"
  4. Now when you open a PR, the agent will automatically review it!

API Endpoints

Endpoint Method Description
/ GET Analytics dashboard
/webhook/github POST GitHub webhook receiver
/api/reviews GET List all reviews
/api/reviews/:id GET Get review details with traces
/api/analytics GET Summary statistics
/api/trigger POST Manually trigger a review

How the Agent Works

Inside the E2B sandbox, the Claude Agent SDK:

  1. Fetches PR metadata and diff from GitHub
  2. Clones the repository
  3. Analyzes the changes using tools:
    • Read - read file contents
    • Glob - find files by pattern
    • Grep - search code
    • Bash - run commands
  4. Generates a structured review
  5. Posts the review as a PR comment

Tracing

The agent captures detailed traces for debugging:

# Get trace events for a review
curl http://localhost:3001/api/reviews | jq '.[0].traceEvents'

Traces include:

  • GitHub API call timing
  • Git clone duration
  • Each tool invocation with inputs/outputs
  • Token usage per turn
  • Total cost calculation

Project Structure

pr-review-agent/
├── src/
│   ├── index.ts           # Express server + routes
│   ├── orchestrator.ts    # E2B sandbox management + agent code
│   ├── agent/
│   │   └── reviewer.ts    # Standalone agent (reference)
│   ├── analytics/
│   │   ├── store.ts       # SQLite operations
│   │   └── types.ts       # TypeScript interfaces
│   └── web/
│       └── dashboard.html # Analytics UI
├── docs/
│   └── dashboard.png      # Screenshot
├── package.json
├── tsconfig.json
└── .env.example

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 73.3%
  • HTML 26.7%