Gh CLI
Use gh CLI for GitHub operations.
Use This Skill
- Push, commit, or any git remote operation needing GitHub interaction
- Create / list / view / close issues or pull requests
- Edit repository metadata (description, topics, homepage)
- Search across repos for issues, PRs, code, or users
- View repository details or authentication status
- "推送" / "提 PR" / "创建 issue" / "改仓库描述" / "查看仓库信息"
Do Not Use
- Operations that do not involve GitHub (local git, other forges)
- Raw
git operations that do not need GitHub API interaction
- Managing Agent Skills (use
gh skill subcommand, not this skill)
Input Contract
Required Inputs:
- A GitHub operation intent (create PR, list issues, edit repo, etc.)
Optional Inputs:
- Target repo (
owner/repo) — if omitted, inferred from cwd's git remotes
- Issue or PR number
- Flags specific to the operation
Missing input handling:
- No specific repo: Use git remote from cwd. If no remote found, ask user.
- No PR/issue number for view: List recent items first, then ask which one.
- Ambiguous intent: Run
gh <command> --help to clarify options.
Execution Protocol
- Verify authentication:
gh auth status. If unauthenticated, report and stop.
- Choose the right command path:
- Typed commands (
gh pr, gh issue, gh repo) for standard operations.
gh search for cross-repo queries.
gh api for anything typed commands do not expose.
- Use structured output: Always prefer
--json + --jq over parsing human-readable text.
- Handle pagination: Pass
-L N to control result count. For totalCount, use gh api graphql.
- Target repo: Override with
--repo OWNER/REPO (-R) when not operating on cwd's repo.
- Execute and validate: Run the command. If it fails, interpret the error and retry with adjusted parameters.
Core Patterns
Structured output
--json field1,field2,... for structured JSON.
- Run with
--json and no field list to see available fields first.
--jq '<expr>' for filtering inline, no separate jq pipe.
--template '<go-template>' for shaped text output.
Pagination
List commands cap results. Default is usually 30. Pass -L N (--limit N) to control count. gh issue list / gh pr list do not expose totalCount via --json. For a true total, use gh api graphql. For raw API pagination: gh api --paginate <path> + --jq + optionally --slurp.
Repo targeting
gh infers repo from cwd's git remotes. Override with --repo OWNER/REPO (-R).
Search vs list
gh search issues|prs|code|repos|commits|users — cross-repo, full search syntax. Prefer for cross-repo or author/label filtering.
gh issue list --search "..." / gh pr list --search "..." — same syntax but scoped to one repo.
Fall back to gh api
When typed commands don't expose the data you need. {owner}/{repo} placeholders auto-filled from repo remotes.
Interactivity
In non-TTY contexts gh already skips the pager, strips ANSI, and errors with clear messages instead of prompting.
When not sure about flags or available fields, run gh <command> --help before searching elsewhere.
Common Operations
gh repo edit <owner/repo> — edit metadata. Flags: --description, --homepage, --add-topic, --remove-topic, --default-branch.
gh repo view <owner/repo> — view details.
gh pr create — create. Flags: --title, --body, --draft, --base.
gh pr list — list. Flags: --state open/closed/merged, --author, --assignee, --draft, -L.
gh pr view <number> — view details. --comments for issue-level comments.
gh pr diff <number> — read diff without switching branches.
gh pr checkout <number> — switch to PR branch locally.
gh issue create — create. Flags: --title, --body, --label, --assignee.
gh issue list — list. Flags: --state, --label, --author, --assignee, -L, --search.
gh issue view <number> — view details.
gh issue close <number> — close.
gh issue reopen <number> — reopen.
Failure Handling
- Not authenticated:
gh auth status fails. Report to user and ask them to run gh auth login.
- 404 / not found: Repo or resource does not exist. Verify
owner/repo spelling and user's access.
- API rate limited: Wait and retry, or inform user if limit is exceeded.
- Command not found:
gh not installed. Ask user to install GitHub CLI.
- Network error: Report the exact error. Do not guess the output.
- Ambiguous result from no field list: Re-run with explicit fields.
Output Contract
When using this skill, include in your response:
- What command was executed (or attempted)
- The structured result (key fields, not raw JSON dump)
- If failed, the exact error and suggested next step
1---2name: gh-cli3description: Operate GitHub repositories, pull requests, issues, and releases via the `gh` CLI. Use when the user asks to push, create PR, manage issues, edit repo metadata, view repo, or any GitHub workflow operation, including Chinese requests such as “推送”“提 PR”“创建 issue”“改仓库描述”“查看仓库信息”.4---56# Gh CLI78Use `gh` CLI for GitHub operations.910## Use This Skill1112- Push, commit, or any git remote operation needing GitHub interaction13- Create / list / view / close issues or pull requests14- Edit repository metadata (description, topics, homepage)15- Search across repos for issues, PRs, code, or users16- View repository details or authentication status17- "推送" / "提 PR" / "创建 issue" / "改仓库描述" / "查看仓库信息"1819## Do Not Use2021- Operations that do not involve GitHub (local git, other forges)22- Raw `git` operations that do not need GitHub API interaction23- Managing Agent Skills (use `gh skill` subcommand, not this skill)2425## Input Contract2627**Required Inputs:**28- A GitHub operation intent (create PR, list issues, edit repo, etc.)2930**Optional Inputs:**31- Target repo (`owner/repo`) — if omitted, inferred from cwd's git remotes32- Issue or PR number33- Flags specific to the operation3435**Missing input handling:**36- **No specific repo**: Use git remote from cwd. If no remote found, ask user.37- **No PR/issue number for view**: List recent items first, then ask which one.38- **Ambiguous intent**: Run `gh <command> --help` to clarify options.3940## Execution Protocol41421. **Verify authentication**: `gh auth status`. If unauthenticated, report and stop.432. **Choose the right command path**:44 - Typed commands (`gh pr`, `gh issue`, `gh repo`) for standard operations.45 - `gh search` for cross-repo queries.46 - `gh api` for anything typed commands do not expose.473. **Use structured output**: Always prefer `--json` + `--jq` over parsing human-readable text.484. **Handle pagination**: Pass `-L N` to control result count. For `totalCount`, use `gh api graphql`.495. **Target repo**: Override with `--repo OWNER/REPO` (`-R`) when not operating on cwd's repo.506. **Execute and validate**: Run the command. If it fails, interpret the error and retry with adjusted parameters.5152### Core Patterns5354#### Structured output5556- `--json field1,field2,...` for structured JSON.57- Run with `--json` and **no field list** to see available fields first.58- `--jq '<expr>'` for filtering inline, no separate `jq` pipe.59- `--template '<go-template>'` for shaped text output.6061#### Pagination6263List commands cap results. Default is usually 30. Pass `-L N` (`--limit N`) to control count. `gh issue list` / `gh pr list` do not expose `totalCount` via `--json`. For a true total, use `gh api graphql`. For raw API pagination: `gh api --paginate <path>` + `--jq` + optionally `--slurp`.6465#### Repo targeting6667`gh` infers repo from cwd's git remotes. Override with `--repo OWNER/REPO` (`-R`).6869#### Search vs list7071- `gh search issues|prs|code|repos|commits|users` — cross-repo, full search syntax. Prefer for cross-repo or author/label filtering.72- `gh issue list --search "..."` / `gh pr list --search "..."` — same syntax but scoped to one repo.7374#### Fall back to `gh api`7576When typed commands don't expose the data you need. `{owner}/{repo}` placeholders auto-filled from repo remotes.7778#### Interactivity7980In non-TTY contexts `gh` already skips the pager, strips ANSI, and errors with clear messages instead of prompting.8182When not sure about flags or available fields, run `gh <command> --help` before searching elsewhere.8384### Common Operations8586`gh repo edit <owner/repo>` — edit metadata. Flags: `--description`, `--homepage`, `--add-topic`, `--remove-topic`, `--default-branch`.87`gh repo view <owner/repo>` — view details.8889`gh pr create` — create. Flags: `--title`, `--body`, `--draft`, `--base`.90`gh pr list` — list. Flags: `--state open/closed/merged`, `--author`, `--assignee`, `--draft`, `-L`.91`gh pr view <number>` — view details. `--comments` for issue-level comments.92`gh pr diff <number>` — read diff without switching branches.93`gh pr checkout <number>` — switch to PR branch locally.9495`gh issue create` — create. Flags: `--title`, `--body`, `--label`, `--assignee`.96`gh issue list` — list. Flags: `--state`, `--label`, `--author`, `--assignee`, `-L`, `--search`.97`gh issue view <number>` — view details.98`gh issue close <number>` — close.99`gh issue reopen <number>` — reopen.100101## Failure Handling102103- **Not authenticated**: `gh auth status` fails. Report to user and ask them to run `gh auth login`.104- **404 / not found**: Repo or resource does not exist. Verify `owner/repo` spelling and user's access.105- **API rate limited**: Wait and retry, or inform user if limit is exceeded.106- **Command not found**: `gh` not installed. Ask user to install GitHub CLI.107- **Network error**: Report the exact error. Do not guess the output.108- **Ambiguous result from no field list**: Re-run with explicit fields.109110## Output Contract111112When using this skill, include in your response:113- What command was executed (or attempted)114- The structured result (key fields, not raw JSON dump)115- If failed, the exact error and suggested next step