How to Run Claude Code in GitHub Actions to Review Pull Requests (Step-by-Step)
Every small team I work with has the same bottleneck: pull requests sit for a day because the one person who knows the codebase is busy. You can't clone that person, but you can get a careful first pass on every PR before a human looks at it. In this tutorial, you'll set up Claude Code in GitHub Actions so it reviews each pull request automatically and leaves inline comments on the lines that need attention.
What you'll build: two small workflow files. The first runs a review whenever a PR is opened or updated. The second lets anyone with write access type @claude in a PR comment to ask a follow-up question or request a fix. You'll also add a short CLAUDE.md so the reviews follow your team's rules instead of generic advice.
ANTHROPIC_API_KEY (or CLAUDE_CODE_OAUTH_TOKEN) repository secret, then add a workflow that runs anthropics/claude-code-action@v1 on pull_request events with a review prompt and the inline-comment tool allowed. Running /install-github-app inside Claude Code does all three for you.Pick the Right Option First
Anthropic ships three ways to get Claude reviewing code, and they're easy to mix up. This tutorial covers the first one, because it works on any plan and you control every setting.
| Option | Where it runs | Who can use it |
|---|---|---|
| Claude Code GitHub Action (this guide) | Your GitHub Actions runners | Anyone with an API key or a Pro, Max, Team or Enterprise subscription token |
| Code Review (managed) | Anthropic infrastructure, no workflow file | Team and Enterprise organizations, once an Owner turns it on |
/code-review command | Your local Claude Code session | Anyone, on any plan |
Prerequisites
- A repository on github.com where you have admin access (needed to install the app and add secrets).
- Either a Claude API key from the Claude Console, or a Claude subscription (Pro, Max, Team or Enterprise) so you can generate an OAuth token.
- Claude Code installed locally if you want the quick setup path, plus the GitHub CLI (
gh). - GitHub Actions enabled for the repo. Runs use your Actions minutes.
Step 1: Try the Quick Setup With /install-github-app
If you already use Claude Code, this is the fastest route. It only works for repositories hosted on github.com.
- Sign in to the GitHub CLI if you haven't yet.
gh auth login
- Open Claude Code inside your repository and run the setup command.
cd my-project
claude
> /install-github-app
- When the Claude GitHub App page opens in your browser, install it and give it access to this repo. Go back to the terminal and press Enter.
- Choose Set up GitHub Actions workflows. Keep both the
@claudementions workflow and the pull request review workflow selected. - Pick a credential: a long-lived token from your Claude subscription, or an API key. Claude Code saves it as a repository secret named
CLAUDE_CODE_OAUTH_TOKENorANTHROPIC_API_KEY. - Confirm with Yes, make these changes. Claude Code pushes a branch with the workflow files and opens a pull request. Merge it, and the workflows are live.
When I set this up on a fresh repo, quick setup is all I need. The manual steps below are for when the command fails, when you don't run Claude Code locally, or when you want to edit the review prompt yourself (which you will, eventually).
Step 2: Install the App and Add the Secret Manually
Install the Claude GitHub App on your repository. The action relies on three of its permissions: Contents, Issues and Pull requests (read and write). The app also asks for other permissions that features like the managed Code Review use, and GitHub doesn't let you accept only a subset. If your company needs a tighter set, Anthropic's setup guide explains how to create a custom GitHub App with just those three.
Next, add one repository secret under Settings > Secrets and variables > Actions:
ANTHROPIC_API_KEY: an API key from the Claude Console. Billed per token.CLAUDE_CODE_OAUTH_TOKEN: a token tied to your Claude subscription. Generate it locally with the command below.
claude setup-token
For a secret shared across many repos in an organization, use an API key. An OAuth token belongs to the subscription of whoever ran claude setup-token, so it walks out the door with that person.
Step 3: Add the Automatic PR Review Workflow
Create .github/workflows/claude-code-review.yml. This version uses Anthropic's official code-review plugin, which is the same one quick setup installs. It runs on every opened, updated, reopened or ready-for-review PR.
name: Code Review
on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
plugin_marketplaces: "https://github.com/anthropics/claude-plugins-official.git"
plugins: "code-review@claude-plugins-official"
prompt: "/code-review:code-review --comment ${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
claude_args: '--allowedTools "mcp__github_inline_comment__create_inline_comment"'
Two lines decide where the review ends up:
--commenttells Claude to post on the PR: an inline comment for each issue, or one summary comment if it finds nothing. Leave it out and the findings only appear in the workflow run log.claude_argsmust name the inline-comment tool. The action only starts the MCP server that posts inline comments when--allowedToolslists it.
The plugin skips drafts, closed PRs, PRs that already have a comment from Claude, and ones it judges too trivial to need a review. If you use a subscription token, swap the anthropic_api_key line for claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}.
Step 4 (Optional): Write Your Own Review Prompt
The plugin is a good default. But for client projects I usually want the review to focus on a few things that actually bite that team, like missing input validation or unhandled API errors. A plain-text prompt gives you that control. Here's the version I start from:
name: Claude PR Review (custom)
on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
concurrency:
group: claude-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
track_progress: true
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number }}
Review only the changes in this pull request.
Follow the review rules in CLAUDE.md.
Focus on bugs, missing error handling, security problems
and missing tests. Skip style nitpicks a linter would catch.
Use inline comments for specific lines and one top-level
comment with a short summary.
claude_args: |
--max-turns 10
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
What each addition does:
concurrencycancels the older run when someone pushes again, so you don't pay for a review of code that's already been replaced.timeout-minutesand--max-turnscap how long a single review can run. Both are cost controls Anthropic recommends.track_progressadds a tracking comment with checkboxes that updates as the review moves along.--allowedToolsis required here. With a plain-text prompt, Claude has no shell or GitHub access until you grant it. These four tools let it read the diff and post comments, nothing more.
Use either Step 3 or Step 4, not both, or every PR gets reviewed twice.
Step 5: Tell Claude Your Review Rules in CLAUDE.md
Claude reads a CLAUDE.md file in the repository root on every run. Keep it short, since a long file costs tokens on every single review. Here's a sample for a small web app:
# Review rules
- Every new API route must validate its input before touching the database.
- Never log full request bodies (they can contain customer emails).
- New functions in src/billing/ need a unit test in tests/billing/.
- Flag any hard-coded secret, token or URL with credentials.
- Don't comment on formatting. Prettier handles that.
If you've already built reusable commands for your team, the same ideas carry over. My guide on creating custom slash commands in Claude Code shows how to package a review checklist as a skill, and you can call a repo skill from the action by passing /skill-name as the prompt (check out the repo first so the skill files exist on the runner).
Step 6: Add @claude Mentions for Follow-Ups
Automatic reviews are a one-way street. To let your team ask Claude questions inside a PR, add .github/workflows/claude.yml:
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
claude:
if: contains(github.event.comment.body, '@claude')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: read
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
Because there's no prompt input, the action runs in interactive mode and waits for the trigger phrase. The actions: read permission lets Claude read CI results on the PR. Now a reviewer can reply to one of Claude's inline comments with something like:
@claude why is this a problem? Show me the fix.
@claude add a unit test for the empty-cart case
Claude answers in the same thread and can push commits to the branch. That's a lot of power, so only people with write access can trigger it by default, and bots are blocked unless you list them in allowed_bots.
Step 7: Test It on a Real Pull Request
- Create a branch and make a small change with an obvious problem, like a function that divides by a value that can be zero.
- Open a PR (not a draft) against your default branch.
- Open the Actions tab and watch the review job. A first run usually takes a few minutes.
- Check the PR's Files changed tab for inline comments, then reply with
@claudeto test the second workflow.
If you also want Claude to tidy formatting before code ever reaches a PR, pair this with Claude Code hooks that auto-format after every edit. Then the review can stick to logic instead of whitespace.
Keep the Costs Under Control
Each run spends GitHub Actions minutes plus Claude usage: API tokens if you use a key, or your subscription limits if you use an OAuth token. The levers that matter most:
- Cap work with
--max-turnsand a jobtimeout-minutes. - Use
concurrencyso pushes cancel stale reviews. - Add a
paths:filter underpull_requestso docs-only PRs don't trigger a review. - Keep
CLAUDE.mdtight, since it's read on every run.
Troubleshooting
The workflow runs but no comments appear
Check two things. With the plugin workflow, the prompt needs --comment. With either workflow, --allowedTools must include mcp__github_inline_comment__create_inline_comment. Without it, the findings land only in the run log.
Nothing happens on pull requests from forks
On public repositories, GitHub withholds secrets from workflows triggered by fork PRs, so the review only runs for branches inside the same repo. That's a GitHub security rule, not a bug.
Claude ignores @claude comments
Confirm the app is installed on the repo, workflows are enabled, and the secret exists. The comment must contain @claude as a whole word (not @claude-bot), and the person commenting needs write access.
CI doesn't run on commits Claude pushes
GitHub doesn't trigger workflows on commits made with the default GITHUB_TOKEN. If you passed github_token: ${{ secrets.GITHUB_TOKEN }} to the action, remove it so it authenticates as the Claude GitHub App.
Authentication errors
Test the key or token locally with claude first. If an old workflow still uses @beta, change it to @v1, replace direct_prompt with prompt, and move options like max_turns and model into claude_args.
Frequently Asked Questions
Is the Claude Code GitHub Action free?
The action itself is open source, but each run uses GitHub Actions minutes and Claude usage. With an API key you pay per token. With a CLAUDE_CODE_OAUTH_TOKEN, runs count against your Claude subscription instead.
Can Claude Code approve or merge my pull request?
The review workflows in this guide only comment. A human still decides what gets merged. The @claude workflow can push commits when asked, so review those changes like any other teammate's.
What's the difference between this and Claude Code Review?
Code Review is a managed service for Team and Enterprise organizations that runs on Anthropic's infrastructure without a workflow file. The GitHub Action runs on your runners, works on any plan, and lets you edit the prompt, model and triggers.
Does it work with GitLab or Bitbucket?
No. /install-github-app only supports github.com repositories. For GitLab, Anthropic has a separate Claude Code GitLab CI/CD integration.
Can I choose which Claude model reviews my code?
Yes. Add --model with a model name to claude_args. Without it, the action uses Claude Code's default model.
Wrapping Up
Two workflow files and a short CLAUDE.md give you a reviewer that never takes a day off. Start with the plugin workflow, watch a week of reviews, then switch to a custom prompt once you know what you want it to catch. If you want to build automations outside GitHub, my Claude Agent SDK invoice-reminder agent tutorial uses the same SDK this action is built on.
Want this built for your business?
I'm Basant, an AI automation consultant. Book a call: https://topmate.io/basant_narayan_singh. See more of my work at singhbasant.com.
Join the conversation