Skip to content

Instantly share code, notes, and snippets.

@KMJ-007
Created July 22, 2025 13:17
Show Gist options
  • Select an option

  • Save KMJ-007/0979814968722051620461ab2aa01bf2 to your computer and use it in GitHub Desktop.

Select an option

Save KMJ-007/0979814968722051620461ab2aa01bf2 to your computer and use it in GitHub Desktop.

Manage Multiple Claude Code Accounts

Run two Claude Code accounts simultaneously on macOS without re-authenticating by using separate configuration directories.

Steps

  1. Create Separate Config Directories

    mkdir ~/.claude-account1
    mkdir ~/.claude-account2
  2. Add Aliases to Shell Config

    • Open ~/.zshrc (or ~/.bashrc for Bash) in an editor:
      nano ~/.zshrc
    • Add:
      alias claude-account1="CLAUDE_CONFIG_DIR=~/.claude-account1 claude"
      alias claude-account2="CLAUDE_CONFIG_DIR=~/.claude-account2 claude"
    • Save and reload:
      source ~/.zshrc
  3. Authenticate Each Account

    • For account 1:
      claude-account1
      Log in; credentials save to ~/.claude-account1.
    • For account 2:
      claude-account2
      Log in; credentials save to ~/.claude-account2.
  4. Switch or Run Simultaneously

    • Run claude-account1 or claude-account2 in separate terminal tabs (Cmd + T).
    • Each uses its own config and usage limits.

Notes

  • Requires separate Anthropic accounts (different emails).
  • Check Anthropic’s terms to ensure compliance.
  • Update Claude Code: npm install -g @anthropic-ai/claude-code.
  • If re-authentication occurs, verify CLAUDE_CONFIG_DIR with echo $CLAUDE_CONFIG_DIR.
@CJ-Hurc
Copy link

CJ-Hurc commented Nov 30, 2025

Will this work with the vs code extension?

@enimiste
Copy link

enimiste commented Dec 30, 2025

alias claude-perso="CLAUDE_CONFIG_DIR=~/.claude-perso command claude"
alias claude-pro="CLAUDE_CONFIG_DIR=~/.claude-pro command claude"
alias claude="echo 'Use claude code specific commandes : claude-perso or claude-pro'"

Edited after @edzme comment :
-command : is a shell command that ignores alias. This avoid us using absolute path to claude command.

@Ben-CA
Copy link

Ben-CA commented Jan 5, 2026

Is there a way to do this on Windows?

@edzme
Copy link

edzme commented Feb 13, 2026

Thanks for posting this and good idea @enimiste .. here's mine edited slightly:

# Example: switch between multiple Claude config directories

alias claude-profile1='CLAUDE_CONFIG_DIR=$HOME/.claude-user-profile1 command claude'
alias claude-profile2='CLAUDE_CONFIG_DIR=$HOME/.claude-user-profile2 command claude'
alias claude-profile3='CLAUDE_CONFIG_DIR=$HOME/.claude-user-profile3 command claude'

# Disable default claude command to prevent mistakes
alias claude="echo 'Use claude-profile1, claude-profile2, or claude-profile3'"

@Eikeskog
Copy link

Eikeskog commented Feb 24, 2026

Is there a way to do this on Windows?

Create config directories

mkdir $env:USERPROFILE\.claude-account1
mkdir $env:USERPROFILE\.claude-account2

Add functions to your PowerShell profile

notepad $PROFILE

function claude-account1 { $env:CLAUDE_CONFIG_DIR="$env:USERPROFILE\.claude-account1"; claude }
function claude-account2 { $env:CLAUDE_CONFIG_DIR="$env:USERPROFILE\.claude-account2"; claude }

Save, then reload:
. $PROFILE

Authenticate each — run claude-account1 and claude-account2 in separate terminals, log in each one.

Use simultaneously — open two terminal tabs, one per account, each with its own credentials and usage limits.

@creamartin
Copy link

While using multiple accounts I kept losing context when a session hit the 5-hour limit mid-flow. Built a hook that monitors
usage per account and silently warns Claude at 95% so it can save memory/notes before the session cuts off. Maybe it's useful to someone.

5. Monitor Usage Limits per Account

When running multiple accounts, you want to know when a specific account is approaching its 5-hour usage limit. This hook
automatically warns Claude at 95% usage — per account — using CLAUDE_CONFIG_DIR to target the right credentials.

Create the hook script (repeat for ~/.claude-account2/hooks/):

mkdir -p ~/.claude-account1/hooks
nano ~/.claude-account1/hooks/session-age-warn.sh

Paste:

#!/bin/bash
# Warn when Claude Pro 5-hour usage hits 95%.
# Runs as a UserPromptSubmit hook; receives JSON payload on stdin.

cat > /dev/null  # drain stdin

# Derive keychain service name from config dir (sha256 prefix, same as Claude Code)
config_dir="${CLAUDE_CONFIG_DIR:-$HOME/.claude}"
hash=$(python3 -c "import hashlib,sys; print(hashlib.sha256(sys.argv[1].encode()).hexdigest()[:8])" "$config_dir" 2>/dev/null)
svc="Claude Code-credentials-${hash}"

creds=$(security find-generic-password -s "$svc" -w 2>/dev/null)
if [ -z "$creds" ]; then exit 0; fi

TOKEN=$(echo "$creds" | python3 -c "
import sys, json, time
d = json.load(sys.stdin)
oauth = d.get('claudeAiOauth', {})
expires = oauth.get('expiresAt', 0)
token = oauth.get('accessToken', '')
if token and int(time.time()*1000) < expires:
    print(token)
" 2>/dev/null)

if [ -z "$TOKEN" ]; then exit 0; fi

response=$(curl -s "https://api.anthropic.com/api/oauth/usage" \
  -H "Authorization: Bearer $TOKEN" \
  -H "anthropic-beta: oauth-2025-04-20" \
  -H "User-Agent: claude-code/2.0.32" 2>/dev/null)

utilization=$(echo "$response" | python3 -c "import sys,json; d=json.load(sys.stdin);
print(int(d['five_hour']['utilization']))" 2>/dev/null)

if [ -z "$utilization" ]; then exit 0; fi

if [ "$utilization" -ge 95 ]; then
  echo "{\"hookSpecificOutput\": {\"hookEventName\": \"UserPromptSubmit\", \"additionalContext\": \"[5-hour usage at
${utilization}% — update memory files before this session ends.]\"}}"
fi
chmod +x ~/.claude-account1/hooks/session-age-warn.sh

Register the hook in ~/.claude-account1/settings.json:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "/Users/YOUR_USERNAME/.claude-account1/hooks/session-age-warn.sh"
          }
        ]
      }
    ]
  }
}

Repeat for ~/.claude-account2/, pointing the command path to that directory.

How it works:

  • Claude Code stores credentials in macOS Keychain under a key derived from CLAUDE_CONFIG_DIR (sha256 prefix). The hook uses
    the same derivation to look up the right account's token.
  • It calls https://api.anthropic.com/api/oauth/usage and checks five_hour.utilization.
  • At 95%+, it injects a silent context warning that Claude sees on your next message, prompting it to save memory/notes before
    the session ends.
  • Silently skips if the token is expired or the API is unreachable.

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