Blog

Claude Code GitHub Actions Integration Guide

How to integrate Claude Code with GitHub Actions for automated PR feedback, issue triage, and code review comments using the official claude-code-action.

Phos Team ·
claude code

Claude Code GitHub Actions Integration Guide

GitHub Actions is where automated workflows live for most development teams. Anthropic’s official claude-code-action brings Claude Code into that environment, enabling AI-assisted review, triage, and feedback as part of the pull request and issue lifecycle.

The integration is not a magic button. It requires deliberate setup, clear prompts, and an understanding of what the action can and cannot reliably do.

This guide covers the full setup and five workflow templates you can adapt immediately.


What the claude-code-action Enables

The claude-code-action is a pre-built GitHub Action that wraps Claude Code’s headless mode for CI/CD for use in standard workflow files. Once configured, it enables:

  • Automated PR feedback. On every pull request open or update, Claude Code reviews the diff and posts structured feedback as a PR comment. The feedback covers what was configured in the prompt: style issues, missing tests, error handling gaps, or security patterns.

  • Issue triage. On new issue creation, Claude Code reads the issue body, compares it against known patterns or a provided FAQ document, and posts an initial response or applies labels. This reduces the time between issue creation and first human response.

  • Code review comments. Rather than a single summary comment, the action can post inline review comments on specific lines of the diff, mimicking the format of human reviewer feedback.

  • Custom workflow triggers. The action supports any GitHub event: push to specific branches, release publication, scheduled runs, or workflow_dispatch for manual triggers. This makes it flexible enough to fit into almost any existing CI/CD structure.

The action is a thin wrapper around Claude Code’s headless capabilities. The quality of the output depends almost entirely on the quality of the prompt, not on the action itself.


Setup Steps

Step 1: Store the API Key as a Secret

Navigate to your repository Settings → Secrets and Variables → Actions. Add a new secret named ANTHROPIC_API_KEY with your Anthropic API key as the value.

For organization-wide deployments, add the secret at the organization level and configure which repositories can access it. This avoids duplicating the key across dozens of repositories.

Step 2: Configure Repository Permissions

The action needs permission to read repository content and write to pull requests or issues. In your workflow file, set the permissions block explicitly:

permissions:
  contents: read
  pull-requests: write
  issues: write

Avoid using permissions: write-all. Scope permissions to exactly what the action needs.

This is both a security best practice and a requirement if your organization uses permission policies that reject over-permissioned workflows.

Step 3: Write the Workflow File

Create a file at .github/workflows/claude-review.yml. The basic structure uses anthropics/claude-code-action@v1 with your ANTHROPIC_API_KEY secret and a prompt field that defines the review behavior:

name: Claude Code Review

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  claude-review:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Claude Code Review
        uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: |
            Review this pull request for:
            1. Missing error handling
            2. Potential null pointer issues
            3. Functions over 50 lines without clear justification
            4. Missing input validation on public-facing functions
            Format findings as a markdown list with severity (high/medium/low).
          github_token: ${{ secrets.GITHUB_TOKEN }}

The prompt field is where the behavior is defined. Treat it as a careful specification, not a rough description.

Step 4: Test on a Non-Critical Repository

Before enabling the workflow on a production repository, run it on a test repository with a few sample PRs. Review the output, adjust the prompt, and confirm the comment format meets your team’s expectations.

A poorly formatted or overly verbose comment creates friction rather than value.

What to check during the pilot:

  • Are findings actionable, or mostly noise?
  • Does severity labeling match your team’s expectations?
  • Is the comment length appropriate for how quickly reviewers will read it?

5 Workflow Templates

These templates cover the most common use cases. Adapt the prompts to your stack and standards.

TemplateTriggerWhat It DoesPrimary Benefit
PR Code Reviewpull_request open/syncReviews diff for bugs, style, error handlingReduces mechanical review burden
Issue Triageissues openedLabels and responds to new issuesFaster first response time
Security Scanpull_request to mainScans for credentials, injection patternsEarly security signal before merge
Changelog Draftrelease publishedGenerates changelog from commits since last tagEliminates manual changelog assembly
Dependency Reviewpull_request with package changesSummarizes new dependencies and flags concernsReduces unreviewed dependency additions

Each template requires a tailored prompt. A generic "review this code" prompt produces generic output.

A prompt that specifies "check for error handling on all database calls and flag any query that does not handle connection timeouts" produces actionable output. For deeper coverage of what each pattern involves:


Limits and Cost Considerations

The claude-code-action is not free to run at scale. Each invocation makes API calls billed by token usage.

Before enabling the action on high-volume repositories, understand the cost model.

Typical token usage per run:

PR SizeLines ChangedEstimated Tokens
SmallUnder 100 lines2,000–5,000
Medium100–500 lines5,000–20,000
LargeOver 500 lines20,000–80,000

For a team merging 30 PRs per week at medium size on average, expect roughly 300,000–600,000 tokens per week just for PR review. Model the cost against your current API pricing tier before rolling out broadly.

Practical limits to set:

  • Diff size check. Add a step before invoking Claude Code that skips the review if the diff exceeds a threshold (1,000 lines is a reasonable starting point). Very large PRs are better reviewed by splitting them.
  • Concurrency limit. If multiple PRs open simultaneously, stagger the review jobs to avoid rate limit errors and unexpected cost spikes.
  • Monthly spend alert. Set a budget alert on your Anthropic API account. Automated pipeline usage can spike unexpectedly during high-activity sprints or mass refactors.

Common Questions on the claude-code-action

Can the action make commits or push code changes to the repository?

The action can be configured with write access to repository contents, which would allow it to commit changes. This is strongly discouraged for automated, non-human-supervised runs.

Reserve contents: write for workflows where a human reviews and approves the proposed change before it is applied. Automated commits to shared branches are a significant source of unexpected production issues.

How do we prevent the action from commenting on the same PR multiple times?

Add logic to check whether a Claude Code comment already exists before posting a new one. The actions/github-script action can query existing comments and skip posting if a previous review comment from the bot is found.

Alternatively, configure the action to update an existing comment rather than creating a new one on each synchronize event.

Does the action support self-hosted runners?

Yes. The action runs as a standard GitHub Actions step and works on self-hosted runners. If your organization uses self-hosted runners for security or compliance reasons, the action is compatible without modification.

Ensure the runner has internet access to reach the Anthropic API endpoint, or configure a proxy if your network policy requires it.

What if we want different prompts for different types of files or directories?

Use path filters in your workflow trigger to run different jobs for different file types. A backend-focused review prompt for changes in /api and a frontend-focused prompt for changes in /src/components gives more relevant output than a single generic prompt applied to all changes.


From Setup to Sustained Value

The claude-code-action is straightforward to configure and fast to deploy. The harder work is writing prompts that produce output your team actually uses, calibrating the cost controls, and building the habit of treating automated comments as a first pass rather than a final verdict.

Teams that get sustained value from this integration treat the initial deployment as a pilot, measure whether developers are acting on the output, and iterate on the prompts based on what they observe. A useful signal: if developers are dismissing more than half of automated comments without acting on them, the prompt needs refinement.

Path one: set it up yourself. The workflow file above is the starting point. Add it to a test repository, run a few PRs through it, and refine the prompt based on the output. The iteration cycle is short when you work on a small, low-risk repository first.

Path two: work with Phos AI Labs. If you want the integration designed for your specific codebase, the prompts calibrated against your team’s standards, and the cost model validated before a broad rollout as part of a broader AI-Native Operations setup, that is the kind of implementation work we do with development teams. Start the conversation here.

Related articles

The fastest way to know whether we're the right fit, is a conversation.

STEP 1/2 · ABOUT YOU