1---2name: gh-cli3description: Uses the GitHub CLI (`gh`) from the terminal for auth, repos, issues, PRs, Actions, API calls, and browsing. Apply when the user or task involves GitHub operations, CI status, or authenticated GitHub API access from a shell.4---56# GitHub CLI (`gh`)78## When to use910- Inspect or change GitHub resources (repos, PRs, issues, Actions, releases) without opening the browser first.11- Run authenticated `gh api` for endpoints not wrapped by a subcommand.12- The workspace may be a Coder VM or local machine; prefer **non-interactive** flags in scripts and agent-driven runs.1314## Prerequisites1516- `gh` installed (`gh version`). Documentation: [GitHub CLI manual](https://cli.github.com/manual/).17- Authentication: `gh auth status`. If needed, `gh auth login` (interactive) or token-based flows documented in `gh auth login --help`.1819## Patterns2021- **Help**: `gh help`, `gh <cmd> --help` (e.g. `gh pr create --help`).22- **Current repo context**: many commands infer the repo from `git` remotes in the working directory. Override with `-R owner/repo` when needed.23- **JSON / scripting**: many commands support `--json` and `-q` / `--jq` for machine-readable output.24- **API**: `gh api <endpoint> [-X METHOD] [-f key=value ...]` for REST; use `-H` as needed.2526## Core commands (orienting)2728| Area | Examples |29|------|----------|30| Auth | `gh auth status`, `gh auth login`, `gh auth token` |31| PRs | `gh pr list`, `gh pr view`, `gh pr create`, `gh pr checkout <n>`, `gh pr merge` |32| Issues | `gh issue list`, `gh issue create`, `gh issue view` |33| Repo | `gh repo view`, `gh repo clone`, `gh repo create` |34| Actions | `gh run list`, `gh run view`, `gh workflow run` |35| Search | `gh search repos`, `gh search issues`, `gh search prs` |36| Browse | `gh browse` (opens browser) |3738## Safety3940- Do not paste or log tokens. Prefer env vars and `gh`’s own credential storage.41- For destructive actions (merge, delete branch, close issues), confirm intent matches the user’s request.4243## References4445- **Official documentation:** [GitHub CLI manual](https://cli.github.com/manual/)46- **Local help:** `gh help`, `gh <cmd> --help` (authoritative for your installed `gh` version)