Repository navigation
Description
Summary
gh repo clone <public-repo> performs the clone anonymously even when gh holds a valid token. Because GitHub throttles unauthenticated git downloads, an authenticated user can be refused with:
fatal: remote error: GitHub is temporarily limiting some unauthenticated downloads to protect the stability of the platform. Please retry later or authenticate.
failed to run git: exit status 128
…while every gh api call from the same machine, in the same second, succeeds.
The cause is that gh auth setup-git installs a credential helper:
credential.https://github.com.helper = !gh auth git-credential
and git only consults a credential helper after the server answers 401. github.com answers 200 for a public repository, so git never asks the helper and never sends an Authorization header. gh repo clone shells out to that git clone, so it inherits the behaviour.
gh version
gh version 2.95.0 (2026-06-17)
git version 2.43.0
Reproducible example
gh auth status # logged in
gh auth setup-git # credential helper installed
# Count the Authorization headers git actually sends:
GIT_TRACE_CURL=/tmp/trace.log GIT_TRACE_CURL_NO_DATA=1 \
gh repo clone cli/cli /tmp/clone-a -- --depth 1
grep -ci 'Send header: Authorization:' /tmp/trace.log
# -> 0
# Same clone with the token sent preemptively:
GIT_TRACE_CURL=/tmp/trace2.log GIT_TRACE_CURL_NO_DATA=1 \
GIT_CONFIG_COUNT=1 \
GIT_CONFIG_KEY_0='http.https://github.com/.extraheader' \
GIT_CONFIG_VALUE_0="Authorization: Basic $(printf 'x-access-token:%s' "$(gh auth token)" | base64 -w0)" \
gh repo clone cli/cli /tmp/clone-b -- --depth 1
grep -ci 'Send header: Authorization:' /tmp/trace2.log
# -> 3(A scripted version of this measurement: https://github.com/link-assistant/hive-mind/blob/main/experiments/issue-2192-anonymous-clone-auth.mjs)
Expected vs actual
- Expected: when
ghis authenticated,gh repo clonesends the token, so the clone counts against the authenticated budget. - Actual: the clone is anonymous for public repositories, and is throttled as such. The failure text ("Please retry later or authenticate") is confusing, because the user is authenticated —
gh auth statusis green andgh apiworks.
Workaround
Send the token preemptively — the same mechanism actions/checkout uses — through environment variables so it never lands in a config file or in argv:
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0='http.https://github.com/.extraheader'
export GIT_CONFIG_VALUE_0="Authorization: Basic $(printf 'x-access-token:%s' "$(gh auth token)" | base64 -w0)"
gh repo clone owner/repoSuggested fix
In the clone path (pkg/cmd/repo/clone), when a token for the host is available, pass the preemptive header to the git invocation, e.g. append
-c http.https://<host>/.extraheader=Authorization: Basic <base64("x-access-token:"+token)>
or set the equivalent GIT_CONFIG_COUNT/GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n variables on the child process (the env form keeps the token out of ps output, which is why we prefer it downstream). Behaviour for private repositories is unchanged — those already get a 401 and reach the helper.
Related downstream report and analysis: link-assistant/hive-mind#2192
Activity
cli-triage commentedon Sep 3, 2026
Thanks for the detailed report and reproduction. Tracing this through the source:
gh repo clone(https://github.com/cli/cli/blob/9646a83d34f4e4968d76bed989f9f4e25fd78a7a/pkg/cmd/repo/clone/clone.go#L184-L189) callsgitClient.Clone(https://github.com/cli/cli/blob/9646a83d34f4e4968d76bed989f9f4e25fd78a7a/git/client.go#L922-L940), which just execsgit clonewith the constructed URL and passed-through args — noAuthorizationheader or extraheader config is injected. Sincegh auth setup-gitonly installs a credential helper (invoked by git after a 401), and github.com returns 200 for public repos, the token never gets sent, matching the reported behavior. This looks like a legitimate bug, not just expected credential-helper semantics, sinceghalready holds a token it could use preemptively (asactions/checkoutdoes). No exact duplicate found (searched cli/cli issues); related but distinct: #12591, #13032, #13307, #12891, #13317. Suggestingbug,priority-3(workaround exists, public-repo-only, no data loss/security impact), andgh-repo.williammartin commentedon Sep 4, 2026
Hey @konard,
As per https://github.com/orgs/community/discussions/206581#discussioncomment-18251638, the abuse team have been rolling out some protections. I think you landed in a window here where the platform was returning
200plus an error, and it has later been correctly updated to401. Hopefully you shouldn't see this again, at least when authenticated viaghin the setup you have.Sorry for the inconvenience and thanks for the detailed write up.