Build a Code Review Assistant for GitHub PRs with Claude

What Does This Code Review Assistant Do?
This project builds a GitHub PR review assistant that fetches changed files from a pull request, sends each file to Claude with full PR context, and receives structured feedback categorised by severity — critical, high, medium, low. Claude identifies security issues, performance problems, and best-practice violations, then posts the full review as a comment directly on the pull request.
Code review is one of the most valuable practices in software development — and one of the most time-consuming. Experienced reviewers catch bugs, spot security vulnerabilities, enforce best practices, and share knowledge. But reviewers cannot always respond quickly, and even the best reviewers have blind spots.
An AI code review assistant does not replace human reviewers — it supplements them. It provides an immediate first pass on every pull request, catching common issues, flagging security concerns, and giving the author quick feedback before a human reviewer even opens the PR. Human reviewers can then focus their energy on the architecture, design decisions, and domain-specific logic that genuinely requires human judgment.
This project builds a GitHub PR review assistant that analyses changed files, provides structured feedback by category, and posts a review comment directly to the pull request.
What We Are Building
The code review assistant:
- Fetches the PR diff from GitHub using the GitHub REST API
- Analyses each changed file with Claude for bugs, security issues, performance problems, and style violations
- Produces a structured review with severity-labelled findings
- Posts the review as a comment on the GitHub PR
Prerequisites
- Python 3.9 or later
- pip install anthropic requests
- An Anthropic API key set as ANTHROPIC_API_KEY
- A GitHub Personal Access Token with repo scope set as GITHUB_TOKEN
Complete Implementation
Set post_comment=False During Testing
Always test your review with post_comment=False first. This prints the formatted review to your terminal without posting to GitHub, letting you verify the output quality before it becomes visible to your team. Only set post_comment=True in your production GitHub Actions workflow once you are confident in the review quality.
Deploying as a GitHub Action
Create .github/workflows/ai-review.yml to run automatically on every PR:
Summary
This project demonstrates Claude's ability to reason about code structure and quality across multiple files simultaneously. The critical design elements:
- Structured tool output with severity levels — makes it easy to filter critical vs cosmetic findings
- Context from the PR title and description — Claude understands the intent of the change, not just the code
- Skipping non-reviewable files (documentation, images, lock files) — keeps focus on actual code
- Posting to GitHub — makes the review visible in the existing developer workflow without requiring a separate tool
Next project: Project: Build a Multi-Language Translator App with Claude.
To deploy this as a full automated pipeline, see AI Coding Agents in CI/CD and Build a GitHub PR Review Agent. For the structured output concepts behind the review schema, see Claude Structured Outputs and JSON.
External Resources
- GitHub REST API: Pull Request Reviews — official docs for the API endpoints used to post review comments.
- Anthropic Tool Use documentation — reference for the structured tool schema that powers the review output.
This post is part of the Anthropic AI Tutorial Series. Previous post: Project: Build an Automated Meeting Notes Summariser.
