Loading

GitHub Actions and Code Review

Lesson 76 min
Loading

GitHub Actions and Code Review

A lot of your busywork lives in the pull request, so it's a good place to hand work to Claude. You can do that in two ways: turn on a managed review service, or set up a GitHub Action yourself.

Which one should you use?

The two solve different problems. Use Code Review for comments on pull requests, and the GitHub Action when Claude should do work in CI.

Code ReviewGitHub Action
What it doesPosts findings on pull requestsRuns any job you'd write a workflow for
Who sets it upAn Owner of your Claude organizationA repo admin
What you needA Team or Enterprise planA way to sign in, such as an API key
What you maintainNothingA workflow file

If you aren't on a Team or Enterprise plan, skip ahead to the GitHub Action.

Turn on Code Review

Code Review runs on Anthropic's infrastructure, so there's nothing to build or host. An Owner of your Claude organization sets it up once:

  1. Start the setup. Open your organization's Code Review settings and click the switch. The setup guide shows each click.
  2. Pick the repos. Install the Claude GitHub app and choose which repos it watches. If you don't own the GitHub organization, an owner has to install and link the app first.
  3. Confirm the setup. If the setup ends in a dialog, Code Review stays off until you confirm it. If you weren't asked to pick repos, add them from the Repositories table.
  4. Set the timing. Each repo starts with a review on every push, which runs the most reviews and costs more. Click Edit on the repo's row to review once when a PR opens, or only when someone comments @claude review.

What Code Review does

A set of review agents checks each diff against your full codebase. They remove duplicates and rank what's left, so you read a handful of real issues. Each one lands as an inline comment with a severity, an explanation, and a suggested fix. The check run sums them up in a table.

By itself, Code Review only comments, so the decision and the fix stay with you. It doesn't approve or block a PR, and it doesn't push fixes. Your repo's GitHub branch rules decide what merges.

To check your fix before you push, run /code-review in your own terminal. That starts a separate review of your diff, and --fix applies that review's findings to your working tree.

Set up the GitHub Action

When the job goes beyond review, use the action, anthropics/claude-code-action@v1. Run /install-github-app in Claude Code, which needs admin rights on the repo. It walks you through installing the GitHub app and saving your Anthropic API key as a repo secret. It can also add workflow files on a new branch, which turn on once you create and merge that pull request.

The prompt input decides when Claude runs. Without one, the action waits for someone to mention @claude. With one, Claude runs as soon as the event fires. The next two workflows show one of each.

Respond to @claude

This workflow has no prompt, so it waits for @claude in PR and issue comments. If setup added a claude.yml, merge that one and don't add a second. Otherwise, save this one as .github/workflows/claude.yml. The id-token: write permission lets the action sign in as the Claude GitHub app:

yaml
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 }}
          claude_args: "--model claude-sonnet-5"

Suppose someone comments @claude implement the spec in the linked GitHub issue on a pull request. The action picks it up, and Claude pushes commits and comments with what it did.

Run on a schedule

This workflow has a prompt, so it runs on its own at 9:00 UTC every day. The workflow_dispatch line also lets you start it by hand from the Actions tab. The prompt names the repo, because this job has no checkout step:

yaml
name: Daily report
on:
  schedule:
    - cron: "0 9 * * *"
  workflow_dispatch:
jobs:
  report:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      issues: read
      id-token: write
    steps:
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: "Generate a summary of yesterday's commits and open issues in ${{ github.repository }}"
          claude_args: |
            --permission-mode dontAsk
            --allowedTools "mcp__github__list_commits,mcp__github__list_issues"

A scheduled run doesn't post a comment on its own. You read the result in the run's log, in the Actions tab.

Limit what a run can do

No one is at the keyboard during a run, so give each job only what it needs. The claude_args input passes CLI arguments straight to Claude Code, and three of them set the limits:

  • --max-turns caps the agent loop, so it can't run forever. A run that goes over the cap fails. So leave room, because even a small @claude code change can take more than five turns.
  • --allowedTools lists the tools Claude can use without asking. For a report, list only read-only tools.
  • --permission-mode dontAsk denies anything else that needs approval. Use it on a job like the report, because it would also deny file edits you haven't listed. Without it, the action defaults to auto mode, where a safety review can let unlisted tools through.

Adapt it to your setup

Both workflows sign in with an API key and act as the Claude GitHub app. If your setup differs, start from these inputs:

If you want toUse
Sign in with a Claude subscriptionclaude_code_oauth_token
Store no secretWorkload identity federation, set up through a Claude Console service account
Run on Amazon Bedrockuse_bedrock: "true"
Run on Google Cloud's Agent Platformuse_vertex: "true"
Run on Microsoft Foundryuse_foundry: "true"
Act as something other than the appgithub_token
Listen for a different phrasetrigger_phrase

With a subscription, point that input at the CLAUDE_CODE_OAUTH_TOKEN secret and remove the API key line. With a cloud provider, you sign in with your cloud account, which takes a few more setup steps. If you change the trigger phrase, change the workflow's if line to match.

Key takeaways

  • Turn on Code Review when you want findings on pull requests with nothing to maintain.
  • Set up the action when Claude should make changes or run on a schedule.
  • Use claude_args to limit what each run can do.