Skip to content

Rotating tokens

Which tokens a script can create, and which have to be pasted:

Service Variables How rotate.sh gets a new one Old one removed by
GitHub GITHUB_TOKEN, GITHUB_PERSONAL_ACCESS_TOKEN gh auth login device flow into a throwaway config: confirm a code at github.com/login/device on any device rotate.sh clean, via GitHub's credential revocation API
Context7 CONTEXT7_API_KEY (stored as Bearer ctx7sk-…) ctx7 login device flow into a throwaway config; the CLI receives an API key hand, in the dashboard
Sonatype Guide SONATYPE_GUIDE_TOKEN pasted, hidden input—no API hand, in the dashboard
Aikido AIKIDO_API_KEY pasted, hidden input—no API hand, in the dashboard

GitHub has no API that creates a personal access token, classic or fine-grained. The device flow is the scriptable substitute, and it never passes through the clipboard. It yields an OAuth token (gho_…) of the GitHub CLI app with the classic scopes repo, read:org, project, workflow and user. The token:

  • shows up under Settings → Applications → Authorized OAuth Apps → GitHub CLI, not under Tokens;
  • does not expire;
  • is revoked alone by rotate.sh clean. Revoking the whole GitHub CLI app on that page would also sign out gh on every other machine.

For a real classic PAT (ghp_…, with an expiry), use rotate.sh rotate github --github-method paste. It prints the creation page with the scopes preselected and reads the token with hidden input.

Every new value is tested before it is staged. The sandboxes use it from their next request on, because their token helper reads the token file on every refresh. The home session, if it runs, uses it only after systemctl --user restart claude-remote (#319, no root needed). Replaced GitHub tokens are kept in ~/.config/claude-dev-doctor/revoke-pending (mode 0600). clean revokes them only once the home session no longer uses them; revoking earlier would cut off the running session. clean asks before every step.

Which account

The service's sessions act as the bot account, not as the owner (sdlc/repository-setup.md). The device flow grants a token to whoever is signed in to GitHub on the device where the code is confirmed. So sign in there as the bot; a private browser window keeps the owner's own session apart.

rotate.sh and status.sh ask GitHub which account a token belongs to and compare it with CLAUDE_GITHUB_LOGIN. They read that from the environment, else from the token file, where set-token.sh CLAUDE_GITHUB_LOGIN stores it. When it is unset, the checks warn that the account is not checked, and rotate.sh rotate github refuses to get a new token: it could not tell whose it is.

A token of another account is refused like a 401. It works everywhere, so nothing else would catch it. A token that lacks one of the scopes above fails the check too. user is the one an older token lacks. It covers:

  • user:email, which dev-env:dev-doctor needs to compare the commit email with the account;
  • the account's billing report of Copilot premium requests (gh api users/<bot login>/settings/billing/premium_request/usage).

user is broader than that need—it includes write access to the profile—and the owner accepted it (#518). An older token gets the scope with rotate.sh rotate github, then systemctl --user restart claude-remote, then rotate.sh clean. The shared check is scripts/linux/github-account.sh, tested by scripts/tests/github-account-test.sh.

From the owner's workstation

From the owner's workstation, scripts/windows/Invoke-RemoteRotate.ps1 (scripts/windows/README.md) runs the same over SSH.

None of the four services offers an API that lists a user's tokens. Tokens the scripts never saw can only be reviewed by hand; rotate.sh prints the pages.