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 Haiku 4.5 for intelligent code analysis and typo detection
- Secure Integration: Webhook signature verification for security
- Smart File Filtering: Reviews code files and markdown files for typos, skips other documentation and config files
- Detailed Feedback: Provides structured reviews with inline comments on specific lines, including GitHub suggestions for one-click fixes
- 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 and markdown files (up to 8 files)
- π§ Generate a comprehensive review using Claude Haiku 4.5
- π¬ Post a structured review with:
- Summary comment on the PR
- Inline comments on specific lines with issues
- GitHub suggestions for one-click fixes (typos, simple errors)
- For markdown files: typos, grammar issues, and formatting problems
- For code files: bugs, security concerns, and performance issues
- Actionable suggestions and improvements
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 Haiku 4.5
- Post a summary comment on the PR
- Post inline comments on specific lines with issues and suggestions
The bot provides two types of feedback:
- Summary Comment: Posted on the PR with an overall assessment
- Inline Comments: Posted on specific lines where issues are found, with actionable suggestions
- GitHub Suggestions: For simple fixes (typos, formatting), provides one-click suggestions that can be applied directly
This makes it easy to see exactly where problems occur and apply fixes with minimal effort.
βββ 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 Haiku 4.5 - 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
- Code files are reviewed for quality, security, and best practices
- Markdown files (.md, .mdx) are reviewed for typos, grammar, and formatting
- 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
The bot automatically reviews these file types:
- JavaScript/TypeScript:
.js,.ts,.jsx,.tsx - Python:
.py - Java:
.java - C/C++:
.c,.cpp,.h - C#:
.cs - PHP:
.php - Ruby:
.rb - Go:
.go - Rust:
.rs - Swift:
.swift - Kotlin:
.kt - Web:
.html,.css,.scss,.vue,.svelte - Database:
.sql - Documentation:
.md,.mdx(focuses on typos, grammar, and formatting) - And more...
- Small PRs: The bot works best with focused changes (8 files or fewer)
- Clear Descriptions: Add good PR descriptions to help the AI understand context
- Test First: Use the debug endpoints to verify your setup before going live
- Monitor Usage: Keep an eye on your Anthropic API usage for cost management
- Apply Suggestions: Use GitHub's "Apply suggestion" button for one-click fixes
The bot uses GitHub's suggestion syntax for simple fixes:
- Typos and Grammar: Spelling corrections in markdown files
- Code Fixes: Simple syntax errors, missing punctuation, variable name corrections
- Formatting: Indentation, spacing, and style improvements
When you see a suggestion, you can apply it with one click using GitHub's "Apply suggestion" button!
- Modify the file type filters in
utils.ts - Adjust the Claude prompt in
claude.tsfor your team's coding standards - Add custom rules or checks specific to your project
- Integrate with other tools (Slack notifications, JIRA, etc.)
Edit claude.ts to customize the AI review criteria:
// Add your team's specific guidelines
const customGuidelines = `
Additional review criteria:
- Check for proper error handling
- Verify database query optimization
- Ensure proper logging practices
`;
The bot truncates large files to 2000 characters. Adjust in claude.ts:
// Increase or decrease based on your needs
${file.content.substring(0, 2000)}
- File Limit: Reviews up to 8 files per PR (to stay within API token limits)
- File Size: Large files are truncated to 2000 characters for analysis
- File Types: Reviews code files for quality/security and markdown files for typos/grammar
- Dependencies: Requires internet access to GitHub and Anthropic APIs
- Rate Limits: Subject to GitHub and Anthropic API rate limits
These limitations help ensure fast, reliable reviews while managing API costs and complexity.