GitHub Integration Best Practices
Proven patterns for using Claude Code safely and effectively across pull requests and CI pipelines, from opening a PR by hand to running a fully automated review bot.
Search across all documentation pages
Proven patterns for using Claude Code safely and effectively across pull requests and CI pipelines, from opening a PR by hand to running a fully automated review bot.
gh once per environment and verify it before relying on it. Run gh auth status after gh auth login, and re-check it whenever a session's GitHub commands unexpectedly fail.gh and git commands you'd type yourself. There's no separate "Claude Code GitHub feature" to learn - understanding the underlying gh pr create, gh pr view, and gh pr comment commands makes it easy to verify what a session actually did.git status or git branch --show-current avoids committing changes to the wrong branch, especially after checking out a PR for follow-up work.Fixes #<number> or Refs #<number> in the PR body so GitHub links and auto-closes the issue on merge.gh api, not just gh pr view --comments. The API endpoint returns the file and line each comment refers to, which top-level view output doesn't always surface clearly.gh pr view --json commits rather than assuming a push succeeded before pinging reviewers again.claude -p "..." command from a terminal first to validate the prompt and output format before putting it in a GitHub Actions workflow.permissions block explicitly. Grant only what the job needs - typically contents: read and pull-requests: write for a review job - rather than relying on broader default token permissions.pull_request, not pull_request_target, unless you specifically need and understand the trade-off. pull_request_target can expose repository secrets to code from a forked PR if not handled carefully.timeout-minutes setting at the job level prevents a hung invocation from tying up runner minutes indefinitely.synchronize in the workflow's pull_request event types so later commits get reviewed too, not just the PR's initial state.Storing the Anthropic API key as a proper GitHub Actions secret and scoping the workflow's permissions explicitly - a leaked key or an overly broad token turns a convenience feature into a real security exposure.
Yes, though the risks differ - interactive usage mistakes tend to cost time (wrong branch, unclear PR body), while CI mistakes tend to cost security exposure (leaked secrets, overly broad permissions).
Because they apply at different points in the workflow and carry different risks - a gh habit mistake wastes a few minutes, while a CI security mistake can expose credentials to every future run of the job.
Occasionally, when a job genuinely needs secret access even for forked-PR runs, but only with a clear understanding of the trust boundary being crossed - pull_request is the safer default absent that specific need.
Whenever it consistently misses or over-flags a category of issue - treat the prompt as living guidance that improves with feedback, not a one-time setup task.
Reviewers start skimming past or ignoring its comments entirely, usually because it comments on every PR regardless of whether the diff is actually clean - the fix is adding an explicit "stay quiet when clean" instruction.
Yes - a timeout-minutes setting is cheap insurance against a hung headless invocation consuming runner minutes indefinitely.
No - it's designed to run alongside a team's existing review process and branch protection rules, adding a fast first-pass signal rather than replacing the human gate.
It widens the blast radius unnecessarily - if the job or its dependencies were ever compromised, a write-scoped token can do more damage than a read-scoped one that can't modify the repository.
Yes - it's the fastest way to validate the prompt wording and output format, since debugging a misbehaving prompt is much slower once it's wrapped inside a full GitHub Actions run.
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.
Reviewed by Chris St. John·Last updated Jul 18, 2026