Developer Evgeny Potapov published github-cli-yubikey on November 24, an unofficial fork of GitHub CLI (gh) for macOS that encrypts the stored credential with a key held on a YubiKey and only releases usable tokens during a session unlocked with a PIN and a physical touch. The project targets a risk that has grown with AI coding agents running terminal commands under the developer’s own account: on a standard install, any process running as that user can read the GitHub token with a single command.
Key points on github-cli-yubikey in 20 seconds
- Standard gh on macOS keeps the token in the Keychain, readable without a password prompt by processes running as the user.
- The fork encrypts the refresh token with a key that never leaves the YubiKey.
- It is unofficial, macOS-only, newly published and unaudited.
The problem is documented by GitHub CLI itself. On macOS, gh stores the token in the Keychain and reaches it through the system utility /usr/bin/security, so any process that calls that same utility is already authorized and usually sees no password prompt. The stored value carries a go-keyring-base64 prefix, which is encoding, not encryption. And gh auth token prints the token to whoever runs it. With the default login scopes (repo, read:org and gist), that token grants full access to the user’s public and private repositories.
How the YubiKey fork works
The YubiKey generates a P-256 key pair in PIV slot 83, and the private key cannot leave the device. The fork uses it to encrypt the refresh token with ECDH, HKDF-SHA256 and AES-256-GCM, the same scheme used by age-plugin-yubikey. Access tokens are never written to disk: they live in memory and are served to gh through a local socket by an agent process.
# One-time setup: create the key on the YubiKey, then log in
gh auth setup-yubikey
gh auth login
# Open a session with PIN and touch (one hour by default)
gh auth unlock
gh auth unlock --for 30m
# Close the session and invalidate the token
gh auth lock
Sessions last one hour by default and can be set anywhere up to eight hours. On unlock, the tool exchanges the refresh token for a new pair, re-encrypts the new refresh token and verifies the account. A session ends on lock, on timeout or two seconds after the YubiKey is unplugged. Locking spends the refresh token, which invalidates the previous one; the author reports that a copied token returns a 401 error after locking.
What it does not protect against
The author documents the limits in the repository’s YUBIKEY.md file. While a session is open, any process running as the user can still request a token, which is the window an AI agent works in. A program able to read other processes’ memory could grab the refresh token. Anyone who can modify gh’s configuration can redirect its traffic. A kill -9 or a power cut leaves the last token valid for up to eight hours, and with two YubiKeys connected, removing one does not end the session.
There are practical costs too. The fork runs only on macOS, must be compiled from source and needs Git 2.46 or later. It replaces the official gh, so Homebrew stops updating it. It ignores the GH_TOKEN and GITHUB_TOKEN environment variables, rejects –with-token and does not read or clean the Keychain, so old tokens stay there. The GitHub CLI authorization should be revoked before installing. Above all, it is an unofficial, newly published and unaudited project sitting in the middle of a credential with full repository access.
GitHub’s own answer: expiring tokens
Teams that do not want to swap their CLI have an official option that narrows part of the same risk. On October 21, 2026, GitHub launched a public preview of expiring, automatically refreshing OAuth credentials in GitHub CLI, available from version 2.103.0. Once opted in, gh stores a short-lived access token alongside a rotating refresh token and renews them as needed, so a leaked access token stops working within a few hours. It is available on github.com and ghe.com, and on GitHub Enterprise Server from 3.23; GitHub recommends running gh auth setup-git if git also authenticates over HTTPS.
Expiring tokens do not stop a local process from reading the current token, which is the scenario the YubiKey fork addresses. Reducing scopes helps in both cases: fine-grained personal access tokens can be limited to specific repositories and permissions, and agents can run under a separate account or in a sandbox with only the access they need.
Frequently asked questions
Where does GitHub CLI store the token on macOS?
In the Keychain, accessed through /usr/bin/security. Any process running as the user can usually read it without a password prompt.
Does github-cli-yubikey work on Linux or Windows?
No. It is macOS-only and must be compiled from source.
Does it stop an AI agent from using my token?
Only while no session is open. During an unlocked session, any process running as the user can still request a token.
Is there an official alternative?
GitHub CLI 2.103.0 and later offer opt-in expiring, auto-refreshing tokens in public preview, which limit how long a leaked token remains valid.
Sources:

