GitHub Integration Basics
8 examples to get you started with GitHub Integration & CI - 5 basic and 3 intermediate.
Prerequisites
- Install the
ghCLI (GitHub's official command-line tool) -brew install ghon macOS, or see GitHub's install docs for your platform. - Authenticate it once per machine with
gh auth login, following the interactive prompts to connect your GitHub account. - Run Claude Code from inside a git repository that has a GitHub remote configured, so
ghandgitcommands resolve correctly. - No special Claude Code configuration is required - Claude Code simply runs
ghandgitcommands the same way you would type them yourself.
Basic Examples
1. Check the gh CLI Is Connected
Confirm gh is installed and authenticated before asking Claude Code to use it.
gh auth status- Prints the authenticated account and the token's scopes for the current host.
- Run this once after
gh auth loginand anytime a session's GitHub commands unexpectedly fail. - A missing or expired token is the most common reason a Claude Code session can't open or comment on a PR.
2. View the Current Repository's PRs
List open pull requests before asking Claude Code to act on one of them.
gh pr list- Shows title, branch, and status for every open PR in the current repository.
- Useful context to give Claude Code before pointing it at a specific PR number.
- Add
--state allto include merged and closed PRs in the list.
3. Open a Pull Request from a Session
Ask Claude Code to commit staged changes and open a PR in one step.
git add -A
git commit -m "Add rate limiting to the search endpoint"
gh pr create --title "Add rate limiting to the search endpoint" --body "Fixes #482"gh pr createopens the PR against the repository's default base branch unless you pass--base.--titleand--bodyskip the interactive prompt so the command runs cleanly inside a session.- Claude Code runs this exact sequence when you ask it to "commit this and open a PR."
4. View a Specific PR's Details
Pull the full context of one PR before asking Claude Code to review or update it.
gh pr view 482- Prints title, description, status checks, and review state for PR #482.
- Add
--commentsto include the review comment thread in the output. - Claude Code reads this output to understand what a PR already contains before making changes.
5. Check Out a PR's Branch Locally
Pull a PR's branch into your working directory so Claude Code can edit its files directly.
gh pr checkout 482- Fetches the PR's branch and switches your local working directory to it.
- Required before Claude Code can push a follow-up commit to that exact PR.
- Run
git statusafterward to confirm you're on the expected branch before making changes.
Intermediate Examples
6. Read Review Comments and Push a Fix
Fetch a PR's review comments, then ask Claude Code to address them and push a follow-up commit.
gh pr view 482 --comments
# Ask Claude Code: "Address the review comments on PR #482 and push a fix."
git add -A
git commit -m "Address review feedback: validate rate limit window bounds"
git pushgh pr view --commentssurfaces the reviewer's exact wording so Claude Code can address each point specifically.- The follow-up commit lands on the same branch, so it appears directly in the existing PR - no new PR is created.
- Commit messages that reference what changed (not just "address feedback") make the PR's history easier to skim later.
Related: Responding to PR Review Comments Automatically - the full workflow this example previews.
7. Run Claude Code Headlessly Against a PR
Invoke Claude Code non-interactively to summarize a PR, useful as a first step toward CI automation.
claude -p "Summarize the changes in PR #482 and flag any obvious risks." --output-format text-p(print mode) runs one prompt and exits, without opening the interactive REPL.- This is the same invocation shape a GitHub Actions job uses to run Claude Code headlessly on every PR.
- Useful for testing a review prompt locally before wiring it into CI.
Related: Headless Mode Explained: Running Claude Code Without a Terminal - how this mode works in depth.
8. Leave a Review Comment via gh
Post a comment directly to a PR from the command line, the same call a CI job would make.
gh pr comment 482 --body "Looks good overall - one suggestion: consider caching the rate-limit window lookup."gh pr commentposts a top-level comment on the PR's conversation thread.- This is the exact command an automated review job runs to leave feedback without a human typing it.
- Combine with headless mode output (example 7) to post Claude Code's own review as a PR comment.
Related: Running Claude Code as an Automated Code Review Bot in CI - wiring this into a real CI job.
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5. Model names, pricing, and product features move quickly - verify current specifics at platform.claude.com/docs before relying on them.