Multiple Claude Code accounts: work and personal on one machine, and how to switch
Dmitriy Solodukha · Updated · 4 min read
Checked against Caprock v0.199.0
Two Claude Code accounts on one machine: a CLAUDE_CONFIG_DIR per account, what overrides the login, switchers, Codex's CODEX_HOME, and what Caprock adds.
Give each account its own config directory. Claude Code keeps its settings, session history and login under CLAUDE_CONFIG_DIR (default ~/.claude), so alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude' runs a second account beside the first — both at once, no logout. Anthropic documents this setup under "Log in with multiple accounts".
Caprock keeps several Claude Code and Codex sign-ins side by side, shows each one's 5-hour and weekly windows, and lets you pick the account per session. Free and open source, as many sign-ins as you need.
Set up a second Claude Code account
- 1
alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'
- 2
claude-work
The first run in a new directory walks you through signing in: pick the other account there. Put the alias in ~/.zshrc or ~/.bashrc to keep it. In PowerShell, $env:CLAUDE_CONFIG_DIR = "$HOME\.claude-work"; claude does the same for that window.
What the directory holds, and what it does not:
- Its own: settings, plugins, session history, and the claude.ai login or API key.
- Shared by both: everything in the repository — the project's
CLAUDE.mdand.claude/folder apply whichever account runs. - Starts empty: a new directory has none of your user settings or plugins. Copy what you want in both.
- One exception: a Console sign-in without a key is stored outside the config directory, so separate directories do not keep two of those apart.
Where the login is stored
| System | Stored in |
|---|---|
| macOS | the Keychain, an entry keyed to the config directory |
| Linux | .credentials.json in the config directory (mode 0600) |
| Windows | .credentials.json in the config directory |
So two directories on a Mac read two Keychain entries, not one. claude auth status --text (v2.1.318 or later) shows when that directory's claude.ai sign-in ends.
What overrides the account you signed in with
Claude Code uses the first credential it finds, in this order (Anthropic's "authentication precedence"):
- cloud provider variables (Bedrock, Vertex, Foundry)
ANTHROPIC_AUTH_TOKENANTHROPIC_API_KEY, once you approve itapiKeyHelperCLAUDE_CODE_OAUTH_TOKEN- Anthropic profile and federation credentials
- the subscription you signed in to with
/login
An API key exported in your shell profile is the usual reason a "work" alias bills the API instead of the plan. Run /status in the session to see what it is using, and unset ANTHROPIC_API_KEY where you want the subscription. More on keys: Claude Code API key.
Switching instead: /logout, /login and switcher tools
With one directory you switch by /logout and /login, which also resets the first-launch setup. Tools that keep several logins and swap the active one:
- claude-swap (
cswap, MIT) — swaps the one active login without logging out, can rotate near a rate limit, and runs another account in the current terminal only. Its README warns not to/logoutfirst. - swapdex (MIT) — Claude Code, Codex, Gemini and Antigravity: a
CLAUDE_CONFIG_DIRorCODEX_HOMEslot per account, flipped by launcher shims. In slot mode you sign in once per slot and it copies no credentials; its olderaddmode copies the current login, refresh token included, into a local store.
Both are third-party; read their repositories before handing them your logins.
Is it allowed?
Anthropic's Consumer Terms forbid sharing your login or API key with anyone else; they say nothing about one person holding two accounts. Anthropic's help center says a personal account and a Team or Enterprise account can be on one email address, and you can keep both. Work and personal on one machine is that case.
Two Codex accounts: CODEX_HOME
Codex's cli_auth_credentials_store decides where the sign-in goes: file writes auth.json under CODEX_HOME (default ~/.codex), keyring the system's credential store, auto the store when there is one and the file otherwise, ephemeral memory only. OpenAI's docs do not say whether the system store keeps one entry per CODEX_HOME, so set file for a folder per account:
- 1
CODEX_HOME=~/.codex-work codex login
- 2
alias codex-work='CODEX_HOME=~/.codex-work codex'
OpenAI's docs have no section on several accounts; a CODEX_HOME per account is the convention switchers and Caprock use. Codex's own limits: Codex usage limits.
What Caprock adds: every sign-in in one window
Caprock, a free, open-source desktop app for macOS, Windows and Linux, does the folder-per-account setup for you and shows what each account has left:
- Settings → Subscriptions keeps several Claude Code or Codex accounts, each in a folder of its own. Add subscription makes the folder and types
CLAUDE_CONFIG_DIR='…' claude auth login(orCODEX_HOME='…' codex login) into a shell tab; you sign in there. Caprock never sees a password or token. - Each account's windows. Plan limits list every sign-in with what is left of its 5-hour and weekly windows and when each resets; the picker in New agent shows each option's tightest window, and is remembered per project.
- No surprise switching. Near 90% of a window the picker suggests another account but picks nothing for you, and a running session never changes account. At a limit Caprock asks whether to continue the same conversation on another sign-in (the transcript is copied, not moved), unless you chose Continue automatically in Settings.
- Your shell's key does not leak in. A session on an added subscription runs on its own sign-in even when your shell exports
ANTHROPIC_API_KEYorCLAUDE_CODE_OAUTH_TOKEN.
Add as many sign-ins per agent as you need; every one is free. A new subscription starts with the agent's defaults: your settings, plugins and MCP servers are not copied. How the windows work: Claude Code usage limits.
Which to use
- Two aliases — you want work and personal apart and are happy in the terminal. Nothing to install.
- claude-swap or swapdex — you want one command to flip the active login, or several agents' accounts in one tool.
- Caprock — you run several accounts every day and want each one's windows in view and the account chosen per session.
Questions people ask
- Can I use two Claude Code accounts on one computer?
- Yes. Give each account its own config directory with CLAUDE_CONFIG_DIR, for example alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'. Each directory has its own settings, history and login, and both can run at the same time.
- How do I switch accounts in Claude Code?
- Inside one config directory, /logout and then /login, which also resets the first-launch setup. With one directory per account you do not switch: you start the alias for the account you want.
- Why does Claude Code use my API key instead of my subscription?
- An exported ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, apiKeyHelper or CLAUDE_CODE_OAUTH_TOKEN comes before the /login subscription in Claude Code's authentication order. Unset it and check /status.
- Where does Claude Code store its login?
- In the macOS Keychain on a Mac, keyed to the config directory, and in .credentials.json inside the config directory on Linux and Windows (~/.claude by default).
- How do I use two Codex accounts?
- Give each its own CODEX_HOME and sign in once in each: CODEX_HOME=~/.codex-work codex login. OpenAI's docs do not describe several accounts; a folder per account is the convention switchers and Caprock use.
Sources
- Claude Code docs — Environment variables: CLAUDE_CONFIG_DIR, ANTHROPIC_API_KEY, read 27 November 2026
- Claude Code docs — Authentication: log in with multiple accounts, credential management, authentication precedence, read 27 November 2026
- Anthropic — Consumer Terms of Service, section 2 (account credentials), read 27 November 2026
- Claude Help Center — Move your personal Claude account to a Team or Enterprise organization, read 27 November 2026
- OpenAI — Codex authentication: codex login, auth.json, CODEX_HOME, cli_auth_credentials_store, read 27 November 2026
- realiti4/claude-swap on GitHub (MIT), read 27 November 2026
- youdie006/swapdex on GitHub (MIT), read 27 November 2026
- Caprock CHANGELOG — 0.101.0 More than one sign-in, 0.112.0, 0.133.0, 0.171.0, 0.183.0
- Caprock docs — Subscriptions: more than one sign-in (docs/app.md)
Try it
The record of every coding agent you run, the sessions it did not start included. Free, open source; nothing leaves your machine.
Caprock is a desktop app: it installs on your computer, not your phone.
Or email yourself the link:
macOS, Windows and Linux. Your phone pairs with it by QR code. Install options →
Notarized by Apple. One file for Apple silicon and Intel, macOS 13 or later.
Windows 10 22H2 or later, x64. Windows may ask once whether to run it: click More info, then Run anyway.
Paste it into Claude Code, Codex or any coding agent.
See what it says ▾
Install the Caprock desktop app for me. It is open source (Apache-2.0), a local app for my coding agents: https://github.com/dspv/caprock What the install does and how to remove it: https://github.com/dspv/caprock/blob/master/docs/install-agent.md Run the install script for my system: https://caprock.dev/mac.sh, /win.ps1 or /linux.sh. Read it before you run it if you like. Leave my Claude Code settings alone; the app asks me itself. Tell me when it's open.
Or run it yourself:
Paste in Terminal: it installs Caprock and opens it.Or with Homebrew: brew install --cask dspv/tap/caprock-app
Or run it yourself:
Paste in PowerShell: it installs Caprock for you and opens it.
Or run it yourself:
Paste in a terminal: it installs Caprock for you, no sudo. Or download the AppImage