oc-auth-switcher
v0.9.3
Published
OpenCode auth plugin for multi-account Anthropic Claude Max rotation with automatic failover.
Downloads
1,389
Maintainers
Readme
oc-auth-switcher
OpenCode auth plugin for multi-account Anthropic Claude Max rotation with automatic failover. Captures rate-limit headers in real-time and switches accounts before you hit usage limits.
How It Works
This plugin registers as the Anthropic auth provider for OpenCode. It uses @ex-machina/opencode-anthropic-auth as a library for request/response transformation (billing header, system prompt sanitization, tool name prefixing) and adds:
- Multi-account rotation — maintains a pool of OAuth accounts and selects the best one on each request
- Real-time metric capture — reads Anthropic's rate-limit response headers on every API call (no manual pinging needed)
- Automatic failover — when any utilization metric exceeds the threshold (default 95%), the next request automatically uses a different account
Setup
1. Add the plugin to your opencode.json
{
"plugin": ["oc-auth-switcher@latest"]
}This is the only auth plugin you need for Anthropic. Do not also list @ex-machina/opencode-anthropic-auth — it is included as a dependency.
2. Add accounts
# Add accounts in any order
oc-auth-switcher add work
oc-auth-switcher add personal
oc-auth-switcher add teamEach add command runs an OAuth flow — you'll be given a URL to open in your browser and prompted to paste the callback.
3. Use OpenCode normally
Metrics update automatically on every API request. The active account remains selected until it reaches a relevant utilization threshold or becomes unavailable, then the plugin switches to the available account with the most headroom.
CLI Commands
oc-auth-switcher <command> [options]| Command | Description |
|---------|-------------|
| add [name] | Add a new account via OAuth |
| reauth <name> | Re-authenticate an existing account |
| usage [--watch] | Show utilization dashboard with progress bars and reset countdowns |
| config [options] | View/modify thresholds |
| switch <name> | Set the active account |
| status | Show current active account and rotation state |
| remove <name> | Remove an account from the pool |
Configuration
# Set uniform threshold (default: 95%)
oc-auth-switcher config --threshold 0.95
# Set per-metric thresholds (5h, 7d, 7d-sonnet, 7d-fable)
oc-auth-switcher config --thresholds 90,80,70,70
# Reset to defaults
oc-auth-switcher config --resetData Files
| File | Location | Purpose |
|------|----------|---------|
| Accounts | ~/.config/opencode/auth-switcher-accounts.json | OAuth token pool |
| State | ~/.config/opencode/auth-switcher-state.json | Usage metrics, active account, config |
Both files use atomic writes with .bak fallback for crash safety.
Rotation Algorithm
- Keep the active account while its model-relevant utilization remains below threshold
- When rotation is required, select the available account with the lowest maximum threshold-normalized utilization
- Break exact utilization ties by account array order
- If every account is exhausted, select the least-loaded account rather than failing
- Recovered accounts do not preempt a healthy active account
- Auth failures trigger a 10-minute cooldown per account
- Token refresh is handled automatically with retry and failover to other accounts
Running the CLI
When installed via npm (as part of the OpenCode plugin):
npx oc-auth-switcher <command>From the project directory (development):
bun dist/cli.js <command>Building from Source
bun install
bun run buildPublishing to npm
npm login
npm publishThe prepublishOnly script automatically runs bun run build before publishing.
Versioning
# Patch (bug fixes)
npm version patch && npm publish && git push --follow-tags
# Minor (new features)
npm version minor && npm publish && git push --follow-tags
# Major (breaking changes)
npm version major && npm publish && git push --follow-tagsUpdating the ex-machina dependency
bun update @ex-machina/opencode-anthropic-auth
bun run build
# Test, then publishLicense
MIT
