Repository navigation
Description
Describe the bug
When an environment-provided classic token lacks a scope, gh api suggests gh auth refresh. The suggested command fails because gh cannot update an environment-provided token. I reproduced this with gh 2.105.0 and 2.102.0 on Linux using an isolated loopback API and a synthetic token.
Steps to reproduce
- In an isolated shell, export a classic personal access token that has
repoand lacks bothuseranduser:emailasGH_TOKEN. - Run
gh api --hostname github.com user/emails. - Run the command printed in the scope hint.
The same diagnostic path can be reproduced without a real token or account. Configure GH_HOST=127.0.0.1 and a dummy GH_ENTERPRISE_TOKEN with a temporary GH_CONFIG_DIR. Serve HTTPS locally for GET /api/v3/user/emails and return HTTP 404 with {"message":"Not Found"}, Content-Type: application/json, X-OAuth-Scopes: repo, and X-Accepted-OAuth-Scopes: user, user:email. Trust the local certificate for the experiment and run the two commands below.
$ gh api --hostname 127.0.0.1 user/emails
{"message":"Not Found"}
gh: Not Found (HTTP 404)
gh: This API operation needs the "user" scope. To request it, run: gh auth refresh -h 127.0.0.1 -s user
$ gh auth refresh -h 127.0.0.1 -s user
The value of the GH_ENTERPRISE_TOKEN environment variable is being used for authentication.
To refresh credentials stored in GitHub CLI, first clear the value from the environment.
Both commands exit 1. The email API documentation describes user:email as sufficient for classic tokens.
Expected behavior and proposed change
Keep the missing-scope information and tailor the next step to the active credential. For an environment token, name the environment variable and suggest replacing its value with a credential that has the required permission. Suggest gh auth refresh for eligible stored credentials.
In the API command's error handling, resolve the token source for the request host using the same authentication configuration as the API transport. Pass the source into the scope hint formatter, or pass back the missing scope and choose the remediation at the call site. The refresh command already distinguishes environment-provided tokens. Test the same 404 response with a stored token and an environment-provided token and assert the appropriate hint for each.
Workaround
Replace the exported token with a classic token that has user:email or a fine-grained user token with Email addresses: Read. To use stored credentials instead, clear the applicable environment token and sign in with gh auth login -h github.com -s user:email --web.
This is a concrete example of credential-specific remediation under the actionable errors design. It was investigated while working on gh-setup-git-identity issue 34.
Activity
cli-triage commentedon Nov 22, 2026
Partly reproduced on 2.105.0.
Using test data with a token that has
repobut notuser, the API command printed the same refresh hint:Exit status:
1.The same result appears on release 2.105.0 and source
de06af2. The test setup could not preserve an environment-token source for the follow-up command, but current source confirmsgh auth refreshrejects environment tokens. The hint can therefore direct users to a command that cannot update their active credential.Supporting reports
Duplicate analysis
Label reasoning
Reproduction log
Investigation notes
Generated by issue triage.
army20152015-design commentedon Nov 22, 2026
Shanmukh-l33t commentedon Nov 23, 2026