I pay for more than one Claude subscription, and I wanted plain claude to run on whichever one has room left, without losing my sessions or splitting my history in two.
The obvious fix looked easy: keep a copy of each account's login file and copy the right one back when I want to switch. It worked for a few hours. Then Claude Code started asking me to log in again.
Repo: https://github.com/Abubakr-Alsheikh/claude-account-switch
Why a saved login dies
Claude Code signs in with OAuth. It holds a short-lived access token, about 8 hours, and a refresh token. When the access token runs out, Claude Code trades the refresh token for a new pair and writes both back.
The server accepts each refresh token once. After a renewal, the old one is dead.
So a copy you saved on Monday dies the moment any running claude renews that login on Monday night. Copy it back on Tuesday and you are logged out. Every "save the file, swap the file" approach hits this.
What the tool does about it
claude-switch keeps one Claude Code profile and swaps only the login. To stay correct with single-use tokens:
- Most commands save the active account's newest login first, so a saved copy is never older than your last command.
- It takes Claude Code's own locks during the swap, in the same order Claude Code takes them, so no running session renews or rewrites the login halfway through.
- It refuses to file one account's login under another name. It compares logins by a SHA-256 hash of the refresh token and by the email Claude Code records.
- It keeps the last 3 copies of each account, and parks logins it doesn't recognize instead of overwriting them.
- It tells you when a saved login is dead, and how to repair it.
$ claude-switch list CLAUDE ACCOUNTS active: work (me@work.example) name email plan weekly use (resets) 5-hour use (resets) renewed ends >> work me@work.example Ultra #######... 71% Sun 09:00 ###... 48% 17:00 10-30 12:10 11-24 personal me@home.example Max ##........ 18% Tue 21:00 ...... 0% 19:40 10-30 09:02 11-19 Most weekly room: personal (18% used) -> claude-switch use personal or claude-switch auto claude-switch use personal swaps the login. In an open session, /exit and claude -c continue the same conversation on the other account.
Things I learned matching Claude Code
Getting this right meant reading how Claude Code itself behaves, version by version:
- It guards renewals with lock folders (
~/.claude/.oauth_refresh.lock, then an older~/.claude.lock) and refreshes their timestamps every few seconds. A lock that stops moving counts as dead. - Every write of the login goes through a separate lock,
~/.claude/.storage-write.lock. - On macOS, current versions file the Keychain item under the account
claude-code-user, not your user name. - Newer versions can keep the Windows login in Windows Credential Manager. claude-switch doesn't handle that store yet, so it notices and stops before touching anything.
What it is not
It is unofficial: not made, endorsed or supported by Anthropic. It reads and writes the same files Claude Code uses, so a Claude Code update can break it.
It is for one person moving between their own subscriptions. Don't share logins or pool access, and follow Anthropic's terms for every account. Renewing logins you are not using (refresh, keepalive) is opt-in, and the README lists exactly what leaves your machine.
Try it
Python 3.9 or newer, no dependencies:
pipx install git+https://github.com/Abubakr-Alsheikh/claude-account-switch@v0.2.1 claude-switch save work claude-switch add personal # then sign the browser into the other account claude auth login claude-switch save personal claude-switch list I use it daily on Windows. Linux runs in CI. The macOS code passes its tests against a fake Keychain, but I haven't run it on a real Mac yet, so reports from Mac users are welcome.
