| name | gh-cli |
| description | Interact with GitHub via the gh CLI for PRs, issues, releases, Actions, and API calls. Use when performing any GitHub operation such as creating PRs, viewing issues, checking CI status, making API requests, or managing releases. |
GitHub CLI (gh)
Prerequisites
- User is already authenticated (
gh auth login completed)
- All
gh commands require required_permissions: ["full_network"] in the Shell tool
Pull Requests
gh pr create --title "feat: add caching layer" --body "$(cat <<'EOF'
## Summary
- Added Redis caching for API responses
- Cache TTL configurable via env var
## Test plan
- [ ] Unit tests pass
- [ ] Manual smoke test
EOF
)"
gh pr list
gh pr view 42
gh pr view 42 --web
gh pr checks 42
gh pr diff 42
gh pr merge 42
gh pr merge 42 --squash --delete-branch
gh pr review 42 --approve
gh pr review 42 --request-changes --body "Needs error handling"
gh pr checkout 42
Issues
gh issue create --title "Bug: login fails on Safari" --body "Steps to reproduce..."
gh issue create --title "..." --label bug --label urgent --assignee @me
gh issue list
gh issue list --label bug --state closed
gh issue view 99
gh issue comment 99 --body "Fixed in PR #42"
gh issue close 99
gh issue develop 99 --checkout
GitHub Actions
gh run list
gh run list --workflow ci.yml
gh run view <run-id>
gh run watch <run-id> --exit-status
gh run download <run-id>
gh run rerun <run-id> --failed
Releases
gh release create v1.2.0 --title "v1.2.0" --notes "Release notes here"
gh release create v1.2.0 --generate-notes
gh release upload v1.2.0 ./dist/*.tar.gz
gh release list
gh release view v1.2.0
API (REST and GraphQL)
Use gh api for anything not covered by top-level commands. Placeholders {owner}, {repo}, {branch} auto-resolve from the current repo.
gh api repos/{owner}/{repo}
gh api repos/{owner}/{repo}/issues --jq '.[].title'
gh api repos/{owner}/{repo}/issues/123/comments -f body='Automated comment'
gh api -X PATCH repos/{owner}/{repo}/issues/123 -f state=closed
gh api repos/{owner}/{repo}/commits --paginate --jq '.[].sha'
gh api graphql -f query='
query {
repository(owner: "{owner}", name: "{repo}") {
issues(first: 5, states: OPEN) {
nodes { title number }
}
}
}
'
gh api repos/{owner}/{repo}/dispatches --input payload.json
Search
gh search issues "memory leak" --repo cli/cli
gh search prs "auth" --state open --repo myorg/myrepo
gh search code "TODO" --repo {owner}/{repo}
gh search repos "language:lua stars:>100"
Cross-Repository Operations
Add -R OWNER/REPO to target a different repository:
gh pr list -R cli/cli
gh issue view 500 -R vercel/next.js
gh api repos/vercel/next.js/releases --jq '.[0].tag_name'
Output Formatting
gh pr list --json number,title,author --jq '.[] | "\(.number) \(.title) by \(.author.login)"'
gh pr list --json number,title --template '{{range .}}#{{.number}} {{.title}}{{"\n"}}{{end}}'
gh pr view 42 --web
gh repo view --web
Tips
- Prefer
--json + --jq to extract structured data programmatically
- Use
gh api with --paginate --slurp for collecting all pages into one array
gh pr create --fill auto-fills title/body from commits (useful for single-commit PRs)
gh run watch --exit-status exits with non-zero if the run fails (useful for scripting)