Skip to content

GitHub Integration & PR Reviews

Claude Code works directly with git. It stages changes, writes commit messages, creates branches, and opens pull requests. It can review PRs from a diff, from a PR number, or automatically triggered by GitHub events. This lesson covers the full GitHub integration.

Gnome mascot

What you'll learn

  • claude -p "commit my changes" stages, commits, and writes a descriptive message
  • claude --from-pr 42 reviews a specific PR by number
  • GitHub Actions and GitHub Code Review automate PR reviews on every push

The problem

Manual code review is the bottleneck in every team's workflow. A PR sits for hours waiting for a human to look at it. Claude Code can review PRs in seconds, catching security issues, missing tests, and style violations before a human ever sees the code. The human reviews the review, not the raw diff.

Build it

Step 1: Review a PR from the terminal

Use these terminal commands to instruct Claude to review a specific pull request, either by comparing branches or providing the PR number.

bash
# Review a PR branch against main
claude -p "Review this PR for bugs, security issues, and style problems. Be thorough." \
  --max-turns 10

# Review from a PR number
claude -p "Review this PR thoroughly" --from-pr 42 --max-turns 10

Step 2: Commit and create a PR

In an interactive session:

/commit

Claude stages changes, writes a commit message, and pushes. Or from print mode:

bash
claude -p "commit my changes with a descriptive message following conventional commits"

Step 3: GitHub Actions for automated PR review

Integrate this workflow into your repository to trigger an automated Claude review whenever a pull request is opened or updated.

yaml
# .github/workflows/claude-review.yml
name: Claude Code Review
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: |
          curl -fsSL https://claude.ai/install.sh | bash
          claude -p "Review this PR for bugs, security issues, missing tests, and style problems. Post findings as a PR review." \
            --max-turns 10 --allowedTools "Read,Grep" --output-format json

Step 4: GitHub Code Review (automatic on every PR)

Configure in your repo settings to enable Claude Code's GitHub Code Review integration. Every PR automatically gets a Claude review posted as a comment.

What goes wrong

MistakeHow you notice itThe fix
--from-pr can't find the PRError: PR not foundMake sure you're in the repo directory and the PR number is correct. The branch must exist locally or be fetchable
Commit message is genericClaude writes "update code" instead of a descriptive messageAdd a CLAUDE.md rule: "Use conventional commits format: type(scope): description"
GitHub Actions review fails auth401 error in CISet ANTHROPIC_API_KEY as a GitHub Secret. The OAuth flow doesn't work in CI

Confirm it worked

Run these steps locally to generate a mock change and verify that Claude can successfully format and commit the resulting diff.

bash
# 1. Make a change, commit it
echo "# test" >> README.md
claude -p "commit this change with a conventional commit message"

# 2. Verify the commit
git log -1

# 3. Clean up
git reset HEAD~1

Next: CI/CD Pipelines