Skip to content

Instantly share code, notes, and snippets.

@LeZuse
Created April 27, 2026 18:49
Show Gist options
  • Select an option

  • Save LeZuse/e92877e2e647eff253076d7aa10931a2 to your computer and use it in GitHub Desktop.

Select an option

Save LeZuse/e92877e2e647eff253076d7aa10931a2 to your computer and use it in GitHub Desktop.
Claude Code Multiple Plan Subscriptions Switch
#!/bin/bash
# Switch Claude Code keychain credentials and launch
# Usage: cc-switch <profile> [claude args...]
# cc-switch team → launch with Team plan
# cc-switch max → launch with Max plan
# cc-switch which → show current active profile
KEYCHAIN_SVC="Claude Code-credentials"
TEAM_SVC="Claude Code-credentials-backup-team"
MAX_SVC="Claude Code-credentials-backup-extra"
ACCT="zuse"
profile="$1"
shift 2>/dev/null
case "$profile" in
team)
SOURCE_SVC="$TEAM_SVC"
;;
max)
SOURCE_SVC="$MAX_SVC"
;;
which)
CREDS=$(security find-generic-password -s "$KEYCHAIN_SVC" -a "$ACCT" -w 2>/dev/null)
if [ -z "$CREDS" ]; then
echo "No active credentials"
else
TYPE=$(echo "$CREDS" | python3 -c "import sys,json; print(json.load(sys.stdin).get('claudeAiOauth',{}).get('subscriptionType','unknown'))" 2>/dev/null)
echo "Active: $TYPE"
fi
exit 0
;;
*)
echo "Usage: cc-switch <team|max|which> [claude args...]"
exit 1
;;
esac
# Read source credentials
CREDS=$(security find-generic-password -s "$SOURCE_SVC" -a "$ACCT" -w 2>/dev/null)
if [ -z "$CREDS" ]; then
echo "Error: No credentials found for $profile ($SOURCE_SVC)"
exit 1
fi
# Remove current active entry if it exists
security delete-generic-password -s "$KEYCHAIN_SVC" -a "$ACCT" >/dev/null 2>&1
# Write the selected credentials as active
security add-generic-password -s "$KEYCHAIN_SVC" -a "$ACCT" -l "$KEYCHAIN_SVC" -w "$CREDS" >/dev/null 2>&1
echo "Switched to: $profile"
# Launch Claude Code (unset OAUTH token so keychain takes effect)
unset CLAUDE_CODE_OAUTH_TOKEN
exec claude --dangerously-skip-permissions "$@"
@LeZuse
Copy link
Copy Markdown
Author

LeZuse commented Apr 27, 2026

cc-switch: Multiple Claude Code Accounts

Switch between Claude Code subscriptions (e.g. Team + Max) via macOS Keychain.

Setup

1. Login and backup each account

Login with your first account:

claude /login

Backup the credentials (check the subscription type first):

security find-generic-password -s "Claude Code-credentials" -a "$(whoami)" -w | \
  python3 -c "import sys,json; print(json.load(sys.stdin).get('claudeAiOauth',{}).get('subscriptionType','?'))"

Save it under a backup name:

CREDS=$(security find-generic-password -s "Claude Code-credentials" -a "$(whoami)" -w)
security add-generic-password -s "Claude Code-credentials-backup-team" -a "$(whoami)" \
  -l "Claude Code-credentials-backup-team" -w "$CREDS"

Delete the active entry and repeat for your second account:

security delete-generic-password -s "Claude Code-credentials" -a "$(whoami)" >/dev/null 2>&1
claude /login
# ... then backup as "Claude Code-credentials-backup-max" (same steps, different name)

2. Install cc-switch

Put the cc-switch script in your PATH (e.g. ~/bin/cc-switch), make it executable. Update the TEAM_SVC and MAX_SVC variables to match your backup names.

3. Add aliases

alias teamcc='cc-switch team'
alias maxcc='cc-switch max'
alias ccwhich='cc-switch which'

Usage

teamcc           # launch with Team plan
maxcc           # launch with Max plan
maxcc -r myses  # launch with Max plan, resume session "myses"
ccwhich         # show active plan

How it works

Claude Code stores OAuth credentials in macOS Keychain under Claude Code-credentials. The script swaps the active entry with a backup before launching. Each running session caches credentials in memory, so swapping doesn't affect already-running sessions.

Important: Unset CLAUDE_CODE_OAUTH_TOKEN if set — it takes precedence over the keychain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment