Claude Code for GitHub CLI — Workflow Guide
The Setup
You are using the GitHub CLI (gh) to manage pull requests, issues, releases, and workflows directly from the terminal. When paired with Claude Code, gh enables powerful automation — creating PRs with AI-generated descriptions, managing issue triage, and triggering workflows. Claude Code can write gh commands, but it defaults to the GitHub REST API with curl or Octokit instead.
What Claude Code Gets Wrong By Default
-
Uses curl with the GitHub API. Claude writes
curl -H "Authorization: Bearer $TOKEN" https://api.github.com/.... TheghCLI handles authentication automatically and provides simpler commands:gh pr list,gh issue create. -
Installs Octokit for GitHub automation. Claude adds
@octokit/restas a dependency for GitHub operations. For CLI automation,gh apiprovides the same access without code dependencies. -
Opens the browser for PR creation. Claude says “go to github.com to create a PR.” With
gh pr create, you can create PRs entirely from the terminal, including title, body, reviewers, and labels. -
Ignores
gh apifor custom queries. Claude writes raw HTTP requests for GitHub API endpoints. Usegh api repos/{owner}/{repo}/pulls --jq '.[] | .title'for authenticated API access with built-in JSON processing.
The CLAUDE.md Configuration
# GitHub CLI Workflow
## Tool
- CLI: gh (GitHub CLI, authenticated)
- Auth: gh auth login (automatic token management)
- API: gh api for any GitHub REST/GraphQL endpoint
## GitHub CLI Rules
- PRs: gh pr create, gh pr list, gh pr merge, gh pr review
- Issues: gh issue create, gh issue list, gh issue close
- Releases: gh release create v1.0.0 --generate-notes
- Workflows: gh workflow run, gh run list, gh run watch
- API: gh api endpoint --jq 'filter' for custom queries
- Auth: handled automatically, no manual token management
- JSON output: --json fields for machine-readable output
## Conventions
- Use gh for all GitHub operations (not browser or curl)
- PR descriptions in markdown with ## sections
- Labels set with --label flag on create commands
- Reviewers assigned with --reviewer flag
- Use gh pr checks to verify CI before merge
- gh run watch for monitoring workflow execution
- Template PRs with --body-file for consistent formatting
Workflow Example
You want to create a PR with AI-generated description from Claude Code changes. Prompt Claude Code:
“Create a pull request for the current branch with a summary of all changes. Add the ‘enhancement’ label, request review from the team lead, and wait for CI checks to pass.”
Claude Code should run gh pr create --title "..." --body "..." --label enhancement --reviewer teamlead, then gh pr checks --watch to monitor CI status, and report back when checks pass or fail.
Common Pitfalls
-
Not checking CI before merge. Claude runs
gh pr mergeimmediately after creation. Always rungh pr checksfirst to verify CI passes. Usegh pr merge --autoto auto-merge once checks pass. -
Missing
--jqfor API output parsing. Claude pipesgh apioutput throughjqas a separate command. Thegh apicommand has built-in--jqsupport that is more convenient:gh api repos/owner/repo/pulls --jq '.[].title'. -
Draft PRs not marked correctly. Claude creates PRs that are not ready for review without marking them as drafts. Use
gh pr create --draftfor work-in-progress PRs, thengh pr readywhen the PR is ready for review.