A reusable GitHub Action for automated code review using Claude Code.
- Two-phase review: codebase analysis + PR review
- Incremental review support (only review new commits on PR updates)
- Posts review summary and inline comments to PR
- Configurable conventions path for project-specific rules
- Supports multiple Claude models
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: AI Code Review
uses: team247/auto-code-review@main
with:
api-key: ${{ secrets.ANTHROPIC_API_KEY }}
github-token: ${{ secrets.GITHUB_TOKEN }}
base-sha: ${{ github.event.pull_request.base.sha }}
head-sha: ${{ github.event.pull_request.head.sha }}
event-action: ${{ github.event.action }}
before-sha: ${{ github.event.before }}Pro and Max users can use OAuth token authentication (run claude setup-token locally to generate):
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: AI Code Review
uses: team247/auto-code-review@main
with:
oauth-token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
base-sha: ${{ github.event.pull_request.base.sha }}
head-sha: ${{ github.event.pull_request.head.sha }}
event-action: ${{ github.event.action }}
before-sha: ${{ github.event.before }}jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: AI Code Review with Options
uses: team247/auto-code-review@main
with:
api-key: ${{ secrets.ANTHROPIC_API_KEY }}
github-token: ${{ secrets.GITHUB_TOKEN }}
base-sha: ${{ github.event.pull_request.base.sha }}
head-sha: ${{ github.event.pull_request.head.sha }}
event-action: ${{ github.event.action }}
before-sha: ${{ github.event.before }}
model: "sonnet" # Default: sonnet (options: haiku, sonnet, opus)
post-review: "true" # Default: true (set "false" to skip PR comments)
conventions-path: "docs/conventions" # Path to conventions files
review-mode: "auto" # Default: auto (options: auto, full, incremental)| Input | Required | Default | Description |
|---|---|---|---|
api-key |
No* | - | Anthropic API key for Claude |
oauth-token |
No* | - | Claude Code OAuth token (Pro/Max users, takes priority over api-key) |
cursor-api-key |
No | - | Cursor API key (falls back to api-key) |
github-token |
No | github.token |
GitHub token for posting comments |
base-sha |
Yes | - | Base commit SHA (target branch) |
head-sha |
Yes | - | Head commit SHA (PR branch) |
event-action |
No | opened |
GitHub event action |
before-sha |
No | - | Previous head SHA (for synchronize events) |
model |
No | sonnet |
Claude model to use |
post-review |
No | true |
Whether to post comments to PR |
conventions-path |
No | docs/conventions |
Path to conventions directory |
review-mode |
No | auto |
Review mode: auto, full, incremental |
* Either api-key or oauth-token is required. If both are provided, oauth-token takes priority.
| Output | Description |
|---|---|
review-report |
Path to the generated review report |
blocking-issues-count |
Number of blocking issues found |
suggestions-count |
Number of suggestions found |
The action looks for conventions in the specified conventions-path directory (default: docs/conventions).
Create these files to customize the review behavior:
global-conventions.md- Global coding standardsproject_conventions.md- Auto-generated from codebase analysis
On the first PR review, the action analyzes your codebase and generates project_conventions.md. This file is cached and used for subsequent reviews.
# Project Coding Conventions
## Language
- TypeScript with strict mode
- ESLint for linting
## Style
- 2 spaces for indentation
- Single quotes for strings
- Semicolons required
## Testing
- Jest for unit tests
- 80% minimum coverageAdd authentication to your repository secrets:
- ANTHROPIC_API_KEY - For API key authentication
- CLAUDE_CODE_OAUTH_TOKEN - For OAuth token authentication (Pro/Max users can generate this by running
claude setup-tokenlocally)
If both are configured, OAuth token takes priority.
- Check that
github-tokenhaspull-requests: writepermission - Verify
PR_NUMBERis available in the workflow context
- Ensure
event-actionissynchronizefor PR updates - Provide
before-shawith the previous commit SHA
# Test the action
bash action.sh <base_sha> <head_sha>auto-code-review/
├── action.yml # Action metadata
├── action.sh # Action entrypoint
├── comment-review.js # PR comment poster
├── prompts/
│ ├── code-analyze.md # Codebase analysis prompt
│ ├── code-review.md # PR review prompt
│ └── generate-json.md # JSON summary generation
└── README.md
MIT