Switch between multiple Claude Code subscriptions (personal / work / API key) on macOS using Keychain.
Lightweight alternative (~80 lines of bash) to heavier solutions. No dependencies beyond Python 3 and macOS security CLI.
Three pieces:
claude-switch-auth— main script, swaps Keychain credentials between saved profilesclaude()wrapper in.zshrc— auto-switches profile based on current directory.envrc(direnv) — isolates Claude config per project (CLAUDE_CONFIG_DIR)
Supports both OAuth credentials (Claude Code-credentials service) and API key credentials (Claude Code service) — the correct keychain service is detected and stored per profile.
# 1. Put the script in PATH
cp claude-switch-auth ~/bin/
chmod +x ~/bin/claude-switch-auth
# 2. Save your current auth as a profile
claude-switch-auth save personal
# 3. Log into another account in Claude Code, then save it too
claude-switch-auth save work
# 4. (Optional) Add the wrapper to ~/.zshrc for auto-switching by directory
# See zshrc-wrapper.sh
# 5. (Optional) Per-project config isolation via direnv
# See dot-envrcclaude-switch-auth list # show saved profiles with service type
claude-switch-auth personal # switch to personal
claude-switch-auth work # switch to work
claude-switch-auth status # show current subscription/tier and service type
claude-switch-auth save <name> # save current keychain to profileWith the .zshrc wrapper, switching is automatic — just cd into the project directory and run claude.
Claude Code uses different keychain service names depending on auth method:
| Auth method | Keychain service name |
|---|---|
| OAuth (Pro/Max subscription) | Claude Code-credentials |
| API key | Claude Code |
This script detects and stores the service name per profile, so you can freely mix OAuth and API key profiles.
- macOS (uses
securityCLI for Keychain) - Python 3 (for JSON parsing and Keychain manipulation)
- direnv (optional, for config isolation)
- Profile files stored in
~/.claude-auth-profiles/withchmod 600 - Credentials never leave macOS Keychain except during profile swap
- No tokens in plain text, environment variables, or git
- ming86/cc-account-switcher — the original, now archived
- fairy-pitta/cc-account-switcher — full-featured fork with Homebrew, npm, 85 tests, directory-based auto-switching, rollback, dry-run, Linux/WSL support
- Madd0g's gist — OAuth + API key fix
- tannyusuf/switch-claude-code-accounts — PowerShell version for Windows
MIT