An intelligent GitHub code review bot built for Val Town that automatically analyzes pull requests using Claude AI and posts detailed review comments.
- Automatic PR Analysis: Responds to GitHub pull request webhooks instantly
- AI-Powered Reviews: Uses Anthropic's Claude 3.5 Sonnet for intelligent code analysis
- Secure Integration: Webhook signature verification for security
- Smart File Filtering: Only reviews code files, skips documentation and config files
- Detailed Feedback: Provides structured reviews covering code quality, security, and best practices
- Easy Setup: Simple configuration with environment variables
- Debug Tools: Built-in endpoints to test API connections and troubleshoot issues
- Fork/Copy this project to your Val Town account
- Set environment variables (see setup section below)
- Configure GitHub webhook in your repository
- Create a test PR and watch the magic happen!
When someone opens a pull request, the bot will:
- π Post an initial "review in progress" comment
- π Fetch and analyze changed code files (up to 8 files)
- π§ Generate a comprehensive review using Claude AI
- π¬ Post a structured review comment with:
- Summary of changes
- Code strengths and good practices
- Issues found with specific file references
- Improvement suggestions
- Security and best practice notes
GitHub Token: Create a fine-grained personal access token at https://github.com/settings/personal-access-tokens/new with:
- Repository access: Select the specific repository you want to review
- Permissions > Repository permissions:
- Metadata: Read-only (required)
- Contents: Read-only (required to fetch file contents)
- Pull requests: Read and write (required to post review comments)
Anthropic API Key: Get your API key from Anthropic Console
In Val Town, set these environment variables:
GITHUB_TOKEN: Your GitHub personal access tokenANTHROPIC_API_KEY: Your Anthropic API keyWEBHOOK_SECRET: A random secret string (generate with:openssl rand -hex 32)
Your webhook URL will be: https://[your-username]--[val-id].web.val.run/webhook
You can find this URL by:
- Opening your
index.tsval in Val Town - Looking at the URL in your browser
- Adding
/webhookto the end
Example: If your val URL is https://alice--abc123.web.val.run, your webhook URL is https://alice--abc123.web.val.run/webhook
Before setting up the webhook, test your API connections:
- Open your debug val:
https://[your-username]--[debug-val-id].web.val.run - Check that all environment variables show "β Set"
- Test GitHub API: Visit
/test-githubendpoint - Test Claude API: Visit
/test-claudeendpoint
All tests should return "success": true.
In your GitHub repository:
- Go to Settings > Webhooks > Add webhook
- Set Payload URL: Your Val Town webhook URL (from step 3)
- Set Content type:
application/json - Set Secret: Same value as your
WEBHOOK_SECRETenvironment variable - Select Let me select individual events β Check Pull requests
- Ensure Active is checked
- Click Add webhook
Create a test pull request in your repository. The bot should:
- Post an initial "review in progress" comment
- Analyze the changed files
- Post a detailed review comment within 30-60 seconds
The bot automatically reviews pull requests when they are opened or reopened. It will:
- Fetch the changed files from the PR
- Analyze the code using Claude
- Post a review comment with findings
βββ index.ts # Main webhook handler (HTTP endpoint)
βββ github.ts # GitHub API integration and PR processing
βββ claude.ts # Claude AI integration for code analysis
βββ utils.ts # Utility functions (webhook verification, file filtering)
βββ debug.ts # Debug endpoints for testing API connections
βββ test.ts # Webhook signature verification tests
βββ webhook-test.ts # Mock webhook payload testing
βββ example-env.md # Environment variable setup guide
βββ README.md # This file
- Webhook Handler (
index.ts): Receives GitHub webhooks, verifies signatures, and triggers reviews - GitHub Integration (
github.ts): Fetches PR data, file contents, and posts review comments - AI Analysis (
claude.ts): Generates intelligent code reviews using Claude 3.5 Sonnet - Security (
utils.ts): HMAC-SHA256 webhook signature verification - Debug Tools (
debug.ts): Test API connections and troubleshoot configuration issues
- Check that your webhook URL is correct in GitHub settings
- Verify all environment variables are set in Val Town
- Check the webhook delivery logs in GitHub (Settings > Webhooks > Recent Deliveries)
- Look at the Val Town logs for error messages
- Ensure your GitHub token has the correct permissions
- Verify the token hasn't expired
- Check that the repository is accessible with your token
- The bot analyzes up to 10 files per PR to stay within API limits
- Only code files are reviewed (JS, TS, Python, etc.)
- Very large files are truncated to prevent token limit issues
- Ensure the
WEBHOOK_SECRETin Val Town matches the secret in GitHub - Check that the webhook is configured to send JSON payloads
- Reviews up to 10 files per PR
- File content is truncated to 2000 characters for analysis
- Only reviews code files (filters out documentation, images, etc.)
- Requires internet access to GitHub and Anthropic APIs