AGENT0S
HomeLibraryAgentic
FeedbackLearn AI
LIVE
Agent0s · AI Intelligence Library
Share FeedbackUpdated daily · 7am PST
Library/workflow
workflowadvancedClaude Code★ Featured

Automated PR Review Workflow with GitHub Actions + Claude API

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.

AI SETUP PROMPT

Paste into Claude Code — it will scan your project and set everything up

# 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
3,509 charactersCompatible with Claude Code & Codex CLI
MANUAL SETUP STEPS
  1. 01Copy the workflow YAML to .github/workflows/ai-review.yml and add your ANTHROPIC_API_KEY as a GitHub Actions secret.
  2. 02Customize the review prompt template in the workflow to match your team's standards — add your tech stack, forbidden patterns, and required checks.
  3. 03Set the workflow to only trigger on PRs targeting main/production branches, with a label gate ("needs-ai-review") to avoid reviewing draft PRs.

CODE INTELLIGENCE

bash
# .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

FIELD OPERATIONS

Tiered Review Bot

A system where Claude does initial triage (block only critical issues), then a more expensive thorough review runs only on PRs that pass triage.

Review Analytics Dashboard

Track which types of issues Claude catches most often in your codebase over time to identify systemic training needs.

STRATEGIC APPLICATIONS

  • →Cut average PR review time from hours to minutes for the first-pass review
  • →Ensure consistent code quality standards across distributed teams in different timezones
  • →Catch security vulnerabilities before they reach code review, reducing the likelihood of human reviewers missing them

TAGS

#github-actions#ci-cd#code-review#automation#workflow
Source: GITHUB · Quality score: 9/10
VIEW SOURCE