GitHub CLI
$ gh Official Med RiskGitHub's official command-line interface exposes pull requests, issues, Actions runs, releases, and raw REST/GraphQL endpoints. Native --json field selection and built-in --jq querying let agents fetch exact payloads without burning context tokens.
brew install gh Prefer gh over GitHub MCP for coding agents: --json <fields> + --jq cuts token usage dramatically and avoids loading 30+ MCP tool schemas upfront.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Native --json field whitelist, embedded --jq processor, GH_PROMPT_DISABLED=1 headless mode, and clear non-zero exit codes make gh a benchmark for agent-friendly CLIs.
- Supports
--json <fields>and--jqacross core subcommands - Supports
GH_PROMPT_DISABLED=1andNO_COLOR=1for non-TTY execution
Strong credential isolation via OS keychain and fine-grained GH_TOKEN scoping, though destructive commands (repo delete, pr merge) have no global --dry-run flag.
- OS keychain / scoped
GH_TOKENsupport - Lacks universal
--dry-runon remote write subcommands
Single static Go binary available across Homebrew, apt, winget, and official GitHub releases on macOS, Linux, and Windows.
- Fast single binary startup with zero language runtime dependencies
Covers daily GitHub workflows plus gh api escape hatch, consistently outperforming GitHub MCP servers on token efficiency.
- Covers PRs, issues, Actions, releases, and raw
gh apiREST/GraphQL
First-party official tool maintained by GitHub (cli/cli) with frequent releases and MIT license.
- Official
cli/clirepository under MIT license
Comprehensive manual and predictable --help hierarchy across all subcommands.
- Structured CLI manual at cli.github.com/manual
Security, Auth & Guardrails
Stores OAuth tokens in the OS keychain by default (or ~/.config/gh/hosts.yml), and supports scoped GH_TOKEN / GITHUB_TOKEN env vars.
CLI is MIT open-source and free; GitHub API rate limits apply (5,000 req/hr authenticated).
# GitHub CLI (gh) Agent Rules - Always pass `--json <fields>` when reading issues, PRs, or runs. - Never run `gh pr merge`, `gh repo delete`, or `gh release delete` without explicit user confirmation. - Use `GH_PROMPT_DISABLED=1` and pass all flags (`--title`, `--body`) explicitly.
Agent-Ready Command Recipes
Safe Read-Only Queries
gh pr list --state open --json number,title,author,headRefName --limit 20
Returns compact structured JSON without terminal tables or wasted tokens.
gh run view <run-id> --log-failed
Streams only the failing step logs so the agent can diagnose CI failures directly.
Controlled Writes & Previews
gh pr create --draft --title "feat: update pipeline" --body-file pr.md
Explicit --title and --body-file prevent interactive TTY prompts; --draft reduces merge risk.
Strengths for Agents
- + Built-in
--json <fields>+--jqeliminates brittle stdout scraping and saves context tokens. - + Supports
GH_TOKENfine-grained PATs andGH_PROMPT_DISABLED=1for CI/agent sandboxes. - +
gh apiprovides full fallback access to any GitHub REST or GraphQL endpoint.
Caveats & Pitfalls
- ! No global
--dry-runflag on mutation commands likegh pr mergeorgh issue close. - ! Omitting explicit
--title/--bodyflags can trigger interactive prompts unlessGH_PROMPT_DISABLED=1is set.