The missing profile switcher for
claude code
Switch Claude Code OAuth tokens between accounts. Tokens are stored in the OS keyring (macOS Keychain / Linux libsecret) and validated against claude auth status before they land.
CLAUDE_CODE_OAUTH_TOKEN is a single env var but most people have more than one account (work, home, client). This gives you one command to rotate it without plaintext files or re-running the OAuth flow.
bash install.sh
Installs cc-switch to ~/.local/bin/ and prints the line to add to your shell rc file:
source /path/to/cc-switch/shell/cc-switch.sh
Reload your shell. Done.
claudeCLI inPATH(Claude Code subscription, forsetup-tokenandauth status)- macOS: nothing extra (
securityis built-in) - Linux:
secret-tool—apt install libsecret-tools/dnf install libsecret/pacman -S libsecret jqis used if present; falls back tosedotherwise
cc-switch add work # runs `claude setup-token`, validates, stores
cc-switch add home # (log out / switch browser account first)
cc-switch work # switch active account (shorthand)
cc-switch use work # explicit form
cc-switch current # show active account
cc-switch unset # clear CLAUDE_CODE_OAUTH_TOKEN
cc-switch list # show stored accounts and their emails
cc-switch remove work # delete an account
cc-switch backend # print keyring backend in use
Non-interactive seed:
echo "$TOKEN" | cc-switch set work
- Binary (
bin/cc-switch) handles keyring I/O and an index file at$XDG_DATA_HOME/cc-switch/accounts(format:name<TAB>email). Token values live only in the keyring. - Shell function (
shell/cc-switch.sh) wraps the binary sousecanexportinto the current shell. A bare name likecc-switch workis rewritten touse workunless it collides with a reserved subcommand. - Validation: on
add/set, the candidate token is probed viaCLAUDE_CODE_OAUTH_TOKEN=<token> claude auth status --json. A token is accepted only whenloggedIn == trueandemailis non-empty. The resulting email is stored in the index and used to reject duplicate-email adds under different names.
- You must log in as a different account in the browser between
cc-switch addruns, otherwise both tokens resolve to the same email and the second add is rejected. claude auth statusfalls back to the Keychain session whenCLAUDE_CODE_OAUTH_TOKENis empty or unset — the binary guards against empty input so that fallback can't leak into validation.- Re-adding an existing account (e.g. after token rotation) is allowed; the index row is replaced in place.
cc-switch/
bin/cc-switch # CLI: add/set/get/list/remove/backend
shell/cc-switch.sh # shell wrapper: use/unset/current + bare-name dispatch
install.sh # symlink binary, print source line, verify backend