| name | gh |
| description | Use this skill when the user asks about GitHub operations, pull requests, issues, releases, actions, gists, repos, or any task involving the GitHub CLI (gh). Also use when needing to interact with GitHub APIs, check CI status, review PRs, manage labels, create releases, or automate GitHub workflows from the command line.
|
gh - GitHub CLI
The GitHub CLI (gh) brings GitHub workflows to the terminal. It provides
commands for pull requests, issues, repos, actions, and direct API access.
Web Sessions
In Claude Code web sessions, the git remote is a local proxy, not github.com. The gh CLI infers the host and repo from the remote, so subcommands like gh pr create would fail without configuration.
The proxy remote URL looks like this (the trailing owner/repo is what the hook extracts for GH_REPO):
http://local_proxy@127.0.0.1:<port>/git/nsheaps/ai-mktpl
Solution: GH_HOST and GH_REPO Environment Variables
The github plugin's SessionStart hook automatically sets GH_HOST and GH_REPO in web sessions. Once set, all standard gh subcommands work normally:
gh pr create --draft --title "Add feature X" --body "Description"
gh pr list
gh pr view 123
gh issue create --title "Bug: X" --body "Details"
gh issue list --label "bug"
gh run list
gh run view 12345 --log
If for some reason the env vars are not set (e.g., hook didn't run), set them manually:
export GH_HOST="github.com"
export GH_REPO="owner/repo"
Reference: https://cli.github.com/manual/gh_help_environment
Fallback: gh api
For edge cases or direct API access, gh api with --hostname github.com always works:
gh api repos/OWNER/REPO/pulls --hostname github.com --jq '.[].title'
Quick Reference
Authentication
gh auth status
gh auth login
echo "$GH_TOKEN" | gh auth login --with-token
gh auth switch
Git Identity Setup
After authenticating with gh, configure git user identity from the GitHub profile:
gh auth setup-git
gh api user --jq '.name' | xargs git config user.name
gh api user --jq '.email // .login + "@users.noreply.github.com"' | xargs git config user.email
For GitHub App bot accounts (automated/CI), the identity follows the convention:
git config user.name "my-app[bot]"
git config user.email "12345+my-app[bot]@users.noreply.github.com"
To find the App's bot user ID:
gh api users/my-app[bot] --jq '.id'
Core Commands
| Command | Description |
|---|
gh pr create | Create a pull request |
gh pr view | View PR details |
gh pr list | List pull requests |
gh pr merge | Merge a pull request |
gh pr checkout | Checkout a PR branch |
gh issue create | Create an issue |
gh issue list | List issues |
gh issue view | View issue details |
gh repo clone | Clone a repository |
gh run list | List workflow runs |
gh run view | View workflow run details |
gh api | Make authenticated API calls |
Pull Request Workflows
Creating PRs
gh pr create --title "Add feature X" --body "Description here"
gh pr create --title "Fix bug Y" --body "$(cat <<'EOF'
## Summary
- Fixed the thing
## Test plan
- [ ] Unit tests pass
EOF
)"
gh pr create --draft --title "WIP: Feature Z"
gh pr create --base develop --title "Feature for develop"
gh pr create --fill
gh pr create --title "Fix" --label "bug" --reviewer "username"
Reviewing PRs
gh pr view 123
gh pr view 123 --json title,body,reviews,mergeable
gh pr diff 123
gh pr view 123 --json files --jq '.files[].path'
gh pr checks 123
gh api repos/{owner}/{repo}/pulls/123/comments
gh pr review 123 --comment --body "LGTM!"
gh pr review 123 --approve
gh pr review 123 --request-changes --body "Please fix X"
Managing PRs
gh pr list
gh pr list --author "@me"
gh pr list --label "needs-review"
gh pr merge 123
gh pr merge 123 --squash
gh pr merge 123 --rebase
gh pr merge 123 --auto --squash
gh pr close 123
gh pr checkout 123
Issue Workflows
Creating Issues
gh issue create
gh issue create --title "Bug: X crashes" --body "Steps to reproduce..."
gh issue create --title "Feature request" --label "enhancement" --label "priority:high"
gh issue create --title "Fix Y" --assignee "@me"
Managing Issues
gh issue list
gh issue list --label "bug"
gh issue list --assignee "@me"
gh issue view 42
gh issue close 42 --comment "Fixed in #123"
gh issue edit 42 --title "New title" --add-label "status:in-progress"
gh issue comment 42 --body "Working on this"
Repository Operations
gh repo clone owner/repo
gh repo create my-project --public --clone
gh repo fork owner/repo --clone
gh repo view owner/repo
gh repo list owner --limit 20
gh repo edit --enable-auto-merge --delete-branch-on-merge
GitHub Actions
gh run list
gh run view 12345
gh run view 12345 --log
gh run watch 12345
gh run rerun 12345
gh run rerun 12345 --failed
gh workflow run ci.yaml --ref main
gh workflow list
gh workflow view ci.yaml
GitHub API Access
The gh api command provides authenticated access to any GitHub API endpoint.
Common API Patterns
gh api repos/owner/repo
gh api repos/owner/repo --jq '.description'
gh api repos/owner/repo/labels -f name="priority:critical" -f color="FF0000"
gh api repos/owner/repo/issues/42 -X PATCH -f state="closed"
gh api repos/owner/repo/labels/old-label -X DELETE
gh api repos/owner/repo/issues --paginate --jq '.[].title'
gh api graphql -f query='
query {
repository(owner: "owner", name: "repo") {
pullRequests(first: 10, states: OPEN) {
nodes { title number }
}
}
}
'
Useful API Endpoints
gh api repos/owner/repo/contents/path/to/file --jq '.content' | base64 -d
gh api repos/owner/repo/pulls/123/comments
gh api repos/owner/repo/commits/SHA/status
gh api repos/owner/repo/topics --jq '.names[]'
gh api search/code -f q="pattern repo:owner/repo" --jq '.items[].path'
gh api repos/owner/repo/dispatches -f event_type="deploy" -f client_payload='{"env":"prod"}'
Releases
gh release create v1.0.0 --title "Version 1.0.0" --notes "Release notes"
gh release create v1.0.0 --generate-notes
gh release create v1.0.0 --draft
gh release upload v1.0.0 ./dist/app-linux-x64.tar.gz
gh release list
gh release download v1.0.0 --pattern "*.tar.gz"
gh release delete v1.0.0 --yes
Gists
gh gist create file.txt --public --desc "My gist"
echo "content" | gh gist create --filename notes.md
gh gist list
gh gist view GIST_ID
gh gist edit GIST_ID
Configuration and Aliases
gh config set editor vim
gh config set browser false
gh alias set co 'pr checkout'
gh alias set mine 'issue list --assignee @me'
gh alias list
Output Formatting
gh pr list --json number,title,author
gh pr list --json number,title --jq '.[].title'
gh pr list
gh pr view 123 --web
gh issue view 42 --web
Plugin Settings
This plugin supports configuration via plugins.settings.yaml:
github:
enabled: true
autoInstall: true
installToProject: true
backgroundInstall: false
version: "latest"
autoAuthCheck: true
Place in:
$CLAUDE_PROJECT_DIR/.claude/plugins.settings.yaml (project-level)
~/.claude/plugins.settings.yaml (user-level)
Environment Variables
| Variable | Description |
|---|
GH_TOKEN | Authentication token (overrides gh auth login) |
GH_HOST | GitHub hostname (for GitHub Enterprise) |
GH_REPO | Default repo in owner/repo format |
GH_EDITOR | Editor for interactive commands |
GH_BROWSER | Browser for --web commands |
GH_DEBUG | Set to enable debug logging |
NO_COLOR | Disable color output |
Troubleshooting
Authentication issues
gh auth status
gh auth login
gh auth status -t
"gh: command not found" in web sessions
This plugin auto-installs gh to $CLAUDE_PROJECT_DIR/bin/.local/gh.
Check that the session start hook ran successfully.
Rate limiting
Use authenticated requests (default with gh) to get 5,000 req/hour
instead of 60. For heavy API usage, check remaining:
gh api rate_limit --jq '.rate'
Working with GitHub Enterprise
GH_HOST=github.mycompany.com gh auth login