Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

cld — switch between Claude Code accounts without re-authenticating

cld lets you keep multiple Claude Code logins (e.g. personal and work) on one machine and hop between them instantly:

cld auth switch work

Each account authenticates exactly once. After that, switching is just a local file swap — no browser, no re-login, no waiting.


Why this exists

Claude Code stores a single active login on your machine. If you have more than one account (a personal Max plan and a work seat, say), the only built-in way to change accounts is to log out and log back in through the browser every time.

cld snapshots each login once and swaps them on demand.


How it works

A Claude Code login lives in two files:

File What cld reads from it
~/.claude/.credentials.json claudeAiOauth — the OAuth access + refresh tokens (the actual auth)
~/.claude.json userID + oauthAccount — email, org, display name (so the UI and /usage show the right account)

A profile is a snapshot of just those identity bits. cld auth switch writes the chosen profile back into the live files. Because the refresh token comes along for the ride, Claude Code silently refreshes the access token the next time you use it — so a profile keeps working indefinitely without re-login.

Everything else in ~/.claude.json (your project history, settings, etc.) is left untouched — cld only rewrites the two identity keys.

Token rotation is handled for you

Claude Code rotates the refresh token periodically and rewrites .credentials.json. To make sure a stored profile never goes stale, switching away from a profile re-snapshots its live tokens first. The practical rule:

Always change accounts with cld auth switch. Don't hand-edit the credential files, or you can strand a refresh token.


Requirements

  • Linux or macOS
  • Python 3.6+ (standard library only — no dependencies)
  • Claude Code installed and used at least once

Note: cld targets the file-based credential store used on Linux (and macOS when not using the system Keychain). If your Claude Code stores credentials in the macOS Keychain, see Keychain note below.


Install

# clone
git clone https://github.com/10xAlien/cld.git
cd cld

# put it on your PATH (pick a dir that's already on $PATH)
install -m 755 bin/cld ~/.local/bin/cld
# or: sudo install -m 755 bin/cld /usr/local/bin/cld

Verify:

cld --help

Quick start

# 1. log into your first account the normal way
claude /login
cld auth save work          # snapshot it as "work"

# 2. log into your second account
claude /login               # choose the other account in the browser
cld auth save personal      # snapshot it as "personal"

# 3. switch freely, forever — no re-auth
cld auth switch work
cld auth switch personal

Restart any running claude session after a switch (a live session reads its credentials at startup and won't pick up the new account mid-run). New sessions use the new account immediately.


Commands

Command Description
cld auth save <profile> Snapshot the current Claude Code login as <profile>. Run this once per account, right after claude /login.
cld auth switch <profile> Make <profile> the active account. Re-snapshots the previously active profile first so its tokens stay fresh.
cld auth list List saved profiles. * marks the active one; shows each account's email.
cld auth current Print the active profile.
cld auth rm <profile> Delete a profile. (Does not log that account out elsewhere.)

The auth word is optional — cld switch work works too.

Example session

$ cld auth save work
saved profile 'work' (you@company.com)

$ claude /login
$ cld auth save personal
saved profile 'personal' (you@gmail.com)

$ cld auth list
* personal         you@gmail.com
  work             you@company.com

$ cld auth switch work
switched to 'work' (you@company.com)
restart any running `claude` session to pick up the new account.

$ cld auth current
work  (you@company.com)

Where things are stored

~/.claude/cld-profiles/
├── work.json            # a profile (tokens + account identity)
├── personal.json
├── .active              # name of the currently active profile
└── .backups/            # timestamped copies of the live files before each write

Profiles and backups are written with 0600 permissions; the directory is 0700.


Security notes

  • Profiles contain live OAuth tokens. Treat ~/.claude/cld-profiles/ like a password store. Anyone who can read it can act as those accounts.
  • cld keeps automatic timestamped backups of .credentials.json and .claude.json in .backups/ before every write, so a bad switch is recoverable. Prune that folder occasionally — those backups also hold tokens.
  • The repo's .gitignore excludes cld-profiles/, *.credentials.json, and .active so you can never accidentally commit credentials.
  • cld auth rm only removes the local snapshot. It does not revoke the session — revoke from your Anthropic account settings if you need that.

Troubleshooting

no credentials at ~/.claude/.credentials.json — run claude /login first You haven't logged into Claude Code yet (or it's using the Keychain — see below). Run claude /login, then cld auth save <name>.

Switched, but the running claude still shows the old account A live session loads credentials at startup. Quit and relaunch claude.

/usage or the displayed email looks wrong after a switch cld updates oauthAccount in ~/.claude.json. If you edited that file by hand or it was rebuilt, re-run cld auth save <name> while logged into that account to refresh the snapshot.

macOS Keychain If Claude Code stores your token in the Keychain rather than ~/.claude/.credentials.json, cld can't see it. You can force the file-based store, or extract/inject via the security CLI — this isn't automated yet (PRs welcome).


Uninstall

rm ~/.local/bin/cld          # or wherever you installed it
rm -rf ~/.claude/cld-profiles # removes saved profiles + backups (tokens!)

Your active Claude Code login is unaffected.


License

MIT

About

Switch between Claude Code accounts without re-authenticating — cld auth switch <profile>

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages