| name | github-cli |
| description | Use the `gh` CLI for all GitHub interactions — issues, PRs, discussions, releases, repos, Actions, and API calls. Prefer `gh` over direct web browsing, web search, or raw git/HTTPS API calls whenever the target is on GitHub. Avoid cloning repos to read files; use `gh api` or `gh repo view` instead. |
| user-invocable | false |
GitHub CLI (gh)
The gh CLI is the preferred way to interact with GitHub from this environment.
It handles authentication, pagination, JSON output, and API discovery automatically.
Always use gh instead of opening GitHub URLs in a browser, using curl against the REST/GraphQL API, or cloning
repos just to read files.
General Principles
- Prefer
gh over web tools — When the information lives on GitHub
(issues, PRs, discussions, repos, releases, Actions, etc.),
use gh commands rather than web_search or web_extract.
- Avoid cloning for reading — Use
gh api, gh repo view,
or gh browse to inspect remote files and metadata without a local clone.
Only clone when you need to build, test, or modify code.
- Use
--json and jq — Structured output is easier to parse than human-readable text.
Pipe through jq for filtering.
- Paginate with
--limit or --jq — gh auto-paginates; use --limit to cap results.
Repository Operations
View repo info & files without cloning
gh repo view owner/repo --json name,description,defaultBranchRef,url
gh api repos/owner/repo/contents/path/to/dir --jq '.[].name'
gh api repos/owner/repo/contents/path/to/file --jq '.content' | base64 -d
gh api "repos/owner/repo/contents/README.md?ref=main" --jq '.content' | base64 -d
Clone only when necessary
gh repo clone owner/repo -- --depth=1
gh repo clone owner/repo -- --branch=develop --single-branch
Issues
gh issue list -R owner/repo --state open --limit 20
gh issue view 123 -R owner/repo --comments
gh issue create -R owner/repo --title "Bug: something broke" --body "Details here"
gh search issues "keyword" --owner owner --limit 10
gh issue list -R owner/repo --state open --json number,title,labels,assignees
Pull Requests
gh pr list -R owner/repo --state open --limit 20
gh pr view 456 -R owner/repo --comments
gh pr diff 456 -R owner/repo
gh pr checkout 456 -R owner/repo
gh pr create -R owner/repo --title "feat: new thing" --body "Description" --base main
gh pr review 456 -R owner/repo --approve --body "LGTM"
gh pr review 456 -R owner/repo --request-changes --body "Please fix X"
gh pr merge 456 -R owner/repo --squash --delete-branch
Discussions
gh api graphql -f query='
query {
repository(owner:"owner", name:"repo") {
discussions(first:10) {
nodes { number title url }
}
}
}
'
gh api graphql -f query='
query {
repository(owner:"owner", name:"repo") {
discussion(number:42) {
title body comments(first:20) { nodes { body author { login } } }
}
}
}
'
Releases & Tags
gh release list -R owner/repo --limit 10
gh release view v1.2.3 -R owner/repo
gh release download v1.2.3 -R owner/repo -D ./downloads
gh release create v1.2.3 -R owner/repo --title "v1.2.3" --notes "Release notes here"
GitHub Actions (CI/CD)
gh run list -R owner/repo --limit 10
gh run view 789 -R owner/repo
gh run rerun 789 -R owner/repo
gh run view 789 -R owner/repo --log
gh run watch 789 -R owner/repo
Direct API Access (gh api)
For anything not covered by a dedicated gh command, use gh api to hit any REST endpoint.
Authentication and headers are handled automatically.
gh api repos/owner/repo/labels
gh api repos/owner/repo/labels \
-f name="bug" -f color="ff0000"
gh api repos/owner/repo/stargazers --paginate --jq '.[].login'
gh api graphql -f query='query { viewer { login } }'
Gists
gh gist create file.txt --public
gh gist view abc123
gh gist edit abc123 file.txt
Tips & Tricks
-R owner/repo — Works from any directory; no need to be inside a clone.
--json field1,field2 — Always prefer structured JSON output for programmatic use.
--jq '.field' — Chain with jq expressions for inline filtering.
--web — Opens the GitHub UI in a browser as a last resort (e.g., to show the user something visually).
gh api --paginate — Automatically follows Link headers to fetch all pages.
- Combine with bash tools — Pipe
gh output into jq, grep, sort, wc, etc. for analysis.
Decision Guide
| Task | Use This |
|---|
| Read a file in a GitHub repo | gh api repos/owner/repo/contents/path |
| Browse repo tree | gh api repos/owner/repo/git/trees/main?recursive=1 |
| Search issues/PRs | gh search issues "query" --owner owner |
| Read an issue thread | gh issue view N -R owner/repo --comments |
| Read a PR thread + diff | gh pr view N -R owner/repo --comments + gh pr diff N |
| Check CI status | gh run list -R owner/repo --limit 5 |
| View release notes | gh release view v1.2.3 -R owner/repo |
| Clone for building/editing | gh repo clone owner/repo -- --depth=1 |
| Anything else on GitHub | gh api ... |