# Set Up Workflow: Automated PR Review Workflow with GitHub Actions + Claude API
## What This Is
A GitHub Actions workflow that automatically reviews every pull request using the Claude API. It reads the diff, runs it through a structured review prompt, and posts inline comments on specific lines — catching logic errors, security issues, and style violations before human review.
Source: https://github.com/anthropics/anthropic-cookbook/tree/main/misc/github_actions_pr_review
## Before You Start
Scan my workspace and analyze:
- The project language, framework, and directory structure
- Existing AI provider config (check .env, .env.local, config files for API keys — OpenRouter, OpenAI, Anthropic, Google AI, etc.)
- Whether this repository or a similar tool is already cloned or installed
Then ask me before proceeding:
1. Which AI provider/API should this use? (Use whatever I already have configured, or ask me to set one up — options include direct provider APIs or a unified service like OpenRouter)
2. Where in my project should this be integrated?
3. Are there any customizations I need (model preferences, naming conventions, constraints)?
## What to Implement
This is an **AI Workflow** — an end-to-end automation pattern or integration pipeline.
- Study the workflow architecture from the source and context below
- Identify which parts I can implement locally vs. parts that need external services
- For local parts: implement them using my existing stack and API keys
- For external parts: tell me exactly what services I need and help me configure the integration code
- Wire up any required API calls using keys from my .env files
## Additional Context
- Copy the workflow YAML to .github/workflows/ai-review.yml and add your ANTHROPIC_API_KEY as a GitHub Actions secret.
- Customize the review prompt template in the workflow to match your team's standards — add your tech stack, forbidden patterns, and required checks.
- Set the workflow to only trigger on PRs targeting main/production branches, with a label gate ("needs-ai-review") to avoid reviewing draft PRs.
## Reference Implementation
```
# .github/workflows/ai-review.yml
name: AI Code Review
on:
pull_request:
types: [opened, synchronize]
branches: [main, production]
jobs:
review:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get PR diff
id: diff
run: |
git diff origin/main...HEAD > /tmp/pr.diff
echo "diff_size=$(wc -c < /tmp/pr.diff)" >> $GITHUB_OUTPUT
- name: Run AI Review
if: steps.diff.outputs.diff_size < 50000
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
node .github/scripts/ai-review.js --pr=${{ github.event.number }} --diff=/tmp/pr.diff
```
## Guidelines
- Adapt everything to my existing project — do not assume a specific stack or directory layout
- Use whichever AI provider I already have configured; if I need a new one, tell me what to sign up for and I'll give you the key
- Check my .env files for existing API keys (OpenRouter, OpenAI, Anthropic, Google AI) before asking me to add one
- Review any fetched code for safety before installing or executing it
- After setup, run a quick verification and show me a summary of exactly what was installed, where, and how to use it