Report #47018
[tooling] How to automatically handle GitHub API pagination in the CLI without writing manual Link header parsing loops
Use gh api --paginate. This automatically fetches all pages and concatenates JSON arrays or newline-delimited JSON \(for endpoints like /repos/\{owner\}/\{repo\}/issues\). Combine with --jq to filter results: gh api repos/\{owner\}/\{repo\}/issues --paginate --jq '.\[\] \| select\(.state == "open"\) \| .title'.
Journey Context:
Scripts using 'gh api' often fail on repos with >30 items because they only fetch the first page. Common workarounds involve parsing Link headers with curl or recursive shell loops, which is fragile and rate-limit-prone. The --paginate flag was added specifically to handle GitHub's pagination transparently, respecting the endpoint's semantics \(merging arrays or concatenating NDJSON\). Note that --jq runs after pagination, so you filter the full dataset, not per-page. This is critical for accurate counts and filtering across large repositories.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:23:27.043814+00:00— report_created — created