Long-lived tokens are one of those security problems that everyone knows about and nobody enjoys fixing. A personal access token created two years ago and pasted into a dotfile, a shell history or a CI variable is a quiet liability. GitHub just gave the command-line tool a way to stop creating that kind of credential by default.
On October 21, GitHub announced a public preview of expiring, automatically refreshing OAuth credentials in GitHub CLI. It's opt-in, it's backward compatible and it will change how some of your scripts behave. Here is the practical version.
What changes
When you opt in, gh stores an expiring access token alongside a rotating refresh token, and refreshes the access token whenever it's needed. You stay signed in without re-authenticating. GitHub's pitch is that a leaked access token becomes unusable within hours, instead of staying valid indefinitely.
That's a meaningful improvement for a developer laptop. The usual way a GitHub token leaks isn't a dramatic hack. It's a screenshot, a committed .env file, a pasted terminal log or a compromised dev machine. A token that expires in hours turns most of those mistakes from "rotate everything" into "wait for it to lapse".
How to turn it on
You need GitHub CLI v2.103.0 or newer. Then there are two ways in:
- Log in with the new flag:
gh auth login --expiring. - Opt in for every future sign-in with
gh config set expiring_credentials enabled.
After that, GitHub says there's nothing new to run day to day, because gh refreshes the credential in the background. To see the state of an expiring credential, including when the current access token expires, run gh auth status.
A few details from GitHub's notes are worth keeping in mind:
- It's opt-in. If you don't use the flag or the setting, nothing changes. Existing sign-ins and manually supplied tokens keep working as before.
- You get whatever the server issues.
--expiringrequests refreshable credentials, and if a server doesn't support them,ghfalls back to a normal non-expiring token. - Expiring tokens are available on github.com and ghe.com today. GitHub Enterprise Server issues them starting with GHES 3.23. On earlier versions, opting in falls back to today's non-expiring behaviour.
- GitHub plans to make expiring credentials the default for new sign-ins in a future release.
The git part
Many people use gh as a convenience while git itself does the pushing and pulling. If you authenticate to git over HTTPS and want expiring tokens, GitHub strongly recommends setting up gh as your git credential helper by running gh auth setup-git. That lets gh serve and refresh the credential for git, so an expiring token is handled correctly.
GitHub also strongly recommends git 2.46 or newer. That version lets gh mark expiring credentials so git doesn't cache them past their lifetime. On older git versions gh still works, but it prints a one-time recommendation to upgrade.
Check your version with git --version. If you're on an older build, plan an upgrade before you switch.
What will break
This is the section to read twice. GitHub is direct about it: expiring access tokens are short-lived, so anything that captures a token once and reuses it later can break. The specific warning:
- Scripts and extensions that run
gh auth tokenand store the result will eventually be left holding an expired token. - Anything that copies the token into another tool has the same problem.
The fix GitHub gives is to read the token fresh each time with gh auth token, which refreshes it when needed rather than caching the value. If a workflow depends on a token that stays valid for a long time, hold off on opting in for that workflow.
Here's how I'd translate that into a plan for a team:
- Search your repositories, dotfiles and onboarding scripts for
gh auth token. Anything that stores the output, or exports it into an environment variable once per day, needs a rethink. - Check which tools take a token from
gh. Editor extensions, Docker build scripts and local helper scripts are the usual suspects. - Pilot with a small group of developers on laptops, where interactive use is the norm.
- Leave long-running automation alone for now. Unattended jobs are exactly where an expired token is hardest to notice.
If you've been following GitHub's recent supply chain security work, this fits the pattern. I wrote about the package firewall for npm installs and about pinning workflows with lockfiles. All three aim at the same thing: reduce what an attacker can reuse after a mistake or a compromise.
Expand
A laptop screen showing code, a stand-in for a developer terminal session
A ten-minute test plan
- Run
gh --versionand upgrade to v2.103.0 or newer. - Run
git --versionand make sure you're on 2.46 or newer if you use HTTPS remotes. - Run
gh auth login --expiringand complete the sign-in. - Run
gh auth setup-gitso thatghserves and refreshes the credential for git. - Run
gh auth statusand note when the access token expires. - Do a normal day of work: clone, fetch, push, open a pull request from the terminal. Come back the next morning and confirm nothing asked you to sign in again.
If step 6 fails for a particular tool, you've found the script that needed fixing. That's the point of testing on one machine first.
Is it worth doing now?
For most individual developers, I'd say yes. The cost is low if you mainly use gh interactively, and the downside risk of a stolen token drops sharply. The opt-in flag also makes it a low-commitment experiment. If something misbehaves, you can sign out and log in again without --expiring.
For teams, I'd wait for a quick audit. The failure mode isn't dramatic, it's annoying: a script that worked yesterday fails with an authentication error three hours later, and the cause isn't obvious unless you know to look at token expiry. Run the audit, then roll out.
One thing I haven't been able to verify: how Actions workflows and other non-interactive environments interact with the preview. GitHub's note focuses on interactive sign-ins and git credential handling. If your CI relies on gh with a stored token, test it in a throwaway repository first.
Expand
A developer's laptop with code on screen
Should you care?
Yes, in a quiet way. Short-lived credentials are one of the few security upgrades that don't require developers to change their habits much, and GitHub says it intends to make them the default eventually. Learning how they behave now, on your own schedule, beats finding out when the default flips and your scripts fail all at once.
Frequently Asked Questions
How do I enable expiring tokens in GitHub CLI?
Update to v2.103.0 or newer, then run gh auth login --expiring, or run gh config set expiring_credentials enabled to opt in for every sign-in.
Do I need to change my git setup?
If you use git over HTTPS, GitHub strongly recommends gh auth setup-git and git 2.46 or newer.
Will my existing sign-ins stop working?
No. The feature is opt-in and backward compatible, and existing sign-ins and manually supplied tokens keep working.
Which scripts will break?
Any that run gh auth token once, store the result and reuse it later, because the stored access token will eventually expire.
Originally published on Mango Developer.


Top comments (1)
Mango, the line I'd underline is that the failure mode 'isn't dramatic, it's annoying.' A script that ran fine for a year quietly holding an expired token is exactly the kind of breakage that wastes a morning before anyone suspects the credential. Your step 1 — searching repos, dotfiles and onboarding scripts for
gh auth token— is the part most people will skip and regret.The detail I'd add to the checklist: the refresh token itself. The access token expiring in hours is the headline, but the rotating refresh token is what makes the whole thing work day to day — and it's the thing that has to survive in the credential store. If a laptop's keychain gets wiped or a dev machine is re-imaged, the refresh token goes with it and you're back at
gh auth login. Worth testing once on purpose, before it happens by accident.One open question from your 'unverified' note: does the background refresh work in a headless container, or does it need an interactive sign-in the first time? That's the answer that decides whether long-running automation can ever opt in. Have you tried it in a throwaway repo yet?