How to use two Claude Code accounts at the same time

2026-11-24来源 dev.toEnglish
How to use two Claude Code accounts at the same time

One Claude Code account hits its limit in the middle of a task. The other one has plenty left. Logging out and back in every time is slow.

Claude Code can keep both signed in at once. Each account gets its own folder, and an environment variable picks the folder:

  • Add the second account: make a folder and an alias for it, then sign in once.
 alias claude-work='CLAUDE_CONFIG_DIR=$HOME/.claude-work claude' claude-work auth login 
  • Switch: run claude-work instead of claude. The account you already use needs no alias.
  • Check: claude-work auth status --text prints the login method, organization, and email of that folder.
  • The catch: the variable is read when Claude Code starts. A running session keeps its account, and each folder has its own settings, MCP servers, and history.
  • When one runs out: a session belongs to one folder. To continue it on the other account, copy its transcript across (below).

Anthropic's authentication docs describe this setup for staying signed in to several accounts, such as work and personal. They don't say anything about holding more than one personal subscription, so check the terms of your plan. I tested the commands on macOS; on Windows, set CLAUDE_CONFIG_DIR in the shell before you run claude, which I haven't tried.

How do I add a second Claude Code account?

Pick a name for each account and make one folder per name. The folder is created the first time Claude Code runs there.

Add one alias per extra account to ~/.zshrc or ~/.bashrc:

alias claude-work='CLAUDE_CONFIG_DIR=$HOME/.claude-work claude' alias claude-personal='CLAUDE_CONFIG_DIR=$HOME/.claude-personal claude' 

Open a new shell, then sign in once in each:

claude-work auth login 

A browser window opens. Sign in with the other account. From then on, claude-work starts Claude Code under it, and plain claude still starts the account you had before. When a Claude Code maintainer closed the feature request for multi-account support in August 2026, the reply was this setup: each folder holds its own login, settings, and session history, so switching is a matter of which alias you run.

Should the first account get an alias too?

Leave it alone. Plain claude uses the default folder, ~/.claude. If you set CLAUDE_CONFIG_DIR to that same folder, Claude Code treats it as a different place: on my Mac, CLAUDE_CONFIG_DIR=$HOME/.claude claude auth status said loggedIn: false, while plain claude was signed in.

The reason is where the sign-in lives. On macOS it is in the Keychain, and Claude Code ties the entry to the folder. The default folder uses Claude Code-credentials. Any folder you set through the variable gets that name plus a suffix, which on 2.1.331 is the first 8 characters of the SHA-256 of the folder's path. The docs only say the entry is tied to the folder; the suffix is what I saw, so don't build tooling on it.

The same variable also moves ~/.claude.json, the file that holds your account details, trust decisions, and personal MCP servers. That is why a second folder starts with none of them.

How do I know which account a session is using?

The documented status line fields have no account in them. Three ways to know:

  • Name the alias after the account. claude-work in your shell history says more than claude.
  • Ask the folder. claude-work auth status --text prints the email and organization it is signed in with, and claude auth status --text does the same for the default one.
  • Inside a session, /status lists the account. Check what it prints for your plan.

An alias sets the variable only for that one command. A shell where you ran claude-work still has no CLAUDE_CONFIG_DIR, so echo $CLAUDE_CONFIG_DIR there tells you nothing about a session that is already running.

What do the accounts share?

Nothing, because each folder is a separate ~/.claude. Each one has its own:

  • settings.json, CLAUDE.md, plugins, and skills
  • personal MCP servers, in its own .claude.json
  • session transcripts and prompt history, under projects/
  • sign-in

If you want the same CLAUDE.md or settings in both, symlink the file from one folder into the other. One write-up does this for skills, settings, and plugins, and notes that MCP servers that sign in with OAuth need signing in again per folder. A hook that points at a script under ~/.claude runs the same script for both accounts, so use a path that doesn't depend on the folder.

What if one account runs out in the middle of a task?

claude --resume only looks in the folder it runs under, so the other account can't see the session:

No conversation found with session ID: <session-id> 

The transcript is a plain file, projects/<project>/<session-id>.jsonl, and copying it works. I tried it: I made a session under one account, copied the file into the same project folder of the other, and resumed it there. The conversation continued, and Claude Code could repeat my first message. The original stays where it was and the two sessions are separate from then on.

Find the file, copy it into the same place under the other folder, and resume from the same working directory:

SID=<session-id> SRC=$HOME/.claude-work DST=$HOME/.claude-personal f=$(find "$SRC/projects" -name "$SID.jsonl") proj=$(basename "$(dirname "$f")") mkdir -p "$DST/projects/$proj" cp "$f" "$DST/projects/$proj/" cd <the project folder where the session ran> CLAUDE_CONFIG_DIR=$DST claude --resume "$SID" 

The project folder name is made from the working directory, so run claude from the same directory the session started in. The most recent transcript is the newest file: ls -t "$SRC/projects/$proj" | head -1.

This moves the conversation, not your files. If both accounts will edit the same checkout, use a git worktree for the second one, as in how to fork a session. Auto memory under projects/<project>/memory stays where it is. Claude Code deletes transcripts after 30 days by default, so copy soon; see Claude Code conversation history.

How do I see how much each account has left?

Run /usage inside a session of each account. It shows the 5-hour and weekly windows for that account only. See how to check your usage limits for what each number means.

How do I remove an account?

Sign out first, then delete the folder. The folder holds that account's session history, so copy out any transcript you still want.

claude-work auth logout rm -r "$HOME/.claude-work" 

On macOS the sign-in is in the Keychain, not in the folder, so deleting the folder alone leaves it there. Remove the alias from your shell file too.

How does PonyMux do this?

PonyMux keeps one folder per login for you. In Settings → Integrations, choose Add another profile… under Claude Code, name it, and sign in. If you already made a folder by hand with CLAUDE_CONFIG_DIR, PonyMux finds it and offers Add.

Settings, Integrations pane with two Claude Code logins: Default is connected, Work is signed out with a Sign in button, and a banner offers another login found on this computer with Dismiss and Add.

Each login gets its own row in the sidebar, with its name and its own usage ring, so you see which account is running low without typing /usage. A session comes back under the login it started with when you resume it or wake its Terminal. When you start a new agent, a Profile chip in the launch panel picks the login.

Since the accounts share nothing, the useful part is moving work between them:

  • A session: Fork Session… asks which login to fork in. Pick the other one and PonyMux copies the conversation there, so it continues under that account while the original stays put. That is the transcript copy above, without the commands. See Fork a session.
  • A task: Handoff lists the same agent under another login, such as Claude · Work, next to the other agents. It starts a new session with the recent turns and a summary as context, which suits a task you want to restart fresh on the other account. See Hand off to another agent.
  • An Artifact: an Artifact belongs to the account that published it. Export to… in the Inspector saves it, and the Artifacts it links to, as a folder, with a prompt you paste into a Claude Code conversation signed in to the other account. It publishes them again at new addresses. See Export an Artifact.

PonyMux doesn't choose between your accounts for you, and each login still needs its own sign-in and its own Connect…. See Use several logins per agent.

PonyMux is free for Mac and Windows. Download it.

原文:https://www.a8q9.cn/en/article/how-to-use-two-claude-code-accounts-at-the-same-time-80cecb.html

相关文章