Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

claude-swap

> 开发工具
Open source

Switch between multiple Claude Code accounts, with automatic rate-limit rotation, usage dashboard, and parallel sessions

1.5K stars0 likes5 views
WebsiteGitHub

About

Switch between multiple Claude Code accounts, with automatic rate-limit rotation, usage dashboard, and parallel sessions

claude-swap

Multi-account switcher for Claude Code. Easily switch between multiple Claude accounts without logging out, or let it switch for you before you hit a rate limit. Track usage for every account in a live dashboard, and run accounts in parallel. Works with both the Claude Code CLI and the VS Code extension.

Installation

Using uv (recommended)

bash
uv tool install claude-swap

Using pipx

bash
pipx install claude-swap

From source

bash
git clone https://github.com/realiti4/claude-swap.git
cd claude-swap
uv sync
uv run cswap help

Updating

bash
cswap upgrade          # uv/pipx installs on macOS/Linux: auto-detects and upgrades
# or run your installer directly:
uv tool upgrade claude-swap
pipx upgrade claude-swap

Usage

Add your first account

Log into Claude Code with your first account, then:

bash
cswap add

Add more accounts

Log in with another account, then:

bash
cswap add

Do not run /logout first: current Claude Code may revoke the refresh token stored for the account you are leaving.

Switch accounts

Rotate to the next account:

bash
cswap switch

Or switch to a specific account:

bash
cswap switch 2
cswap switch [email protected]
cswap switch dev                # or by alias, once set with `cswap alias 2 dev`

Not sure which one? cswap list is the dashboard — every account's 5-hour and 7-day usage and reset times at a glance:

bash
cswap list

Or let claude-swap auto-pick by remaining quota — cswap switch --strategy best (most quota left) or --strategy next-available (skip rate-limited accounts).

Note: You usually don't need to restart — on Linux/Windows the new account is picked up automatically, and on macOS after the Keychain cache expires. To apply it instantly, restart Claude Code or reopen the VS Code extension tab. See Tips for the per-platform details.

Automatic switching

Let claude-swap watch your usage and switch for you. When the active account's 5-hour or 7-day window reaches the threshold (default 90%), it switches to the account with the most quota left — before you hit the limit, and safe to run while Claude Code is working:

bash
cswap auto                     # foreground loop, polls every 60s
cswap auto --threshold 80      # switch earlier
cswap auto --model Fable       # also switch when the Fable weekly limit is hit
cswap auto --once              # single check-and-switch, for cron/scripts
cswap auto --dry-run           # log what it would do, never switch
cswap auto --strategy consume-first   # burn the soonest-resetting account first
How it behaves & advanced usage
  • Runs safely alongside Claude Code: switches take the same credential locks Claude Code uses, so a swap never collides with a token refresh.
  • A cooldown (default 5 min) and a hysteresis margin stop it flip-flopping near the threshold: a proactive switch only lands on an account that's below the threshold and better than the current one by the margin — a candidate that clears the margin is always taken, but two accounts hovering at the line never ping-pong. When every account is exhausted it keeps checking on a bounded slow cadence, waking sooner for an imminent reset.
  • Strategies (--strategy, or cswap config set autoswitch.strategy): best (default) stays put until the active account nears its limit, then moves to the account with the most quota left. consume-first proactively keeps you on the account whose weekly window resets soonest — use-it-or-lose-it — switching to a sooner-resetting account (with room to spare) even below the threshold, so perishable weekly quota isn't wasted.
  • Usage polling is adaptive — a couple of accounts per check, busy alternates watched more closely, and exhausted ones checked about every ten minutes (or slower after 429s) — so API traffic stays flat no matter how many accounts you manage.
  • It fails safe: if a usage check errors it keeps trusting the last-known numbers while retries back off, and an expired token on an idle machine makes it hold rather than fail over (Claude Code refreshes the token on your next message).
  • An account whose refresh token has died is quarantined and reported until you either log in with it and re-run cswap add --slot N, or replace its stored credentials from a known-good export — a plain cswap import backup.cswap replaces dead-token slots on its own (--force is still required to replace other existing accounts; note a stale export can carry an already-superseded token). API-key accounts are never rotated onto unless you pass --include-api-key-accounts.
  • To hold an account out of rotation yourself — a work account you don't want touched, one you're resting — run cswap disable <num|email>; cswap enable <num|email> puts it back. Disabled accounts are skipped by auto-switch, bare cswap switch, and the best / next-available strategies, but stay fully managed and remain a valid explicit cswap switch <num|email> target. They show a (disabled) marker in cswap list, in the TUI, and in the menu bar — both of which also let you toggle the state in place (TUI: menu → Disable / enable account…; menu bar: Disable / enable account).
  • By default only the account-wide 5h/7d windows drive switching. If you work on one model and hit its weekly per-model limit first (e.g. Fable), add --model Fable (or cswap config set autoswitch.model Fable) to fold that model's window into the decision, so it switches off an account whose model quota is spent even while its 5h/7d windows still have room.
    • Model names are Anthropic's own per-model display_names, matched case-insensitively. The exact strings for your accounts are the per-model rows in cswap list (e.g. a line reading Fable: 100%).

For cron/systemd timers, --once reports the outcome in its exit code (0 switched, 1 error, 2 nothing to do, 3 blocked — no viable target), and --json emits one JSON event per line:

bash
*/5 * * * * cswap auto --once --json >> ~/.cswap-auto.log 2>&1

Defaults like the threshold and cooldown are configurable with cswap config set autoswitch.threshold 80 — flags override them (see Configuration).

Run multiple accounts at the same time (session mode)

Launch Claude Code as a specific account in the current terminal only — every other terminal and the VS Code extension stay on your default account, so two accounts can work in parallel.

bash
cswap run 2                     # launch Claude Code as account 2, here only
cswap run [email protected]      # by email
cswap run 2 -- --resume         # everything after '--' is forwarded to claude
cswap run 2 --share-history     # share your chat history with this account too
cswap run 2 --require-session   # refuse rather than run plain claude if 2 is the default login

Sessions use your normal ~/.claude setup (settings, CLAUDE.md, skills, MCP servers, etc.), but each account keeps its own chat history — pass --share-history if you want your accounts to continue the same conversations.

Running the account that is already your default login launches plain claude on that login instead of a session (a second copy of the active credential would go stale). Scripts that need the isolation guaranteed can pass --require-session, which refuses in that case instead.

A session refreshes its own copy of the account's token, so once it exits, the credential it rotated is captured back into the account's stored backup before a switch or usage check uses that backup. While a session is still running, cswap switch refuses to move the default login onto its account if the stored backup has already fallen behind (activating it could only fail); exit the session first, or pick another account. While a session runs, its account's usage is read with the session's own credential and never refreshed by cswap; a read the server refuses shows as token expired, and is not requested again, until the session renews the credential on its next call.

Sharing details — MCP servers & chat history
  • With --share-history, a session started under one account shows up in --resume under the others, and nothing already saved is lost.
  • User-scope MCP servers (claude mcp add -s user) are mirrored from your default profile on every launch — manage them there; changes made inside a session don't persist. Definitions are copied as-is (including inline env/headers values), but MCP OAuth logins are not — HTTP servers may ask you to authenticate once per profile via /mcp.
  • --no-share turns sharing off and removes the mirrored MCP config (profiles that never mirrored are left alone).
Map accounts to directories — auto-pick per repo

Bind a directory to an account, and a bare cswap run there launches that account in session mode — e.g. work account in work repos, personal elsewhere:

bash
cswap map 2 ~/work/client-app   # map a directory to account 2
cswap map [email protected]      # map the current directory
cswap map                       # list mappings
cswap unmap ~/work/client-app   # remove one (defaults to current directory)

cd ~/work/client-app/src
cswap run                       # → account 2, session mode

Subfolders inherit the nearest mapped ancestor. In an unmapped directory, cswap run just launches plain claude with your default login. Mappings are per-machine (not part of cswap export) and are cleaned up when their account is removed.

Interactive dashboard (TUI)

Run cswap on its own (or cswap tui) for the full-screen dashboard: live usage for every account, switching, and the auto-switcher, all keyboard-driven. cswap watch opens it straight to the live monitor. Works on macOS, Linux, and Windows.

Refresh expired tokens

If an account's token expires, log back into Claude Code with that account and re-run:

bash
cswap add

This will update the stored credentials without creating a duplicate.

Other commands

…

The original flag spellings (cswap --switch, cswap --list, ...) keep working.

Tips

  • Do you need to restart after switching? Usually not. On Linux and Windows, credentials are stored in a file and Claude Code re-reads them whenever that file changes, so the new account takes effect on your next message — no restart needed. On macOS, credentials live in the Keychain, which Claude Code caches for about 30 seconds; a running session picks up the switch once that cache expires. Restart Claude Code (or close and reopen the VS Code extension tab) only if you want the change to apply instantly.
  • Continuing sessions after switching: You can keep using the same Claude Code session after switching — run cswap switch in any terminal and carry on. If you'd prefer a clean start, close and reopen Claude Code (or the VS Code extension tab) and use --resume to pick your previous session. Either way, the first message on the new account may use extra usage as its conversation cache rebuilds.

How it works

  • Backs up OAuth tokens and config when you add an account
  • Swaps only the account-specific Claude login when you switch accounts; live account-independent OAuth state (such as MCP server logins) is preserved instead of being overwritten by a slot's older snapshot
  • Account credentials stored securely using platform-appropriate methods
  • Switches (manual and automatic) hold Claude Code's own credential locks while writing, so a swap never interleaves with a token refresh
  • Auto-switch freshens a target's token before activating it, and quarantines accounts whose refresh token has died (recover by re-adding it with cswap add --slot N, or by replacing its stored credentials from a known-good export — a plain

Issues· 138 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonaccount-manageraccount-switcheranthropicclaude

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具