Picking an account for scripts
On this page
ccam pick prints the name of the logged-in account with the most room, so a script can start Claude Code with it. Workers started at the same time each get a different account as long as enough accounts have room, so a batch of claude -p jobs spreads over your accounts instead of draining one.
Usage
Starting a job on the picked account
ccam "$(ccam pick)" -p "fix the failing tests"ccam pick prints only the account's name, so ccam "$(ccam pick)" starts Claude Code as that account. Exit codes: 0 with a name on standard output, 75 (EX_TEMPFAIL) when no account has room or none is logged in, 1 for other errors such as a bad flag. Check for 75 in a script, or let the job wait with --wait (below).
Team and Enterprise seats. Automatic account selection (ccam next, --fallback, ccam pick, ccam agent, the dashboard's n and, once you turn it on, auto_switch) also switches between seats of the same Claude Team or Enterprise organization, which may violate Anthropic's terms. Read the FAQ and check with your organization and Anthropic before you rely on it.
Spreading parallel jobs
for task in parse lint docs; do
ccam "$(ccam pick)" -p "do the $task task" > "$task.json" &
done; waitEach ccam pick remembers its choice for 2 minutes, and the next pick leaves that account out while others have room. The three jobs above therefore start on three different accounts when three have room (How it works).
Seeing why an account was chosen
ccam pick --json--json prints the account, its 5-hour and weekly usage, where the numbers come from and why it was chosen:
$ ccam pick --json
{
"name": "work",
"slot": 2,
"email": "dev@company.com",
"five_hour": { "percent": 12, "resets_at": "2026-10-20T15:10:00Z", "known": true },
"weekly": { "percent": 41, "resets_at": "2026-10-24T09:00:00Z", "known": true },
"source": "live",
"reason": "12% of its 5 hours used, the least"
}Changing how it chooses
ccam pick --model opus
ccam pick --max-usage 80 --strategy expiring
ccam pick --strategy balance
ccam pick --cross-org--model <model>: also count that model's weekly window, such asopus, so an account that has used up its Opus allowance is not picked for an Opus job.--max-usage <1-100>: accounts below this usage come first. Without it,auto_max_usageapplies, otherwise 100.--strategy headroom|expiring|balance:headroomtakes the least weekly usage among the accounts within 3 points of the lowest 5-hour usage,expiringthe soonest 5-hour reset andbalancethe most weekly quota left per day, with fewer running sessions first. Without it,auto_strategyapplies, otherwiseheadroom.--cross-org: also choose accounts of other organizations. Without it,cross_orgdecides, and it is off unless you set it.
ccam --dry-run pick chooses the same way but does not record the pick, so the next pick may choose the same account.
When no account has room
ccam pick --wait=2h
ccam --fallback "$(ccam pick)" -p "…"--wait waits for the first account to reset instead of exiting with code 75, at most 5 hours or as long as you give. The value goes after =: --wait 30m is refused with the hint --wait takes its value after '=': --wait=30m.
If the account reaches its limit during the job, --fallback before the account name runs the job again as another account (Run again at the limit).
How it works
- ccam lists the logged-in accounts (API key accounts and Console logins have no limits and are left out) in the organization of the account this folder would start (see organizations); a folder logged in to the same Claude account as that one is left out too.
- It takes a lock (
~/.local/state/ccam/picks.lock), so picks running at the same time happen one after another. - It looks up every account's usage at once, the same way
ccam usagedoes, with the 60-second cache. A window Claude Code reported full counts as 100% until its reset (the limit record), so an account that has just hit its limit is excluded even if its saved numbers still show room. - Accounts picked within the last 2 minutes, by
ccam pick, byccam agentor byauto_switchmoving a session there (~/.local/state/ccam/picks/<name>; a pick with a future timestamp does not count), are left out first, and the choice rules ofccam next --autopick among the rest: belowauto_max_usagefirst, by the strategy, never an account at 100%. If this skips the account the rules would otherwise choose, thereasonof--jsonsays so:30% of its 5 hours used; work was picked a moment ago. - If every account with room was picked recently, the rules choose among all of them again, so with three accounts, a fourth worker shares one of them.
- The pick is recorded and the lock released, then the name is printed.
The 2-minute window matters because a new job's usage takes a while to show in the numbers: without it, five workers started together would all see the same account as the one with the most room.
Safety and edge cases
ccam pickonly reads usage and writes the pick time; it never renews or reads tokens beyond whatccam usagedoes.- A pick does not reserve the account. Two scripts may still start on the same account after 2 minutes; use
--fallbackto recover when that account hits its limit. - Waiting with
--waitholds no lock, so other picks go on meanwhile. ccam pickdoes not simply return the folder's account set withccam folder: it chooses by usage, and uses the folder's account only to know which organization to stay in.