Multi-account Anthropic auth plugin for OpenCode with quota-aware load balancing.
- Multi-account support: Add multiple Anthropic accounts (Claude Pro/Max)
- Quota-aware load balancing: Automatically selects the account with the lowest quota utilization at session start
- Sticky sessions: Stays on the same account throughout a session for consistency
- Automatic failover: On 429 rate limit errors, automatically switches to the next available account
- Token refresh: Automatically refreshes OAuth tokens when expired
- Account management: List and remove accounts via interactive CLI
- Usage inspection: View per-account Anthropic quota utilization from the login menu
- First-time migration: Automatically imports accounts from OpenAuth if available
Add the plugin to your OpenCode configuration in opencode.json:
{
"plugins": ["anthropic-multi-auth"]
}Run the OpenCode auth flow to add accounts:
opencode auth loginWhen prompted, select "Claude Pro/Max" to authorize a new account. After successful authorization, you'll be asked if you want to add another account. Repeat this process to add multiple Anthropic accounts.
To view and manage your configured accounts:
opencode auth loginSelect "Manage Accounts" to see your accounts and remove ones you no longer need.
To view current utilization for all configured accounts:
opencode auth loginSelect "View Account Usage" to print each account's status and usage utilization.
When a session starts, the plugin:
- Loads your saved accounts from
~/.config/opencode/anthropic-accounts.json - Checks the quota usage API for each account
- Selects the account with the lowest utilization
- Marks it as the active account for the session
Once an account is selected at session start, it remains active throughout the session. This ensures consistent behavior within a single session.
If an API request returns a 429 (Too Many Requests) response:
- The plugin waits the specified retry period
- Automatically switches to the next available account
- Retries the request with the new account
- If all accounts are rate-limited, returns an error with the shortest wait time
When tokens expire (checked via the expires timestamp):
- The plugin automatically refreshes the OAuth token
- Saves the new credentials to storage
- Syncs with OpenAuth to maintain consistency
Accounts are stored at:
~/.config/opencode/anthropic-accounts.json
Each account includes:
access: OAuth access tokenrefresh: OAuth refresh tokenexpires: Token expiration timestamp (milliseconds)addedAt: When the account was addedenabled: Whether this account is activeemail: (optional) User email from OAuthlabel: (optional) Friendly name for the account
This plugin extends the OpenCode builtin opencode-anthropic-auth with:
- Multi-account support (builtin only supports one account)
- Quota-aware account selection (builtin doesn't consider quota)
- Automatic failover on rate limits (builtin doesn't switch accounts)
If no accounts are configured, the plugin falls back to the builtin auth plugin, so the plugin is fully backward compatible.
Symptom: Plugin doesn't seem to be working.
Solution: Run opencode auth login and select "Claude Pro/Max" to add at least one account.
Symptom: Error: "All accounts rate-limited. Shortest wait: Xs."
Solution: Wait the specified time before trying again. If this happens frequently, consider adding more accounts.
Symptom: Error during session with 401/403 status codes.
Solution:
- Verify your refresh tokens haven't been revoked
- Run
opencode auth login→ "Manage Accounts" to remove and re-add affected accounts - Make sure your internet connection is stable
Symptom: Plugin doesn't appear to be active.
Solution:
- Check
opencode.jsonhas the correct plugin name:"anthropic-multi-auth" - Run
bun install(ornpm install) to ensure dependencies are installed - Check OpenCode version is compatible (requires
@opencode-ai/plugin@^0.4.45)
MIT