| name | gh-cli-agentic |
| description | gh CLI commands with JSON output for agent workflows. Use when querying PRs, issues, workflow runs, or repo metadata; inspecting PR checks; fetching failed CI logs; or resolving a github.com URL to an API call. |
| user-invocable | false |
| allowed-tools | Bash(gh pr *), Bash(gh run *), Bash(gh issue *), Bash(gh repo *), Bash(gh workflow *), Bash(gh api *), Read |
| created | "2025-01-16T00:00:00.000Z" |
| modified | "2026-05-09T00:00:00.000Z" |
| reviewed | "2026-04-25T00:00:00.000Z" |
GitHub CLI Agentic Patterns
When to Use This Skill
| Use this skill when... | Use the alternative when... |
|---|
Querying PRs, issues, runs, or repo metadata with gh and need JSON output | Use git-cli-agentic for porcelain-mode local git queries (status, diff, log) |
| Inspecting PR checks, mergeable status, or fetching failed CI logs | Use gh-workflow-monitoring to actively watch a run until it completes |
Resolving a github.com URL into an gh api call or working with sub-issues | Use git-issue-hierarchy for sub-issue add/remove/dependency-graph operations |
Looking up label, repo, or workflow metadata via gh JSON commands | Use github-labels to actually apply or create labels on issues/PRs |
Optimized gh commands for AI agent consumption using JSON output and structured field selection.
Core Principle
Always use --json <fields> for machine-readable output. The --jq filter is built-in (no jq installation required).
Pull Request Operations
Check Status
gh pr checks $PR_NUMBER --json name,state,conclusion,detailsUrl
gh pr checks $PR_NUMBER --json name,state,conclusion --jq '.[] | select(.conclusion == "FAILURE")'
Fields: name, state, conclusion, detailsUrl, startedAt, completedAt
PR Details
gh pr view $PR_NUMBER --json number,title,state,mergeable,statusCheckRollup
gh pr view $PR_NUMBER --json number,title,body,state,author,labels,assignees,reviewDecision,mergeable,statusCheckRollup
Key Fields:
| Field | Description |
|---|
mergeable | MERGEABLE, CONFLICTING, UNKNOWN |
reviewDecision | APPROVED, CHANGES_REQUESTED, REVIEW_REQUIRED |
statusCheckRollup | Array of check statuses |
List PRs
gh pr list --json number,title,author,labels
gh pr list --author @me --json number,title,state
gh pr list --search "review-requested:@me" --json number,title
Workflow Run Operations
Run Details
gh run view $RUN_ID --json conclusion,status,jobs,createdAt,updatedAt
gh run list --json databaseId,status,conclusion,name,createdAt -L 10
Status Values: queued, in_progress, completed
Conclusion Values: success, failure, cancelled, skipped, neutral
Watch Run Until Completion
gh run watch $RUN_ID --compact --exit-status
RUN_ID=$(gh run list -L 1 --json databaseId --jq '.[0].databaseId')
gh run watch $RUN_ID --compact --exit-status
See gh-workflow-monitoring skill for comprehensive workflow watching patterns.
Failed Logs
gh run view $RUN_ID --log-failed
gh run view $RUN_ID --log
Workflow Triggers
gh workflow run $WORKFLOW_NAME
gh workflow run $WORKFLOW_NAME -f param1=value1 -f param2=value2
gh workflow list --json name,state,path
Issue Operations
Issue Details
gh issue view $ISSUE_NUMBER --json number,title,body,state,labels,assignees,comments
gh issue view $ISSUE_NUMBER --json number,title,state,labels
gh issue view $ISSUE_NUMBER --json number,title,state,subIssuesSummary
List Issues
gh issue list --json number,title,labels,assignees
gh issue list --label "bug" --json number,title
gh issue list --assignee @me --json number,title,state
Issue Types
gh issue create --title "..." --body "..." --type "Bug"
gh issue create --title "..." --body "..." --type "Feature"
gh issue create --title "..." --body "..." --type "Task"
Sub-Issues
gh api repos/{owner}/{repo}/issues/{parent}/sub_issues --jq '.[].number'
gh api repos/{owner}/{repo}/issues/{parent}/sub_issues -f sub_issue_id={child_id}
gh api repos/{owner}/{repo}/issues/{parent}/sub_issues/{sub_issue_id} -X DELETE
gh api repos/{owner}/{repo}/issues/{parent}/sub_issues -X PATCH \
-f sub_issue_id={id} -f after_id={after_id}
gh issue view {N} --json title,subIssuesSummary
Custom Issue Fields
gh api orgs/{org}/issue-fields --jq '.[].name'
gh api repos/{owner}/{repo}/issues/{N}/issue-field-values
gh api repos/{owner}/{repo}/issues/{N}/issue-field-values \
-X POST -f field_id={id} -f value='{value}'
Issue Management
gh issue transfer {N} {target-repo}
gh issue pin {N}
gh issue unpin {N}
gh issue lock {N} --reason resolved
gh issue unlock {N}
gh issue develop {N} --checkout
gh issue develop {N} --name {branch-name}
Repository Operations
gh repo view --json nameWithOwner,defaultBranchRef,description
gh repo view --json nameWithOwner --jq '.nameWithOwner'
API Direct Access
For operations not covered by subcommands:
gh api repos/{owner}/{repo}/actions/runs --jq '.workflow_runs[:5]'
gh api repos/{owner}/{repo}/issues --paginate --jq '.[].number'
GitHub URL Resolution
Translate GitHub URLs into gh API commands for programmatic access.
URL → Command Mapping
| URL Pattern | Command |
|---|
github.com/{owner}/{repo}/pull/{n} | gh pr view {n} --repo {owner}/{repo} --json number,title,body,state |
github.com/{owner}/{repo}/issues/{n} | gh issue view {n} --repo {owner}/{repo} --json number,title,body,state |
github.com/{owner}/{repo}/commit/{sha} | gh api repos/{owner}/{repo}/commits/{sha} |
github.com/{owner}/{repo}/blob/{ref}/{path} | gh api repos/{owner}/{repo}/contents/{path}?ref={ref} |
File Contents by Ref
gh api repos/{owner}/{repo}/contents/{path}?ref={ref} --jq '.content' | base64 -d
gh api repos/{owner}/{repo}/contents/{path}?ref={ref} -H "Accept: application/vnd.github.raw+json"
Diff and Patch via API
Use Accept headers to get raw diff or patch output from PRs and commits:
gh api repos/{owner}/{repo}/pulls/{n} -H "Accept: application/vnd.github.diff"
gh api repos/{owner}/{repo}/pulls/{n} -H "Accept: application/vnd.github.patch"
gh api repos/{owner}/{repo}/commits/{sha} -H "Accept: application/vnd.github.diff"
gh api repos/{owner}/{repo}/commits/{sha} -H "Accept: application/vnd.github.patch"
Agentic Optimizations
| Context | Command |
|---|
| CI diagnosis | gh pr checks $N --json name,state,conclusion,detailsUrl |
| Get failure logs | gh run view $ID --log-failed |
| PR merge status | gh pr view $N --json mergeable,reviewDecision,statusCheckRollup |
| Quick issue list | gh issue list --json number,title,labels -L 10 |
| Sub-issue progress | gh issue view $N --json title,subIssuesSummary |
| List sub-issues | gh api repos/{o}/{r}/issues/{N}/sub_issues --jq '.[].number' |
| Add sub-issue | gh api repos/{o}/{r}/issues/{N}/sub_issues -f sub_issue_id=M |
| Transfer issue | gh issue transfer N target-repo |
| Create dev branch | gh issue develop N --checkout |
| Workflow trigger | gh workflow run $NAME |
Error Handling in Context
Use 2>/dev/null to suppress errors in context expressions (do NOT use || fallbacks - blocked by Claude Code 2.1.7+):
- PR checks: !`gh pr checks $PR --json name,state,conclusion`
- Run status: !`gh run view $ID --json status,conclusion`
Field Reference
PR Fields
number, title, body, state, author, labels, assignees, reviewDecision, mergeable, statusCheckRollup, headRefName, baseRefName, isDraft, url, createdAt, updatedAt
Issue Fields
number, title, body, state, author, labels, assignees, comments, milestone, url, createdAt, updatedAt, closedAt, subIssuesSummary, type
Run Fields
databaseId, name, status, conclusion, jobs, createdAt, updatedAt, url, headBranch, headSha, event
Job Fields (within runs)
name, status, conclusion, startedAt, completedAt, steps