TokenSwap for Claude Code
Switch the account Claude Code uses in VS Code, Cursor or Antigravity from the status bar, without signing in again.
Install
VS Code: search for TokenSwap for Claude Code in the Extensions view, or run:
code --install-extension dmt2103.tokenswap-for-claude-code
Cursor and Antigravity do not list it in their Extensions view. Download tokenswap-for-claude-code-<version>.vsix from the latest release, then run Extensions: Install from VSIX… from the Command Palette and pick the file. In Cursor you can also run:
cursor --install-extension tokenswap-for-claude-code-<version>.vsix
Installed this way it does not update itself: install the new .vsix from the releases page to update.
It runs on macOS and Windows (x64 and ARM), and needs the Claude Code extension (anthropic.claude-code, from the editor's Extensions view) and a Claude subscription (Pro, Max, Team or Enterprise). It uses the claude CLI bundled in the Claude Code extension (claude.exe on Windows), so nothing else needs installing.
How it works
- Each account is a long-lived login token made once with
claude setup-token.
- Tokens are kept in the editor's SecretStorage (the OS credential store). Account emails are kept in the extension's global state.
- Switching writes the chosen token as
CLAUDE_CODE_OAUTH_TOKEN into the Claude Code setting claudeCode.environmentVariables, then offers to reload the window. The Claude Code CLI prefers that variable over the login saved in ~/.claude.
- The editor's integrated terminals get the same
CLAUDE_CODE_OAUTH_TOKEN, so claude typed in one uses the switched account too. A terminal opened after the switch has it at once; one already open shows that it needs a relaunch (the editor's own warning on the terminal tab) and keeps the old account until relaunched. Terminals outside the editor are not touched and keep using the /login account.
- Each saved token is treated as expired 30 days after it was saved (a fixed period, not a setting). An expired account shows a warning, cannot be switched to, and is not read for usage; its token is kept, and nothing in your settings changes until you renew or remove it. The token itself stays valid on Anthropic's side until it really expires (about a year), so this is only the extension's own reminder to rotate it.
- Default login removes the variable, so Claude Code goes back to the account signed in with
/login.
- When a token is added or renewed, the extension runs one tiny Haiku turn with it (the same as a usage read) before saving it. If the turn fails, it shows Claude Code's error and asks whether to save the token anyway. The usage that turn read is kept, so the new account is not read again for it.
The setting claudeCode.environmentVariables is machine-scoped, so Settings Sync does not upload it. It does sit as plain text in your user settings.json, as the /login credentials do in ~/.claude/.credentials.json. Do not commit that file if you keep your editor settings in a dotfiles repository. The token is also in the environment of every integrated terminal (where any program run in it can read it, as it could read settings.json); the editor does not keep it in its own storage, the extension sets it again each time the window starts. The Create a token now terminal clears the variable on the command line it types, so claude setup-token runs with no token.
Use
Click the account name (next to the extension's logo) at the left of the status bar, or run TokenSwap: Switch Account.
Add account…: first the token, either
- Create a token now: a terminal runs
claude setup-token. Sign in to that account in the browser page it opens (sign out of claude.ai there first if another account is signed in), then copy the sk-ant-oat… token from the terminal and paste it.
- Paste a token I already have.
The token is checked (see above), then you enter the email the account signs in to claude.ai with, which names it. Nothing is saved if you cancel at any step.
Pick an account. Reload the window when asked, and Claude Code uses it.
Renew token… (in the same menu, or TokenSwap: Renew Account Token) gives an account a new token, made or pasted the same way as when adding it, and starts its 30 days again. Picking an expired account in the menu, or Renew in its tooltip row, does the same. The new token must differ from the one saved. If the account is the active one, the setting gets the new token and you are asked to reload.
Names
An account is named by its email. A setup-token token cannot tell its own email (it lacks the user:profile scope, and the CLI prints none), so Add account asks for it. The /login account's email is read from claude auth status, which makes no request, when the window opens and whenever it gets focus; until it is known, or with no login, it is called Default login.
Usage on hover
Hover over the account name in the status bar to see the plan usage of every account: each saved account and the /login account (Default login). Every account shows the same two rows, Current session and Current week (all models), with the percent used and when it resets, written the way /usage writes it (Dec 2 at 8pm). A setup-token account cannot read the weekly window of a single model, so the /login account's extra rows such as Current week (Fable) are left out too. An account whose token has expired shows only Token expired and a Renew link, in red, at the bottom with the accounts at their limit, and has no Switch link. An account that has hit its limit (the session or the week at 100%) shows only Limit reached and when it resets. The active account is always at the top, in green, even at its limit; the other accounts at their limit are at the bottom, in red. The colours are the theme's chart green and red. The active account has a check mark. Switch after an account's name (every account but the active one and those at their limit) switches to it right there, the same as picking it from the status bar list (with the same warning for an unsaved token and the same reload). A saved account that is not active and has not been read yet shows not read, with a Refresh link. Refresh in the tooltip (or TokenSwap: Refresh Usage) reads every account again now.
The API refuses subscription tokens outside Claude Code, so the extension asks the CLI bundled in the Claude Code extension instead:
- Default login:
claude -p /usage, which makes no model request.
- Saved accounts:
/usage shows nothing for a setup-token token (it lacks the scope to read usage), so the CLI runs one tiny Haiku turn with no tools, the token in CLAUDE_CODE_OAUTH_TOKEN, and the extension reads the 5-hour and weekly usage from the rate-limit event Claude Code reports for that turn. Each read uses a little of that account's quota: about 3,900 input tokens and 4 output tokens on Haiku (about $0.00065 at API list prices, measured with Claude Code 2.1.332). Most of the input is written to the prompt cache again on every read, so a read costs about the same each time.
Either way the CLI runs in the temp folder with no user settings, hooks, plugins or MCP servers, and saves no session. Accounts are read one at a time, a few seconds each. Only the active account and the /login account are read on their own: when the window opens, then at the start of every hour (within a minute of 10:00, 11:00, … local time) while the window has focus, and when the window gets focus again after missing one (in the background), once. After the machine sleeps, the hour that passed is caught up within a minute of waking. A window in the background reads nothing. A read that failed (offline, a timeout) is tried again the next time the window gets focus or the menu opens, at least 5 minutes after it failed, without waiting for the hour. The other saved accounts are read only when you ask, so their quota is not spent in the background:
- Opening the account menu (clicking the status bar): it opens at once with each account's last usage under its name (
48% session · 51% week, limit reached · resets …, or not read), reads the accounts not read yet this hour, and fills them in as they come. Those reads go on if you close the menu, and show in the tooltip. Opening it again in the same hour reads nothing more.
- Refresh, which reads every account.
- Add account and Renew token, whose check of the new token is that account's read.
The tooltip says when the active account was last read. An expired account is never read, even when it is the active one. Set claudeAccounts.showUsage to false to turn all of this off.
claudeAccounts.reloadAfterSwitch can be ask (the default: a notification offers Reload), always or never. With never, or until you reload, new Claude Code sessions use the new account and open ones keep the old one.
Limits
ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN take priority over the token. The extension warns when one is set.
- A saved token counts as expired after 30 days, whatever its real lifetime; renew it to keep switching to that account. The 30 days are counted from the time saved on this machine, so they are not synced and restart if the extension's data is cleared.
- Removing an account deletes its token from the editor only. The token stays valid until it expires (about a year).
- A saved account's usage row shows Claude Code's error when its turn fails, for example an expired token.
- This relies on the
claudeCode.environmentVariables setting of the Claude Code extension, which Anthropic may change.
Develop
npm test # unit tests (node:test)
npm run coverage # with coverage
npx @vscode/vsce package # builds tokenswap-for-claude-code-<version>.vsix
code --install-extension tokenswap-for-claude-code-*.vsix # try it locally
npx @vscode/vsce publish # Visual Studio Marketplace; needs `vsce login dmt2103` once
gh release create v<version> tokenswap-for-claude-code-<version>.vsix # the .vsix for Cursor and Antigravity
The status bar logo is a one-colour glyph (U+E001) in logo-icon.woff, declared under contributes.icons as tokenswap-logo, because the status bar draws icons from fonts only. make-logo.py draws icon.svg, icon.png and logo-icon.woff from the same shapes, with thicker arrows in the glyph so it stays readable at 16 px. To change the logo, edit it and run it from this folder with a Python that has fontTools (rsvg-convert must be on PATH).