Logout, Login, Re-explain
Switching accounts cost me a login and a conversation
I use Claude Code with more than one account: an office one, a personal one. Switching between them was the most annoying five minutes of my day, and the login was the smaller half of it.
The switch itself went like this: /logout, /login, pick the other account in the browser, wait for the OTP email, paste the code. Do it a few times a day and it adds up.
The bigger cost was what came after. I would be halfway through a task on one account, hit its usage limit, switch to the other, and then have to start a fresh conversation and explain everything again: which repo, what we had tried, what the plan was, what not to touch. The work was the same work. Only the account paying for it had changed.
So I wanted two things:
1. Switch accounts with one command. No logout, no browser, no OTP after the first time.
2. Keep the same conversations, memory and settings on every account. Start a chat on the office account, continue the exact same chat on the personal one, with all its context.
The result is a few short commands I now use every day: claude-office, claude-personal, and one more for every extra account I add. Each one opens Claude Code logged in as that account, and all of them read the same history.
This post explains how it works and walks through setting it up on Windows, macOS and Linux. The whole thing is about 20 lines in your shell profile.
What you end up with
claude-office # Claude Code, logged in as the office account
claude-personal # Claude Code, logged in as the personal account
claude-side # add as many as you needKey takeaway
"The account is just who pays for the next message. Your conversations should not have to care which one it is."
Why Not CLAUDE_CONFIG_DIR
The usual answer splits your history in two
Search for "multiple Claude Code accounts" and the standard answer is to give each account its own config folder with the CLAUDE_CONFIG_DIR environment variable. It solves the login problem and creates a new one.
Claude Code keeps almost everything in one folder, ~/.claude: your conversations, global CLAUDE.md, settings, skills and the login (the full layout is below).
With CLAUDE_CONFIG_DIR, each account gets its own copy of all of that. Office gets ~/.claude-office, personal gets ~/.claude-personal. The logins are separate, which is what you wanted. But so is everything else.
A conversation started on office does not exist on personal. --resume cannot see it, so you are back to re-explaining.
Project memory and global CLAUDE.md are written twice and slowly drift apart.
Every setting, skill, hook and MCP server has to be added in both places.
Looking at the folder, only one file is actually tied to an account: .credentials.json. Everything else is about me and my projects, and it is the same no matter which account is logged in.
~/.claude
~/.claude/
.credentials.json the login (the only account-specific file)
projects/ every conversation, stored per working folder
CLAUDE.md your global instructions
settings.json permissions, hooks, model, statusline
skills/ agents/ your skills and subagentsSplit only what is actually different
Instead of one folder per account, keep one folder for everything and keep a saved copy of the login per account. When you start a session, put the right login in place. That is the whole idea.
Key takeaway
"Separate config folders give you separate logins and separate memories. You only wanted the first one."
Swap Only The Login
One shared folder, a saved login per account
Every saved login lives in its own folder, ~/.claude-accounts. A small shell function swaps the right one into ~/.claude before Claude Code starts and saves it back when Claude Code exits.
The layout
Nothing in ~/.claude moves. One new folder sits next to it.
- ~/.claude stays exactly where it is and holds everything shared: conversations, memory, settings, skills.
- ~/.claude-accounts holds one saved login per account, named after the account: office.credentials.json, personal.credentials.json.
- A small file called active remembers which account is currently in ~/.claude, so its login can be saved back before switching.
Home folder
~/.claude/ shared by every account
.credentials.json <- the login currently in use (swapped)
projects/ CLAUDE.md settings.json skills/ ...
~/.claude-accounts/ one saved login per account
office.credentials.json
personal.credentials.json
active "office" or "personal"What happens when you type claude-personal
Four steps, all in your shell profile. Claude Code itself is not modified.
- Save the login that is in place now under the account that was active, because Claude Code refreshes its token while you use it and the newest copy is the one in ~/.claude.
- Copy personal.credentials.json into ~/.claude/.credentials.json. If there is no saved login for personal yet, remove the current one so Claude Code asks you to log in, once.
- Write "personal" into the active file and start claude, passing along any arguments you typed, such as --continue or --resume.
- When Claude Code exits, copy ~/.claude/.credentials.json back to personal.credentials.json, so a refreshed token, or a brand-new login from the first run, is kept.
Key takeaway
"Claude Code always sees one normal config folder with one login in it. It never knows other accounts exist."
Setup: Windows
Windows, in PowerShell
This is the exact setup I run every day
It goes in your PowerShell profile, so the commands exist in every new terminal. Nothing to install. If you also use Git Bash on Windows, follow the next section too. Both read the same files, so the two shells stay in sync.
Open your PowerShell profile
The profile is a script PowerShell runs whenever a new terminal opens. The first line creates it if it does not exist yet. The second opens it in Notepad.
Command
if (!(Test-Path $PROFILE)) { New-Item -ItemType File -Force $PROFILE }
notepad $PROFILEPaste the switcher at the end of the file
One function does the swapping. Each account is a one-line wrapper that gives it a name. Rename office and personal to whatever you like. The name is only used for the saved file and the command.
Microsoft.PowerShell_profile.ps1
# Claude Code: several accounts, ONE shared config folder (~/.claude).
# Only the login file (.credentials.json) is swapped; each account's login
# is kept in ~/.claude-accounts/<name>.credentials.json. One account at a time.
function Use-ClaudeAccount {
param([string]$Name, [string[]]$Rest)
$store = "$env:USERPROFILE\.claude-accounts"
$cred = "$env:USERPROFILE\.claude\.credentials.json"
New-Item -ItemType Directory -Force $store | Out-Null
# Save the login of whichever account was active (tokens refresh while in use).
$active = if (Test-Path "$store\active") { (Get-Content "$store\active").Trim() } else { $null }
if ($active -and (Test-Path $cred)) { Copy-Item $cred "$store\$active.credentials.json" -Force }
# Put this account's login in place; none yet = Claude Code asks to log in once.
if (Test-Path "$store\$Name.credentials.json") {
Copy-Item "$store\$Name.credentials.json" $cred -Force
} elseif (Test-Path $cred) {
Remove-Item $cred -Force
}
Set-Content "$store\active" $Name
claude @Rest
# Save this account's (possibly refreshed, or brand-new) login.
if (Test-Path $cred) { Copy-Item $cred "$store\$Name.credentials.json" -Force }
}
function claude-office { Use-ClaudeAccount -Name office -Rest $args }
function claude-personal { Use-ClaudeAccount -Name personal -Rest $args }Reload the profile
Either open a new terminal or reload it in the current one. If PowerShell refuses to run the profile because scripts are disabled, allow local scripts for your user once.
Command
. $PROFILEThen run
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedLog in to each account once
Run each command one time. There is no saved login yet, so Claude Code shows its normal login screen. Log in with that account, type /exit, and the login is saved. From now on, neither account asks you to log in again.
First run only
PS> claude-office
-> Claude Code asks you to log in -> use your office account
-> /exit (login saved to ~/.claude-accounts/office.credentials.json)
PS> claude-personal
-> Claude Code asks you to log in -> use your personal account
-> /exit (login saved to ~/.claude-accounts/personal.credentials.json)Key takeaway
"Paste once, log in once per account, and switching is a single command from then on."
Setup: macOS / Linux
macOS, Linux and Git Bash
Linux and Git Bash work exactly like Windows. macOS needs one change.
Linux and Git Bash on Windows keep the login in ~/.claude/.credentials.json, the same file as above. macOS keeps it in the login Keychain instead, so on a Mac the function swaps the Keychain entry rather than a file. I run the Git Bash version myself. The macOS version follows the same pattern but I have not run it on a Mac, so check /status after your first switch.
Linux and Git Bash: add this to ~/.bashrc (or ~/.zshrc)
Same four steps as the PowerShell version. Then run source ~/.bashrc, or open a new terminal.
~/.bashrc
# Claude Code: several accounts, ONE shared config folder (~/.claude).
# Only the login file is swapped; logins live in ~/.claude-accounts/<name>.credentials.json.
_claude_account() {
local name="$1"; shift
local store="$HOME/.claude-accounts" cred="$HOME/.claude/.credentials.json"
mkdir -p "$store" && chmod 700 "$store"
local active=""; [ -f "$store/active" ] && active="$(tr -d '[:space:]' < "$store/active")"
if [ -n "$active" ] && [ -f "$cred" ]; then cp -f "$cred" "$store/$active.credentials.json"; fi
if [ -f "$store/$name.credentials.json" ]; then cp -f "$store/$name.credentials.json" "$cred"; else rm -f "$cred"; fi
printf '%s\n' "$name" > "$store/active"
claude "$@"
[ -f "$cred" ] && cp -f "$cred" "$store/$name.credentials.json"
}
alias claude-office='_claude_account office'
alias claude-personal='_claude_account personal'macOS: swap the Keychain entry instead of the file
Claude Code on macOS stores its login as a Keychain item named "Claude Code-credentials". The macOS version reads that item into the saved file and writes the saved file back into it. Everything else is the same. Add it to ~/.zshrc, the default shell on macOS.
~/.zshrc
# macOS: the login lives in the Keychain, not in ~/.claude/.credentials.json.
_claude_account() {
local name="$1"; shift
local store="$HOME/.claude-accounts" svc="Claude Code-credentials"
mkdir -p "$store" && chmod 700 "$store"
local active=""; [ -f "$store/active" ] && active="$(tr -d '[:space:]' < "$store/active")"
# Save the active account's current login out of the Keychain.
if [ -n "$active" ]; then
security find-generic-password -s "$svc" -w > "$store/$active.json.tmp" 2>/dev/null \
&& mv "$store/$active.json.tmp" "$store/$active.json" || rm -f "$store/$active.json.tmp"
fi
# Put this account's login into the Keychain; none yet = Claude Code asks to log in once.
security delete-generic-password -s "$svc" >/dev/null 2>&1
[ -f "$store/$name.json" ] && security add-generic-password -s "$svc" -a "$USER" -w "$(cat "$store/$name.json")"
printf '%s\n' "$name" > "$store/active"
claude "$@"
security find-generic-password -s "$svc" -w > "$store/$name.json" 2>/dev/null || rm -f "$store/$name.json"
}
alias claude-office='_claude_account office'
alias claude-personal='_claude_account personal'Log in to each account once
Same as on Windows: run claude-office, log in, /exit. Run claude-personal, log in, /exit. Then run /status inside a session to confirm which account it is using.
Command
source ~/.bashrc # or ~/.zshrc on macOS
claude-office # log in once, then /exit
claude-personal # log in once, then /exitKey takeaway
"Same idea on every OS: shared ~/.claude, one saved login per account, swap it in before claude starts."
Using It Day To Day
Hit a limit, switch, keep going in the same chat
This is the part that made the setup worth it. Because conversations are stored per folder and not per account, a chat started on one account can be continued on another with all its context.
Example: continue the same conversation on another account
You are deep into a refactor on the office account and it hits its usage limit.
- Type /exit. The office login is saved, including any token refresh that happened during the session.
- In the same project folder, run claude-personal --continue. --continue opens the most recent conversation in this folder.
- The same conversation opens with the full history: the files you discussed, the plan, what you already tried. Nothing to re-explain.
- Only the account changed. Your next message is paid for by the personal account.
Terminal
~/projects/api> claude-office
> refactor the auth middleware to use the new session store
... an hour of work ...
! usage limit reached
> /exit
~/projects/api> claude-personal --continue
(same conversation, same context)
> ok, carry on with the remaining two routesOther things that are shared automatically
All of these live in ~/.claude, so every account sees the same thing.
- claude-office --resume shows every past conversation in the folder, including ones started on personal. Pick any of them.
- Global CLAUDE.md and memory files: write an instruction once and every account follows it.
- settings.json, permissions, hooks, statusline, skills, subagents and MCP servers: set up once, available on every account.
- Any flag works after the command name: claude-personal --model opus, claude-office -p "summarize this diff".
Check which account you are on
Run /status inside any session. It shows the logged-in account. Worth doing once after setup, and any time the switch looks wrong.
Key takeaway
"The conversation belongs to the folder, not the account. Switching accounts is now just switching who pays."
Things To Know
What to watch out for
It is a small setup, but there are a few rules that keep it working.
Two accounts running at the same time will fight over the login.
Solution - There is one credentials file (or one Keychain entry) and both sessions would use it. Run one account at a time. If you start claude-personal while an office session is still open, the open session ends up on the personal login. Exit one before starting the other.
Running plain claude skips the saving step.
Solution - Plain claude still works. It uses whichever login is in place, which is the last account you switched to. But it will not save a refreshed token back. Get used to always starting with claude-office or claude-personal.
The saved files are live login tokens.
Solution - Anyone with office.credentials.json is logged in as you. Keep ~/.claude-accounts out of git, out of OneDrive, iCloud or Dropbox, and off shared machines. If a file leaks, log that account out from claude.ai to revoke it.
A login can still expire.
Solution - If an account has not been used for a long time, or you logged out of it elsewhere, Claude Code asks you to log in again. Do it normally. The function saves the new login on exit and you are back to one-command switching.
Each account still has its own limits and plan.
Solution - Sharing history does not share usage. Each account keeps its own plan, limits and billing, and it should be your own account. This setup only removes the logout, login and re-explaining between them.
Key takeaway
"One account at a time, always start through the named command, and treat the saved logins like passwords."
Quick Answers
Questions people ask about this
Short answers to the things that come up most.
- Can I use two Claude accounts in Claude Code at the same time?
- Not with a single login slot, which is what Claude Code gives you: one credentials file, one active account. The setup here keeps a saved login per account and swaps the right one into place when you start a session, so switching is one command with no logout and no OTP. Use one account at a time. Two sessions running under different accounts at once would share the one credentials file and fight over it.
- Why not just use CLAUDE_CONFIG_DIR for each account?
- It works for logins, but it gives each account its own copy of everything else too: conversation history, project memory, settings, skills, CLAUDE.md, MCP servers. Your office account cannot resume a chat you started on your personal one, and every setting has to be made twice. The point of this setup is the opposite: one config folder that both accounts read, with only the login file swapped.
- Where does Claude Code store the login?
- On Windows and Linux it is a plain JSON file at ~/.claude/.credentials.json. On macOS it is stored in the login Keychain instead, so swapping a file does nothing there and the script has to swap the Keychain entry. Everything else, including conversations, lives under ~/.claude/projects and is shared by both accounts in this setup.
- Do I lose my conversation when I switch accounts?
- No. Conversations are stored on disk under ~/.claude/projects, keyed by the folder you were working in, not by the account. Exit the office session, run claude-personal --continue in the same folder, and the same conversation opens with its full context. Only the account paying for the next message changes.
- Is it safe to keep saved logins in a folder?
- Treat ~/.claude-accounts like a password store. The files hold OAuth tokens that act as your account. Keep the folder out of git, out of cloud-synced folders like OneDrive or Dropbox, and off shared machines. If a file ever leaks, log out of that account from claude.ai to revoke it.
- How do I add a third account?
- One more line in your profile, for example function claude-side { Use-ClaudeAccount -Name side -Rest $args } in PowerShell, or alias claude-side='_claude_account side' in bash. The first time you run it, Claude Code asks you to log in, and from then on the login is saved like the others.
References
Docs behind the setup
The setup only uses documented Claude Code behaviour: where it keeps its files, how it resumes conversations, and how its login works.
Claude Code — Settings and config files
What lives in ~/.claude, including settings.json, CLAUDE.md and the CLAUDE_CONFIG_DIR variable that the usual multi-account approach relies on.
https://docs.claude.com/en/docs/claude-code/settings
Claude Code — CLI reference
The --continue and --resume flags used to pick a conversation back up on a different account.
https://docs.claude.com/en/docs/claude-code/cli-reference
Claude Code — Identity and access management
How Claude Code logs in and where it stores credentials on each operating system, including the macOS Keychain.
https://docs.claude.com/en/docs/claude-code/iam
Claude Code — Memory
How CLAUDE.md and memory files are loaded, which is why sharing one config folder gives every account the same instructions.
https://docs.claude.com/en/docs/claude-code/memory
Key takeaway
"Copy the function, rename the accounts, log in once each. That is the whole setup."