claudeers.
// Developer Tools

claude-swap

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

// Developer Tools[ cli ][ api ][ web ][ claude ]#claude#account-manager#account-switcher#anthropic#claude-code#cli#multi-account#tui#devtoolsMIT$open-sourceupdated about 7 hours ago

Install with your AI

Paste into Claude Code, Cursor, or any agent — it reads the repo and wires the tool into your project.

Install and set up claude-swap (git-clone project) into my current project.
Found on https://claudeers.com/claude-swap
Repo: https://github.com/realiti4/claude-swap
Homepage/docs: —
Detected install method: git-clone → git clone https://github.com/realiti4/claude-swap
Category: devtools. Platforms: cli, api, web.
Read the repo's README for exact setup and env vars, then install it and wire it into my project.

Claudeers Health Verdict:
unknown; community-verified: false. Confirm the source before running anything.
// or clone
git clone https://github.com/realiti4/claude-swap

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

uv tool install claude-swap

Using pipx

pipx install claude-swap

From source

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

Updating

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:

cswap add

Add more accounts

Log in with another account, then:

cswap add

Switch accounts

Rotate to the next account:

cswap switch

Or switch to a specific account:

cswap switch 2
cswap switch [email protected]

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

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:

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
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 sleeps until the first one becomes usable again.
  • Usage polling is adaptive — a couple of accounts per check, busy alternates watched more closely, exhausted ones left alone until they reset — 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 log in with it and re-run cswap add --slot N. API-key accounts are never rotated onto unless you pass --include-api-key-accounts.
  • 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:

*/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.

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

Sessions use your normal ~/.claude setup (settings, CLAUDE.md, skills, etc.), but each account keeps its own chat history. Pass --share-history if you want your accounts to continue the same conversations — a session started under one account shows up in --resume under the others, and nothing already saved is lost. Not supported on Windows yet.

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.

cswap watch — live 5h/7d usage bars for every account, with reset times and the active account marked

Refresh expired tokens

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

cswap add

This will update the stored credentials without creating a duplicate.

Other commands

cswap run 2                     # Run an account in this terminal only (session mode)
cswap auto                      # Auto-switch when nearing rate limits (see above)
cswap config                    # Show or edit settings (see Configuration below)
cswap list                      # Show all accounts with 5h/7d usage and reset times
cswap status                    # Show current account
cswap add --slot 3              # Add account to a specific slot (prompts before overwrite)
cswap remove 2                  # Remove an account
cswap tui                       # Interactive dashboard (also: bare `cswap`)
cswap watch                     # Dashboard, opened on the live watch page
cswap upgrade                   # Upgrade claude-swap to the latest version
cswap purge                     # Remove all claude-swap data

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 credentials when you switch accounts
  • 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 with cswap add --slot N)
  • Usage numbers refresh every few minutes — faster for an account being used or close to switching, slower for idle ones — keeping cswap comfortably inside Anthropic's rate limits however many dashboards you keep open on a machine. An age note like · 6m ago just means the next scheduled check hasn't come yet, not that something is stuck.

Data locations

PlatformCredentialsConfig backups
WindowsFile-based (inside the backup directory, under credentials/)~/.claude-swap-backup/
macOSmacOS Keychain~/.claude-swap-backup/
Linux / WSLFile-based (inside the backup directory, under credentials/)${XDG_DATA_HOME:-~/.local/share}/claude-swap/

Session-mode profiles (cswap run) live under the backup directory in sessions/. Tool preferences (settings.json) and auto-switch state (autoswitch_state.json — cooldown and quarantined accounts; delete it to reset) live in the backup directory root.

On Linux/WSL, set XDG_DATA_HOME to override the default location.

Optional macOS menu bar app — usage at a glance, click to switch

Needs the menubar extra (macOS only):

uv tool install 'claude-swap[menubar]'   # or: pipx install 'claude-swap[menubar]'
cswap menubar

Shows every account's 5h / 7d / spend usage and switches with a click (specific / rotate / best / next-available), plus the TUI's add / remove / refresh actions. Enable Settings → Auto-switch accounts to run the same engine as cswap auto in the background; it shares the autoswitch.* settings, so the menu bar and CLI stay in sync. Off until you turn it on.

Advanced

Configuration

Tool preferences live in settings.json in the backup root; cswap config reads and edits it with validation, so you never have to find the file or guess valid ranges.

Commands & usage
cswap config                              # list effective settings ("(default)" = not set)
cswap config get autoswitch.threshold
cswap config set autoswitch.threshold 80  # validated: rejects out-of-range values loudly
cswap config set autoswitch.model Fable   # per-model switching (see "auto"); Fable,Opus for several
cswap config unset autoswitch.threshold   # back to the default
cswap config path                         # where settings.json lives

cswap config --help lists every key with its valid range and default. Hand-editing the file still works — cswap config is just a safer front door. list and get take --json for scripting.

Backup and migration

Move account data between machines or back it up:

cswap export backup.cswap                    # All accounts to a file
cswap export backup.cswap --account 2        # One account
cswap export backup.cswap --full             # Include full local ~/.claude.json (same-PC backup)
cswap import backup.cswap                    # Skips accounts that already exist
cswap import backup.cswap --force            # Overwrite existing

The export file is plaintext JSON. If you need encryption, pipe through your tool of choice (e.g. cswap export - | gpg -c > backup.gpg).

If an imported account is the one you're currently logged in as, activate the imported credentials with cswap switch N --force (a plain switch to the current account is a safe no-op and won't touch the import).

JSON output for scripting

Add --json to list, status, or switch to emit a single machine-readable JSON object on stdout (human-readable notices go to stderr). Useful for scripting auto-swap and quota tracking.

cswap list --json                   # all accounts with usage/quota
cswap status --json                 # current active account
cswap switch --strategy best --json # switch, then report the result
cswap switch 2 --json
Example output & schema notes
{
  "schemaVersion": 1,
  "activeAccountNumber": 2,
  "accounts": [
    { "number": 2, "email": "[email protected]", "active": true, "usageStatus": "ok",
      "usage": { "fiveHour": { "pct": 25.0, "resetsAt": "2026-06-22T23:29:59Z" },
                 "sevenDay": { "pct": 16.0, "resetsAt": "2026-06-26T17:59:59Z" } } }
  ]
}

Every payload carries a schemaVersion (currently 1); on a handled error stdout is {"schemaVersion":1,"error":{...}} with a non-zero exit code. --switch/--switch-to report {"switched": true|false, "from": …, "to": …, "reason": …}.

Usage is served from a per-account cache: when the usage API is briefly unreachable, the last-known numbers are shown instead of nothing (the human view marks them with their age, e.g. · 2m ago). Rows with usage carry additive usageFetchedAt/usageAgeSeconds fields telling you how old the measurement is.

cswap auto --json emits an event stream instead — one JSON object per line ({"schemaVersion":1,"event":"switch","ts":…, …} with kinds like poll, switch, no-switch, account-quarantined, all-exhausted, error). The contract is additive: new kinds and fields may appear, so scripts should ignore unknown ones.

Add an account from a raw token or API key

If you only have a long-lived setup-token (e.g., produced by claude setup-token) or a managed API key (sk-ant-api...) and you don't want to log in via the browser flow first — useful on headless servers or when receiving a token from another machine — register it directly. The token type is auto-detected:

cswap add-token sk-ant-oat01-...             # OAuth setup-token
cswap add-token sk-ant-api03-...             # managed API key
cswap add-token sk-ant-oat01-... --slot 3
cswap add-token - --slot 3                   # read token from stdin
cswap add-token --email [email protected]     # optional label override

--email is optional; omitted values use setup-token-{slot}@token.local (or api-key-{slot}@token.local for API keys). No Anthropic API calls are made.

API-key accounts. An sk-ant-api... value registers a managed API-key account (the kind Claude Code uses after /login with a key) rather than an OAuth setup-token. It switches like any other account; since API keys have no subscription quota, they show no usage and the usage-aware switch strategies never skip them as rate-limited.

Uninstall

Remove all data:

cswap purge

Then uninstall the tool:

uv tool uninstall claude-swap
# or
pipx uninstall claude-swap

Requirements

  • Python 3.12+
  • Claude Code installed and logged in

License

MIT

// compatibility

Platformscli, api, web
Operating systems
AI compatibilityclaude
LicenseMIT
Pricingopen-source
LanguagePython

// faq

What is claude-swap?

Switch between multiple Claude Code accounts, with automatic rate-limit rotation, usage dashboard, and parallel sessions. It is open-source on GitHub.

Is claude-swap free to use?

claude-swap is open-source under the MIT license, so it is free to use.

What category does claude-swap belong to?

claude-swap is listed under devtools in the Claudeers registry of Claude-compatible tools.

0 views
980 stars
unclaimed
updated about 7 hours ago

// embed badge

claude-swap on Claudeers
[![Claudeers](https://claudeers.com/api/badge/claude-swap.svg)](https://claudeers.com/claude-swap)

// retro hit counter

claude-swap hit counter
[![Hits](https://claudeers.com/api/counter/claude-swap.svg)](https://claudeers.com/claude-swap)

// reviews

// guestbook

0/500

// related in Developer Tools

🔓

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Curs…

// devtoolsaffaan-m/JavaScript227,876MIT[ claude ]
🔓

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

// devtoolsgarrytan/TypeScript120,814MIT[ claude ]
🔓

AI coding assistant skill (Claude Code, Codex, OpenCode, Cursor, Gemini CLI, and more). Turn any folder of code, SQL schemas, R scripts, shell scripts, docs,…

// devtoolssafishamsi/Python80,484MIT[ claude ]
🔓

🙌 OpenHands: AI-Driven Development

// devtoolsOpenHands/Python80,252NOASSERTION[ claude ]
→ see how claude-swap connects across the ecosystem