Blog/Claude AI
Development · Claude + GitHub

How to Connect Anthropic Claude with GitHub

PL
Prashant Lalwani
April 08, 2026 · 11 min read
Dev · Claude Code · GitHub Actions
GitHub Push · PR · Actions on: pull_request jobs: claude-review trigger Claude API claude-sonnet-4 ANTHROPIC_API_KEY Review PR diff Post comment Auto Review Posted on PR ✓ Bugs detected ✓ Suggestions added GitHub Actions + Claude API Integration AUTO CODE REVIEW ON EVERY PR · NEURA PULSE 2026

Connecting Claude to GitHub transforms your development workflow in ways that feel like having a senior engineer reviewing every single commit. In 2026, the two main approaches are: using Claude Code (Anthropic's dedicated coding CLI), or building custom GitHub Actions workflows that call the Claude API for automated code review, documentation generation, and test writing on every pull request.

Two Approaches

Claude Code (CLI): Interactive coding assistant in your terminal. Directly edits files, runs commands, reads your repo. GitHub Actions + API: Automated review bot that comments on every PR, runs on push, requires no developer interaction.

Method 1 — Claude Code CLI

Claude Code is Anthropic's official command-line tool that gives Claude direct access to your codebase. It can read files, make edits, run tests, and push commits — turning it into an agentic developer that works inside your repository.

1

Install Claude Code

Requires Node.js 18+. Run the install command from your terminal. You'll authenticate with your Anthropic API key on first launch.

2

Open Your Repo Directory

Navigate to your project root and launch Claude Code. It immediately reads your file structure and understands the codebase context.

3

Give Natural Language Instructions

"Review the auth module for security issues", "Write unit tests for the payment service", "Refactor this function to use async/await" — Claude makes the changes directly.

Install Claude Code
# Install globally via npm
npm install -g @anthropic-ai/claude-code

# Launch in your project directory
cd my-project
claude

# Example commands inside Claude Code
> Review this PR diff for bugs and security issues
> Write tests for src/api/users.js
> Update the README to reflect recent changes

Method 2 — GitHub Actions Auto-Review Bot

For teams that want Claude reviewing every PR automatically without any manual steps, a GitHub Actions workflow is the answer. On every pull request, the workflow extracts the diff, sends it to Claude API, and posts the review as a PR comment — all without any developer needing to interact with Claude directly.

GitHub Actions Workflow — .github/workflows/claude-review.yml
name: Claude Code Review
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  claude-review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Get PR diff
        run: |
          git diff origin/${{ github.base_ref }}...HEAD \
            > pr_diff.txt

      - name: Review with Claude
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: |
          DIFF=$(cat pr_diff.txt)
          RESPONSE=$(curl -s https://api.anthropic.com/v1/messages \
            -H "x-api-key: $ANTHROPIC_API_KEY" \
            -H "anthropic-version: 2023-06-01" \
            -H "content-type: application/json" \
            -d "{
              \"model\": \"claude-sonnet-4-20250514\",
              \"max_tokens\": 1024,
              \"messages\": [{
                \"role\": \"user\",
                \"content\": \"Review this PR diff for bugs, security issues, and improvements:\n\n$DIFF\"
              }]
            }")
          echo "$RESPONSE" > review.json

      - name: Post review comment
        uses: actions/github-script@v7
        with:
          script: |
            // Parse and post Claude's review as PR comment
            const review = require('./review.json');
            const body = review.content[0].text;
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo, body
            });

Setting Up Your API Key in GitHub Secrets

1

Get API Key

Go to console.anthropic.com → API Keys → Create new key. Copy it immediately (shown only once).

2

Add to GitHub Secrets

In your repo: Settings → Secrets and variables → Actions → New repository secret. Name it ANTHROPIC_API_KEY.

3

Test the Workflow

Open a test PR with a small change. The Actions tab will show the Claude review workflow running. After completion, Claude's review appears as a comment on the PR.

Cost Control Tip

Add a diff size check before calling Claude — skip the API call if the diff is less than 50 lines (trivial changes). This prevents API costs from piling up on formatting-only commits while keeping reviews on meaningful code changes.