Asi using-gh-cli
Guides usage of the GitHub CLI (gh) for interacting with GitHub repositories, PRs, issues, and API. Use when working with GitHub resources instead of WebFetch or curl.
install
source · Clone the upstream repo
git clone https://github.com/plurigrid/asi
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/plurigrid/asi "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/using-gh-cli" ~/.claude/skills/plurigrid-asi-using-gh-cli && rm -rf "$T"
manifest:
skills/using-gh-cli/SKILL.mdsource content
Using the GitHub CLI (gh
)
ghWhen to Use
- Browsing or reading code from a GitHub repository — clone it and use Read/Glob/Grep
- Viewing or creating pull requests, issues, releases, or gists
- Fetching repo metadata or any GitHub API data
- Interacting with GitHub Actions (runs, workflows)
- Any task involving GitHub that you might otherwise use
,curl
, orwget
forWebFetch
When NOT to Use
- Non-GitHub URLs (use
orWebFetch
for those)curl - Public web content that happens to be hosted on GitHub Pages (
) — those are regular websites*.github.io - Local git operations (
,git commit
) — usegit push
directlygit
Key Principle
Always use
instead of gh
, curl
, or wget
for GitHub URLs. The WebFetch
gh CLI uses the user's authenticated token automatically, so it:
- Works with private repositories
- Avoids GitHub API rate limits (unauthenticated: 60 req/hr; authenticated: 5,000 req/hr)
- Handles pagination correctly
- Provides structured output and filtering
Browsing Repository Code
To read or browse files from a GitHub repo, clone it locally and use normal file tools (Read, Glob, Grep). This is much faster and more natural than fetching files one-by-one via the API.
# Clone to a session-scoped temp directory (cleaned up automatically on session end) clonedir="$TMPDIR/gh-clones-${CLAUDE_SESSION_ID}" mkdir -p "$clonedir" gh repo clone owner/repo "$clonedir/repo" -- --depth 1
After cloning, use the Explore agent (via the Task tool with
subagent_type=Explore) to investigate the cloned repo. The Explore agent can use Read, Glob, and Grep across the clone efficiently — much better than calling them one at a time:
Task(subagent_type="Explore", prompt="In $clonedir/repo/, find how authentication is implemented")
For targeted lookups on a clone you already understand, use Read/Glob/Grep directly.
uses the user's authenticated token — works with private reposgh repo clone
keeps the clone fast (only latest commit)--depth 1- No cleanup needed — a SessionEnd hook removes the clone directory automatically
- Use
only when you need a quick single-file lookup without cloninggh api
Quick Start
# View a repo gh repo view owner/repo # List and view PRs gh pr list --repo owner/repo gh pr view 123 --repo owner/repo # List and view issues gh issue list --repo owner/repo gh issue view 456 --repo owner/repo # Call any REST API endpoint gh api repos/owner/repo/contents/README.md # Call with pagination and jq filtering gh api repos/owner/repo/pulls --paginate --jq '.[].title'
Common Patterns
| Instead of | Use |
|---|---|
on | |
on a blob/tree URL | Clone with and use Read/Glob/Grep |
on | Clone with and use Read |
on | |
| |
with | (auth is automatic) |
to download a release asset | |
References
- Pull Requests — list, view, create, merge, review PRs
- Issues — list, view, create, close, comment on issues
- Repos and Files — view repos, browse files, clone
- API — raw REST/GraphQL access, pagination, jq filtering
- Releases — list, create, download releases
- Actions — view runs, trigger workflows, check logs