claw-router
Health Uyari
- License Γ’β¬β License: MIT
- Description Γ’β¬β Repository has a description
- Active repo Γ’β¬β Last push 0 days ago
- Low visibility Γ’β¬β Only 6 GitHub stars
Code Basarisiz
- rm -rf Γ’β¬β Recursive force deletion command in lib/watch.sh
- rm -rf Γ’β¬β Recursive force deletion command in test/run.sh
- Hardcoded secret Γ’β¬β Potential hardcoded credential in test/run.sh
Permissions Gecti
- Permissions Γ’β¬β No dangerous permissions requested
Bu listing icin henuz AI raporu yok.
π¦ Effortlessly manage your Claude subscriptions β route Claude Code across multiple accounts so your plans last longer.
Claw Router π¦
Effortlessly manage your Claude subscriptions.
One command. All your accounts. Used evenly, so they last.
Website Β· Install Β· Quick start Β· Commands Β· Policies Β· How it works
cr is a tiny wrapper around Claude Code.
Type cr followed by any normal claude arguments and it
picks one of your Claude accounts (round-robin by default), tells you which, and
launches Claude Code under that account β spreading the load so no single
subscription burns out first.
$ cr -p "explain this repo"
β work [email protected] (claude_max) Β· round-robin
β¦claude runs normallyβ¦
$ cr -p "and the tests?"
β personal [email protected] (claude_max) Β· round-robin
β¦next call, next accountβ¦
If you keep two or three Claude Max plans around so you don't hit the 5-hour
limit mid-flow, this is for you: stop manually /login-swapping, and let cr
balance them β including a usage-aware mode that routes to whichever account
has the most headroom right now.
Your secrets never move.
crflips one environment variable
(CLAUDE_CONFIG_DIR) per launch; Claude Code reads the right macOS Keychain
login and refreshes its own token.crnever reads, copies, or stores your
credentials.
How it works
Claude Code derives its macOS Keychain credential entry from theCLAUDE_CONFIG_DIR environment variable: each distinct config dir gets its own
isolated login (Claude Code-credentials-<hash>). cr keeps one directory per
account, and on each launch it:
- picks an account by policy (or your forced
--account), - unsets
ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN/CLAUDE_CODE_OAUTH_TOKEN
(these would otherwise override your subscription login), - sets
CLAUDE_CONFIG_DIRto that account's directory, - prints a one-line banner to stderr, and
execs the realclaudeβ so the TTY, signals, and exit code pass straight
through with zero overhead.
Claude Code itself reads the right Keychain credential and refreshes the token;cr never copies or stores your secrets.
Your existing ~/.claude login is registered as the default account and is
never modified.
Install
git clone https://github.com/dennisonbertram/claw-router.git
cd claw-router
./install.sh # symlinks `cr` into ~/.local/bin
Make sure ~/.local/bin is on your PATH. The only hard dependency is jq
(brew install jq); curl is needed for cr usage, and security / shasum
/ python3 ship with macOS.
Platform: macOS-first (it builds on the macOS Keychain). It runs on Linux
too β credentials come fromCLAUDE_CONFIG_DIR/.credentials.jsoninstead β but
the Keychain checks incr doctorare skipped there.
Quick start
cr register-default # adopt your current ~/.claude login as "default"
cr add work # create + browser-login a second account
cr add personal # β¦and a third
cr list # see them all
cr -p "hello" # round-robins across them
Commands
Launch (anything unrecognized is forwarded verbatim to claude):
| Command | Effect |
|---|---|
cr [argsβ¦] |
route by policy, then run claude args⦠|
cr --account <name> [argsβ¦] |
force an account |
cr@<name> [argsβ¦] |
shorthand for --account <name> |
cr --sandbox / -s [argsβ¦] |
run the session inside a cco sandbox |
cr --watch / -w [argsβ¦] |
supervised launch: auto-handoff to a fresher account near the limit |
cr --account <name> -- [argsβ¦] |
-- ends cr's flags; the rest is claude's |
Manage (never forwarded to claude):
| Command | Effect |
|---|---|
cr add <name> |
make an account dir, symlink shared settings, browser-login, cache identity |
cr add-backend <name> β¦ |
register an alt-model endpoint (e.g. DeepSeek); see Backends below |
cr add-api <name> |
register an Anthropic API key account (explicit-only by default) |
cr rotate <name> on|off |
opt an api-key account in or out of rotation |
cr register-default [name] |
register the existing ~/.claude login (no dir move) |
cr login <name> / cr logout <name> |
(re)auth / sign out an account |
cr remove <name> |
unregister (prints how to delete its dir + keychain item) |
cr list (accounts, ls) |
table of accounts: email, plan, last used, usage%, enabled |
cr use <name> |
pin the account a plain cr uses (overrides rotation) |
cr use --clear (cr unuse) |
un-pin; go back to the rotation policy |
cr policy <p> |
round-robin | lru | random | usage-aware |
cr usage [name] |
show usage meters per window (--plain for one-line text) |
cr status [--refresh] |
dashboard: next pick + per-account usage bars (cached; --refresh polls live) |
cr doctor [name] |
verify each account's dir + keychain credential |
Selection policies
- round-robin (default) β even spread across enabled accounts.
- lru β least-recently-used first.
- random β uniform random.
- usage-aware β route to the account with the most headroom, using the
numbers fromcr usage. Runcr usageperiodically (or wire it to a cron) to
refresh the cached figures; falls back tolruif usage data is unavailable.
All policies skip exhausted accounts. Before routing, cr refreshes usage
when the cache is stale and drops any account at/above the exhaustion threshold
(default 100%) from the rotation β so a maxed-out subscription is never chosen.
If every account is exhausted, it falls back to the full set rather than
failing. An account with no usage data yet counts as available. Tune it:
cr config # show routing knobs
cr config exhausted-at 90 # treat β₯90% used as "out", leave headroom
cr config auto-refresh off # don't auto-poll before routing (use cr usage)
cr config ttl 600 # consider cached usage stale after 10 min
Tip: cr usage draws a meter of how much is left in each window (5-hour session,
7-day total, and per-model 7-day) with reset countdowns, so you can see at a
glance which subscription to lean on:
usage left per window (β = available)
default [email protected]
5h session ββββββββββββββββββββββ 42% left resets in 1h17m
7d total ββββββββββββββββββββββ 88% left resets in 2d13h
personal [email protected]
5h session ββββββββββββββββββββββ 100% left resets in 4h47m
7d total ββββββββββββββββββββββ 100% left resets in 4d22h
Bars are colored green/yellow/red by headroom. cr usage --plain prints a
single line per account instead.
API-key accounts
Run Claude Code billed directly to an Anthropic API key, with its own config dir and conversation history β completely separate from your subscription accounts.
API-key accounts are explicit-only by default. A plain
crwill never auto-pick one. This is intentional: if you have a work API key, it must not bleed into personal projects. You reach an api account by naming it directly, or by explicitly opting it into rotation.
Register one:
cr add-api work-key # prompt for key (hidden input)
cr add-api work-key --from-env # copy from $ANTHROPIC_API_KEY
cr add-api personal-key --rotate # opt into rotation at registration time
Opt an existing account in or out of rotation:
cr rotate personal-key on # plain 'cr' may now pick it
cr rotate personal-key off # back to explicit-only
cr rotate personal-key # print current state
Use it:
cr@work-key -p "draft the proposal" # always explicit β never auto-selected
cr@personal-key # interactive session under that key
How it works: cr exports ANTHROPIC_API_KEY and sets CLAUDE_CONFIG_DIR to the account's own directory (history, projects, and settings all live there). It scrubs ANTHROPIC_AUTH_TOKEN, CLAUDE_CODE_OAUTH_TOKEN, and ANTHROPIC_BASE_URL so no conflicting auth leaks through.
No usage meters. API-key accounts are pay-per-token; there are no usage windows to poll. cr usage work-key prints a short note instead of a meter, and the all-accounts cr usage silently skips api accounts. Watch-mode handoffs never target api accounts for the same reason.
Backends (alternate models, e.g. DeepSeek)
Besides your Anthropic subscriptions, cr can route Claude Code to an
Anthropic-compatible endpoint like DeepSeek. These are registered as backend
accounts and behave differently from subscriptions in one deliberate way:
Backends are explicit-only. They are never in the rotation. A plain
cr
(round-robin / lru / usage-aware) only ever picks your subscriptions. You reach
a backend by naming it:cr@deepseek β¦orcr --account deepseek β¦. This keeps
an inferior fallback model out of your normal flow until you ask for it.
Register one (seeding the key from an existing deep-claude Keychain item):
cr add-backend deepseek --seed-from-deep-claude
# or supply the key interactively:
cr add-backend deepseek
# customize endpoint / model / aliases:
cr add-backend myllm --base-url https://host/anthropic --model some-model \
--alias fast=some-fast-model
Use it:
cr@deepseek -p "quick scratch task" # default model
cr@deepseek --model flash -p "β¦" # alias β deepseek-v4-flash
A backend launch sets ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN /ANTHROPIC_MODEL, leaves CLAUDE_CONFIG_DIR and HOME untouched (so gh
and keychain tools keep working), and stores its API key under cr's own Keychain
item (claw-router-backend / <name>). It's effectively deep-claude folded
into cr.
Sandbox mode
Add --sandbox (or -s) to run the session inside a container, so Claude Code
can't touch anything outside your project:
cr --sandbox -p "run the migration and tests"
cr@work -s # sandboxed interactive session
This delegates isolation to cco (βClaude
Containerβ). cr still does the account routing β it picks the account, setsCLAUDE_CONFIG_DIR, then launches through cco instead of claude. Becausecco reads the same CLAUDE_CONFIG_DIR (for both config and the Keychain
login), the right account is used inside the box, and your normal policies,
pins, backends, and --resume all compose with --sandbox unchanged.
cco isn't bundled (it's a separate GPL-3.0 project). If it's missing, cr
tells you the one-line install:
curl -fsSL https://raw.githubusercontent.com/nikvdp/cco/master/install.sh | bash
Watch mode
Add --watch (or -w) to stay in the conversation past your account's usage
limit. Instead of exec-ing claude and stepping away, cr stays alive,
watches the current account's usage in the background every two minutes, and
when usage nears its limit gracefully restarts claude under a fresher account
with --resume β the conversation continues because the session transcript is
symlinked across accounts via the existing session-linking machinery.
cr --watch # interactive session, auto-handoff when near limit
cr -w --account work # force starting account
cr --watch --resume <id> # pick up an existing session and keep watching
The handoff happens at a turn boundary: cr waits until the session transcript
has been idle for at least 30 seconds (configurable), so an in-flight reply is
never interrupted mid-stream. The restart takes only a few seconds.
Three knobs (all configurable via cr config):
cr config watch-at 90 # hand off when usage reaches 90% (default)
cr config watch-interval 120 # poll every 120s (default)
cr config watch-idle 30 # wait for 30s of session inactivity before handing off (default)
Bypasses (watch silently degrades and runs normally):
-p/--printβ one-shot; no session to watch.- Backends (
cr@deepseek) β no usage data to poll. - Only one enabled subscription account β nowhere to hand off to.
--watch composes with --sandbox (best-effort: both flags are independent).
Sessions across accounts
Claude Code stores each conversation under the account that created it
(<config-dir>/projects/<cwd>/<id>.jsonl). cr handles this two ways:
cr --resume <id>just works. Normal rotation (or your--accountpin)
picks the account, andcrtransparently symlinks the session in from whatever
account owns it β so you never see "No conversation found" from landing on the
wrong account, and you don't have to think about where the session lives.
(Subagent transcripts are linked too. The account you resume under is the one
billed for new turns.)cr adopt <id> <account>does the same linking manually, if you want to
prepare a session for another account ahead of time:cr adopt 5fe702a8-β¦ personal # link a session 'work' started into 'personal' cr@personal --resume 5fe702a8-β¦ # (or just `cr --resume` β it auto-links anyway)Linking is a symlink, so the accounts share one evolving transcript.
Notes & limits
- macOS-first. Keychain isolation is the clean path on macOS. On Linux the
same model works viaCLAUDE_CONFIG_DIR/.credentials.jsonbut the Keychain
checks incr doctorare skipped. --resume <id>auto-links the session into the picked account, so it
resumes regardless of which account created it (see Sessions across accounts).
A bare--continuehas no id to match β it just runs under the picked account.- Shared settings.
cr addsymlinkssettings.json,CLAUDE.md,commands/, andrules/from~/.claudeso your config isn't fragmented;
per-account history/projects stay separate. - The
/api/oauth/usageendpoint is undocumented;cr usageis best-effort and
degrades gracefully.
Appearance
cr colorizes its banner, list, status, and help when stderr is a
terminal. It honors NO_COLOR and a dumb $TERM, and
strips all styling automatically when output is piped β so cr -p β¦ stdout and
any captured output stay clean.
Tests
bash test/run.sh
No real Claude or network calls β uses a fake claude and an isolated config
home. 30+ assertions cover account selection, env scrubbing, arg forwarding,
the Keychain naming scheme, backend isolation, usage rendering, and
cross-account session linking.
License
MIT Β© Dennison Bertram
Not affiliated with Anthropic. βClaudeβ and βClaude Codeβ are trademarks of Anthropic.
Yorumlar (0)
Yorum birakmak icin giris yap.
Yorum birakSonuc bulunamadi