| name | Using GitHub CLI (gh) |
| description | Master GitHub CLI workflow for issues, repos, search, and APIs. Use when creating/reading GitHub issues, searching repos, querying GitHub data, or automating GitHub tasks. Focus: gotchas, key workflows with "look at past examples" pattern, practical APIs. |
Using GitHub CLI (gh)
Clear, focused guide to GitHub CLI gotchas and key workflows for issues, repos, search, and APIs.
🚨 Critical Gotchas
1. Search with Exclusions Needs --
gh search issues "my-query -label:bug"
gh search issues -- "my-query -label:bug"
Shell interprets -label:bug as a flag without --.
2. JSON Output Requires Field Names
gh pr list --json
gh pr list --json number,title,author
API must know which fields to fetch.
3. Repo Context Defaults to Current Directory
gh pr list
gh pr list -R owner/repo
GH_REPO=owner/repo gh pr list
4. Token Scope Issues (Silent Failures)
Check your token scopes before automating:
gh auth status
5. API Placeholder Variables Don't Expand Env Vars
gh api /repos/$OWNER/$REPO/issues
gh api /repos/{owner}/{repo}/issues
4 Key Workflows
Workflow 1: CREATE ISSUE
Step 0: Find the repository
pip show package-name | grep "Home-page"
gh search repos "package-name" --limit 5
ALWAYS: Look at past examples in the repo first
gh search issues --repo owner/repo "your search terms" --limit 10
gh issue view --repo owner/repo [issue-number]
Keep It Short
Maintainers are overwhelmed. Good issues are:
- Clear title - One line describing the problem
- Brief description - 1-2 sentences
- Minimal repro - Smallest code/steps to reproduce
- Short environment - OS, version (one line)
Create Issue
gh issue create --repo owner/repo \
--title "Bug: X breaks when Y" \
--body-file body.md
gh issue create --repo owner/repo \
--title "Clear, searchable title" \
--body "Brief description.
Repro steps.
Environment: macOS 14.6.0"
Verify Bug Reports
Before submitting:
- Read the actual code being referenced
- Test reproduction steps
- Confirm exact trigger (e.g., Ctrl+Q vs Ctrl+D)
Key Points:
- Search for duplicates BEFORE creating
- Look at 2-3 recent issues to match repo style
- Keep it concise - respect maintainers' time
- Verify behavior by reading code/testing
Workflow 2: READ ISSUE
Get full issue with comments
gh issue view --repo anthropics/claude-code [number] --comments
gh issue view --repo anthropics/claude-code [number] \
--json title,body,state,author,labels
gh issue list --assignee=@me --json number,title,state
Common Queries
gh issue list --search 'is:open assignee:@me'
gh issue list --search 'is:open label:bug' --limit 20
gh issue list --search 'is:open updated:>=7.days.ago' --limit 10
Workflow 3: READ REPOSITORY INFO
Get repo details
gh repo view --repo anthropics/claude-code --json name,description,url
gh issue list --repo anthropics/claude-code --limit 10
gh pr list --repo anthropics/claude-code --limit 10
gh label list --repo anthropics/claude-code
Find Repo Context
gh repo view --json owner,nameWithOwner
REPO=$(gh repo view --json nameWithOwner --jq '.nameWithOwner')
gh issue list --repo $REPO
Workflow 4: SEARCH
Search syntax (remember the --)
gh search issues -- "your query -label:wontfix" --limit 15
gh search issues --repo anthropics/claude-code "is:open label:bug type:issue"
gh search code "function main" --language python --limit 10
gh search repos "claude-code" --owner anthropics --limit 5
Advanced Filters
gh search issues -- "is:open label:enhancement -label:duplicate"
gh search issues -- "is:closed sort:updated-desc"
gh pr list --search 'is:open review:requested'
Key API Commands
Direct API Access (when gh commands aren't enough)
gh api user | jq '.login, .name'
gh api --paginate /repos/{owner}/{repo}/issues | jq '.[] | .number'
gh api graphql -f query='{ viewer { name login } }'
gh api -f title="New Issue" -f body="Description" /repos/{owner}/{repo}/issues
Output Formatting
gh issue list --json number,title,state
gh pr list --json author,title --jq '.[].author.login'
gh pr list --json number,title \
--template '{{range .}}#{{.number}}: {{.title}}{{"\n"}}{{end}}'
When Things Go Wrong
gh auth status
gh auth status
GH_DEBUG=1 gh issue list
Contributing New Workflows
When you discover a useful automation pattern:
- Save it to
~/.claude/skills/using-github-cli/workflows/gh-pattern-name.sh
- Add documentation comment at top
- Update
WORKFLOWS.md with description
- Next session will have access to it!
See WORKFLOWS.md and workflows/gh-status-dashboard.sh for examples.