Skip to main content
EMil Wu

Running Multiple Claude Code Accounts at the Same Time

You have two Claude accounts with different token quotas and want to run them at the same time without interference. Here are three approaches, ordered from simple to advanced.


Background: Claude Code Authentication Priority

When Claude Code starts, it determines your identity in the following order (highest to lowest):

1. ANTHROPIC_API_KEY (environment variable)
2. apiKeyHelper (a script defined in settings.json)
3. OAuth login (token saved by claude login)

Key point: once ANTHROPIC_API_KEY is set, it overrides OAuth login.

The other critical environment variable:

  • CLAUDE_CONFIG_DIR — specifies where config and credentials are stored; defaults to ~/.claude/

Method 1: Same Machine — OAuth for Some Directories, API Key for Others

Use case: Your primary account uses a Pro/Max subscription (OAuth), and specific projects use another account’s API Key.

Setup

Create a .claude/settings.json (project-level settings) in the root of the project where you want to use an API Key:

{
  "env": {
    "ANTHROPIC_API_KEY": "sk-ant-your-second-account-key"
  }
}

Or, if you’d rather not write the key into a file, use direnv (.envrc):

# project-root/.envrc
export ANTHROPIC_API_KEY="sk-ant-your-second-account-key"
direnv allow

Result

~/project-a/  → no ANTHROPIC_API_KEY set → uses OAuth (Account A)
~/project-b/  → ANTHROPIC_API_KEY set via .envrc → uses API Key (Account B)

Open each directory in a separate terminal and they run completely independently.

Notes

  • API Key takes priority over OAuth, so the API Key path is always used when the environment variable is present
  • When you leave the directory (direnv automatically unsets it), OAuth is restored
  • If you use the .claude/settings.json approach, remember to add it to .gitignore

Method 2: Different Directories Use Different API Keys (Both Accounts Have API Keys)

Use case: Both accounts have Console API Keys and you want to allocate quota by project.

Setup

Set a separate .envrc for each project:

# ~/work-project/.envrc
export ANTHROPIC_API_KEY="sk-ant-account-a-key"

# ~/side-project/.envrc
export ANTHROPIC_API_KEY="sk-ant-account-b-key"
cd ~/work-project && direnv allow
cd ~/side-project && direnv allow

Or use shell aliases

# ~/.zshrc
alias claude-work='ANTHROPIC_API_KEY="sk-ant-account-a-key" claude'
alias claude-side='ANTHROPIC_API_KEY="sk-ant-account-b-key" claude'

Result

# Terminal 1
cd ~/work-project
claude          # → Account A API Key

# Terminal 2
cd ~/side-project
claude          # → Account B API Key

Verification

Once inside Claude Code, run /status to confirm which identity is active.


Method 3: Use CLAUDE_CONFIG_DIR to Isolate Two OAuth Subscription Accounts

Use case: Both accounts are Pro/Max subscriptions with no API Key — each needs its own OAuth login.

How it works

Claude Code stores credentials in CLAUDE_CONFIG_DIR (default: ~/.claude/). Pointing to different directories means completely independent login states.

Initial setup (one-time only)

# Terminal 1 — Account A
export CLAUDE_CONFIG_DIR="$HOME/.claude-account-a"
claude
# Directory is empty → login flow starts automatically → sign in with Account A's email
# Credentials are saved to ~/.claude-account-a/
# Terminal 2 — Account B
export CLAUDE_CONFIG_DIR="$HOME/.claude-account-b"
claude
# Same process → sign in with Account B's email
# Credentials are saved to ~/.claude-account-b/

Daily use

# ~/.zshrc
alias claude-a='CLAUDE_CONFIG_DIR="$HOME/.claude-account-a" claude'
alias claude-b='CLAUDE_CONFIG_DIR="$HOME/.claude-account-b" claude'

Then simply:

claude-a    # Account A's OAuth token
claude-b    # Account B's OAuth token

No logout needed, no switching required — both terminals run fully independently at the same time.

Notes

  • ~/.claude/ (the original default directory) is unaffected, giving you a third independent login
  • Each CLAUDE_CONFIG_DIR has its own settings, memory, and session history
  • If one account’s OAuth token expires, only that directory needs to run claude login again

Summary Comparison Table

ScenarioMethodKey Setting
Primary OAuth + API Key for specific projectsMethod 1Set ANTHROPIC_API_KEY at the project level
Two API Key accounts, split by projectMethod 2Different keys via direnv or aliases
Two OAuth subscription accounts running in parallelMethod 3Point CLAUDE_CONFIG_DIR to different directories

All three methods can be mixed and matched. For example, use Method 3’s OAuth for Account A, and override with Method 1’s API Key for Account B on certain projects.


VariablePurpose
ANTHROPIC_API_KEYAPI Key — overrides OAuth when set
ANTHROPIC_AUTH_TOKENBearer token (used with a proxy)
ANTHROPIC_BASE_URLCustom API endpoint
CLAUDE_CONFIG_DIRWhere config and credentials are stored

Support This Series

If these articles have been helpful, consider buying me a coffee