# Multiple Claude Code accounts: work and personal on one machine, and how to switch

*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.*

Dmitriy Solodukha, checked 2026-11-27 · https://caprock.dev/guides/claude-code-multiple-accounts/

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".

**In short**
- **The setup:** one `CLAUDE_CONFIG_DIR` and one alias per account; sign in
  once in each.
- **What beats the login:** an exported `ANTHROPIC_API_KEY`,
  `ANTHROPIC_AUTH_TOKEN`, `apiKeyHelper` or `CLAUDE_CODE_OAUTH_TOKEN`.
- **Codex:** the same idea with `CODEX_HOME`.
- **What Caprock adds:** every sign-in's 5-hour and weekly windows side by
  side, and the account picked per session.

## Set up a second Claude Code account

1. alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude': `undefined`
2. claude-work: `undefined`

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.md` and `.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

*Where Claude Code keeps credentials, from Anthropic's authentication docs, read 27 November 2026.*

| 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"):

1. cloud provider variables (Bedrock, Vertex, Foundry)
2. `ANTHROPIC_AUTH_TOKEN`
3. `ANTHROPIC_API_KEY`, once you approve it
4. `apiKeyHelper`
5. `CLAUDE_CODE_OAUTH_TOKEN`
6. Anthropic profile and federation credentials
7. 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](https://caprock.dev/guides/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 `/logout` first.
- **swapdex** (MIT) — Claude Code, Codex, Gemini and Antigravity: a
  `CLAUDE_CONFIG_DIR` or `CODEX_HOME` slot per account, flipped by launcher
  shims. In slot mode you sign in once per slot and it copies no
  credentials; its older `add` mode 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: `undefined`
2. alias codex-work='CODEX_HOME=~/.codex-work codex': `undefined`

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](https://caprock.dev/guides/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` (or `CODEX_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_KEY`
  or `CLAUDE_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](https://caprock.dev/guides/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.

## Sources

- [Claude Code docs — Environment variables: CLAUDE_CONFIG_DIR, ANTHROPIC_API_KEY, read 27 November 2026](https://code.claude.com/docs/en/env-vars)
- [Claude Code docs — Authentication: log in with multiple accounts, credential management, authentication precedence, read 27 November 2026](https://code.claude.com/docs/en/authentication)
- [Anthropic — Consumer Terms of Service, section 2 (account credentials), read 27 November 2026](https://www.anthropic.com/legal/consumer-terms)
- [Claude Help Center — Move your personal Claude account to a Team or Enterprise organization, read 27 November 2026](https://support.claude.com/en/articles/9267400-move-your-personal-claude-account-to-a-team-or-enterprise-organization)
- [OpenAI — Codex authentication: codex login, auth.json, CODEX_HOME, cli_auth_credentials_store, read 27 November 2026](https://learn.chatgpt.com/docs/auth)
- [realiti4/claude-swap on GitHub (MIT), read 27 November 2026](https://github.com/realiti4/claude-swap)
- [youdie006/swapdex on GitHub (MIT), read 27 November 2026](https://github.com/youdie006/swapdex)
- [Caprock CHANGELOG — 0.101.0 More than one sign-in, 0.112.0, 0.133.0, 0.171.0, 0.183.0](https://github.com/dspv/caprock/blob/master/CHANGELOG.md)
- [Caprock docs — Subscriptions: more than one sign-in (docs/app.md)](https://github.com/dspv/caprock/blob/master/docs/app.md)
