GitHub CLI Expiring Tokens: What Changed and How to Opt In
GitHub CLI can now store a short-lived token that refreshes itself. Here is how to opt in, and which scripts and AI agent setups to check first.
GitHub CLI expiring tokens entered public preview on 21 October 2026. With version 2.103.0, gh can store a short-lived access token plus a rotating refresh token, and renew the access token on its own. Opting in is optional, and nothing changes for existing sign-ins. The one thing to check before you switch is any script, tool or AI coding agent that copies your token once and keeps using it, because that copy will now expire.
Everything below comes from GitHub's changelog entry for the release.
What changed in GitHub CLI
Until now, signing in with gh auth login stored a token that lasted until you revoked it. The preview adds an alternative: a token that expires, paired with a refresh token that gh uses to get a new one without asking you to sign in again. GitHub's stated reason is damage control. In its words, "a leaked access token becomes unusable within hours instead of lasting indefinitely."
Three details from the announcement matter in practice:
It is opt-in. Existing sign-ins and tokens you supplied yourself are unaffected.
If the server on the other end does not support refreshable credentials,
ghfalls back to a normal nonexpiring token.It works on github.com and ghe.com. GitHub Enterprise Server supports it from GHES 3.23, and earlier versions fall back to nonexpiring behaviour.
GitHub says it plans to make expiring credentials the default for new sign-ins "in a future release", and gives no date. Treat that as a reason to test now rather than later.
How to opt in
You can opt in per sign-in or for every sign-in:
gh auth login --expiring
gh config set expiring_credentials enabledThe first command applies to one login and needs version 2.103.0 or newer. The second makes expiring credentials the setting for every sign-in from then on. To see what you currently have, run gh auth status, which shows the credential state and when the current access token expires.
If you use Git over HTTPS, GitHub strongly recommends running gh auth setup-git, so that gh provides and refreshes the credential for Git. It also recommends Git 2.46 or newer. Older versions still work, but show a one-time upgrade notice.
What breaks: tokens captured once
This is the part of the announcement worth reading twice. GitHub warns that scripts or tools that capture a token once and reuse it can break, because the token is now short-lived. The fix it gives is to read the token fresh each time with gh auth token instead of caching it.
Here is the pattern to look for. A setup script copies the token into a variable at the start and every later step reuses it:
export GH_TOKEN="$(gh auth token)" # captured once, may expire mid-runThat line is fine for a short script. It is a problem in anything long-lived, such as a terminal session an AI coding agent keeps open for hours, a container image with the token baked into an environment variable, or a scheduled job that starts once and runs for days. Once the access token expires, calls fail with an authentication error, and the cause is not obvious unless you know the token is now time-limited.
A short audit takes about ten minutes:
Search your scripts and shell profiles for
gh auth tokenand for any place a token is exported to an environment variable.For each hit, decide whether the process lives longer than a few hours. If it does, call
gh auth tokenat the moment of use instead.For workflows that genuinely need a long-lived token, GitHub's advice is not to opt in yet.
Why this matters if an AI agent uses your GitHub login
Agents that run gh for you inherit whatever your sign-in allows. A leaked token in a log, a pasted chat or a committed file is one of the commonest ways an agent setup goes wrong, which is the subject of what to do if an AI coding agent leaks a secret and whether an agent can leak your API keys. A token that dies within hours turns many of those mistakes from open-ended exposure into a short window.
This does not replace the other controls. Scope what the agent can reach with safe Git habits for AI coding agents, and remember that a refresh token is itself a credential worth protecting. The same week, GitHub also put the package firewall into public preview, which covers a different part of the same supply chain risk.
FAQ
Do I have to switch to expiring tokens?
No. The feature is opt-in, and existing sign-ins keep working. GitHub says it intends to make it the default for new sign-ins in a future release, without naming a date.
How do I check whether my token expires?
Run gh auth status. The output shows the credential state and when the current access token expires.
Will my scripts stop working?
Only the ones that capture a token once and reuse it for longer than its lifetime. Read the token fresh with gh auth token each time it is needed.
Does this work on GitHub Enterprise Server?
Support starts with GHES 3.23. Earlier versions fall back to a normal nonexpiring token.
How did this land?
About the author

Senior Editor, AI & Product
Cecilia leads the Swarmz editorial desk. She has spent a decade turning complex AI and product topics into writing people actually finish, and she owns the blog's quality bar.


