@baizor/cc-switch
v0.1.14
Published
Manage multiple Claude Code subscription OAuth tokens from a TypeScript CLI.
Maintainers
Readme
cc-switch
cc-switch is a TypeScript CLI for managing multiple Claude Code subscription OAuth tokens.
It uses only official Claude Code status-line telemetry. The collector records rate_limits snapshots when Claude Code passes them to a status-line command; it does not call undocumented quota endpoints.
Install
npm install -g @baizor/cc-switchQuick Start
- Generate a Claude Code OAuth token:
claude setup-tokenApprove the browser prompt, then copy the token printed in the terminal.
- Add the subscription to cc-switch:
cc-switch add subscriptionPaste the token when prompted. Repeat claude setup-token and cc-switch add subscription for each Claude subscription account you want to manage.
- Install the Claude Code status-line collector:
cc-switch install status-lineThis lets cc-switch receive official Claude Code rate_limits telemetry. Restart Claude Code, or send one prompt in a trusted workspace, so Claude Code emits fresh status-line data.
- Install the background monitor service:
cc-switch install serviceOn Windows, run this from an Administrator PowerShell if Task Scheduler reports Access is denied.
- Check setup:
cc-switch doctor status-line
cc-switch service status- Open the dashboard:
cc-switchThe dashboard should show your active subscription, stored telemetry, reset time, service status, and switch decision.
Commands
cc-switch
cc-switch config
cc-switch add subscription
cc-switch remove subscription 1
cc-switch list subscriptions
cc-switch status
cc-switch switch 0
cc-switch install service
cc-switch uninstall service
cc-switch service status
cc-switch install status-lineConfiguration
By default, configuration is stored at ~/.cc-switch/.env and state at ~/.cc-switch/state.json.
Important .env keys:
CC_SWITCH_TOKENS=["token-one","token-two"]
CC_SWITCH_TOKEN_LABELS=["Work","Personal"]
CC_SWITCH_POLL_SECONDS=60
CC_SWITCH_FIVE_HOUR_MIN_LEFT_PERCENT=10
CC_SWITCH_WEEKLY_MIN_LEFT_PERCENT=10
CC_SWITCH_SWITCHING_MODE=env
CC_SWITCH_LOG_LEVEL=info
CC_SWITCH_SERVICE_AUTOSTART=true
CC_SWITCH_STATE_PATH=
CC_SWITCH_CREDENTIALS_PATH=env mode writes the active token into cc-switch managed environment files and uses setx on Windows for new shells. credentials-file mode is experimental and writes a guarded JSON credentials file only when explicitly enabled.
A claude setup-token token carries no refresh token, and CLAUDE_CODE_OAUTH_TOKEN takes priority over ~/.claude/.credentials.json. So when a token added to env mode expires, every new Claude Code session fails with 401 OAuth access token has expired and /login does not help while the variable is still set: it overrides the freshly refreshed credentials file. Recover by clearing the user-level variable, then either issue a new token with claude setup-token or use credentials-file mode, which switches refreshable credentials.
[Environment]::SetEnvironmentVariable('CLAUDE_CODE_OAUTH_TOKEN', $null, 'User')Experimental Ongoing-Session Switching
CLAUDE_CODE_OAUTH_TOKEN is the documented switching path, but already-running Claude Code sessions may not reload environment variables. For experiments, credentials-file mode can switch the full Claude Code /login profile stored in ~/.claude/.credentials.json.
For each subscription:
claude auth login
cc-switch import credentials 0Repeat with the matching subscription index after logging Claude Code into each account. Then set CC_SWITCH_SWITCHING_MODE=credentials-file in cc-switch config.
This stores the full claudeAiOauth object, including refresh tokens when present, inside ~/.cc-switch/state.json. Keep that file private. This mode edits an undocumented Claude Code implementation file and may require restarting Claude Code if the running process keeps credentials in memory.
Status-Line Collector
Quota telemetry reaches cc-switch only through the Claude Code status line, so the collector installs itself when the dashboard starts and when the background service is installed. The dashboard menu carries an explicit entry too, and the header shows whether Claude Code currently runs the collector - read from settings.json, not from a cached flag.
cc-switch install status-line
cc-switch uninstall status-lineInstalling wraps an existing Claude Code statusLine command if one is present and forwards its output unchanged while recording official rate_limits snapshots. Re-running the install collapses an earlier collector instead of nesting a second one inside it. Uninstalling puts the wrapped command back.
Verify the integration:
cc-switch doctor status-lineRestart Claude Code, or send one prompt in a trusted Claude Code workspace, so Claude Code emits fresh status-line telemetry. rate_limits appears only for Claude.ai Pro/Max subscribers after the first API response.
Background Service
Install the per-user monitor:
cc-switch install serviceCheck it:
cc-switch service statusRemove it:
cc-switch uninstall serviceOn Windows, Task Scheduler may require an elevated PowerShell. If install reports Access is denied, open PowerShell as Administrator and rerun:
cc-switch install serviceThe service does not fetch Claude Code quota data by itself. It watches the telemetry stored by the status-line collector and switches when configured thresholds are crossed.
Publishing
This package is configured for npm Trusted Publishing through .github/workflows/publish.yml.
On npmjs.com, configure the trusted publisher for @baizor/cc-switch with:
- Publisher: GitHub Actions
- Organization or user:
IvanMurzak - Repository:
Claude-Subscription-Switcher - Workflow filename:
publish.yml - Allowed action:
npm publish
For the first manual publish, run npm publish --access public from a local npm login. Do not enable local provenance for this first publish; provenance is generated by the GitHub Actions trusted publisher after npm is configured.
After the trusted publisher is configured, publish by running the Publish to npm workflow manually from GitHub Actions. When npm publish succeeds, the workflow creates a matching GitHub Release named v<package.json version> with GitHub-generated release notes.
You can also publish by creating a GitHub Release first. In that case, the release tag must match the package version, for example v0.1.4.
