npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

oc-anthropic-multi-account

v1.0.11

Published

OpenCode plugin for managing multiple Anthropic Max accounts with automatic failover based on rate limit utilization

Readme

oc-anthropic-multi-account

npm version

Never hit a Claude rate limit again with proactive multi-account switching for OpenCode.

Installation

1. Add plugin to OpenCode config

Add to your opencode.json (global or project-level):

{
  "plugin": [
    "oc-anthropic-multi-account@latest"
  ]
}

OpenCode will install the plugin automatically on next launch.

2. Disable default Anthropic plugin

Add this to your ~/.zshrc or ~/.bashrc:

export OPENCODE_DISABLE_DEFAULT_PLUGINS=true

Without this, the built-in Anthropic plugin will override the custom fetch wrapper.

3. Configure accounts

The CLI (src/cli.ts) isn't bundled in the npm package. Clone the repo to use it:

git clone [email protected]:gaboe/oc-anthropic-multi-account.git
cd oc-anthropic-multi-account
bun install

Add accounts (the first account added is the primary):

bun src/cli.ts add primary
bun src/cli.ts add fallback1
bun src/cli.ts add fallback2

You can name accounts anything, such as work, personal, or backup. The CLI will guide you through OAuth authentication for each account.

Each account requires a separate Anthropic Max subscription.

Tokens are stored in ~/.config/opencode/anthropic-multi-account-accounts.json:

{
  "accounts": [
    {
      "name": "primary",
      "access": "your-access-token",
      "refresh": "your-refresh-token",
      "expires": 1234567890000
    }
  ]
}

Tokens are automatically refreshed when expired.

4. Restart OpenCode

opencode

Why This Plugin?

Claude Max subscriptions have strict rate limits. Hitting them kills your flow and forces you to wait minutes or hours before you can work again. This plugin manages multiple accounts and automatically switches between them based on real-time usage metrics.

What This Plugin Does Differently

  • Proactive switching reads rate limit headers from every response and switches before you hit a 429 error.
  • Tracks 3 independent metrics: session (5h), weekly (all models), and weekly (Sonnet).
  • Per-metric configurable thresholds allow fine-grained control over when to switch.
  • Mid-session switching ensures you aren't stuck with a depleted account.
  • Primary-first logic with automatic recovery switches back when your main account recovers.
  • Atomic file writes with backups ensure crash-safe state persistence.
  • Works with any number of accounts and subscription tiers (5x, 20x, or a mix).
  • Live usage dashboard via CLI provides full visibility into your account status.

How It Works

┌─────────────────────────────────────────────────────────────┐
│                      Request Flow                           │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   Request  ──►  Check primary metrics  ──►  Route request  │
│                        │                        │           │
│                        ▼                        ▼           │
│               Any metric > 70%?         Use selected        │
│                   │       │              account            │
│                  YES      NO                 │              │
│                   │       │                  ▼              │
│                   ▼       ▼           Capture response      │
│            Use fallback  Use primary    headers             │
│                                              │              │
│                                              ▼              │
│                                        Update usage         │
│                                        metrics              │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Account Priority

  • accounts[0] = Primary (always preferred)
  • accounts[1..n] = Fallbacks (in order of preference)

Threshold Logic

Each metric (session, weekly, sonnet) can have its own threshold.

| Condition | Action | |-----------|--------| | Any primary metric > its threshold | Switch to first fallback under thresholds | | All primary metrics < their thresholds | Switch back to primary | | On fallback | Check recovery every 1 hour or on rate limit window reset |

Metrics Tracked

Anthropic sends these headers with every response (no extra API calls needed):

  • anthropic-ratelimit-unified-5h-utilization - 5-hour rolling window
  • anthropic-ratelimit-unified-7d-utilization - 7-day rolling window
  • anthropic-ratelimit-unified-7d_sonnet-utilization - 7-day Sonnet-specific

CLI

All commands via unified CLI:

bun src/cli.ts usage              # show usage
bun src/cli.ts usage --watch      # live updates (5s)
bun src/cli.ts config             # show config
bun src/cli.ts config --thresholds 95,80,90   # session, weekly, sonnet
bun src/cli.ts config --threshold 0.80        # same value for all metrics
bun src/cli.ts config --interval 30           # recovery check interval (minutes)
bun src/cli.ts add <account-name>             # add account via OAuth

Example output:

╔══════════════════════════════════════════════════════════════════╗
║              oc-anthropic-multi-account                          ║
╚══════════════════════════════════════════════════════════════════╝

┌─ max-5x ◄── ACTIVE
│
│  Session (5h)  (threshold 95%)
│  █████████                                           18%
│  Resets Feb 4 at 5:00 PM
│
│  Weekly (all)  (threshold 80%)
│  ██                                                  4%
│  Resets Feb 11 at 9:00 AM
│
│  Weekly (Sonnet)  (threshold 90%)
│  █                                                   2%
│  Resets Feb 16 at 8:00 AM
└─

┌─ max-20x
│  ...
└─

  Requests: 473

Colors: 🟢 < 50% │ 🟡 50-70% │ 🔴 > 70% │ 🔵 active

Configuration

Configure via CLI (saved to state file):

bun src/cli.ts config --thresholds 95,80,90   # set session, weekly, sonnet thresholds
bun src/cli.ts config --threshold 0.80         # same threshold for all metrics
bun src/cli.ts config --threshold-session 0.95  # set individual metric
bun src/cli.ts config --threshold-weekly 0.80
bun src/cli.ts config --threshold-sonnet 0.90
bun src/cli.ts config --interval 30             # check recovery every 30 min
bun src/cli.ts config --reset                   # reset to defaults

Defaults: threshold=70%, interval=60min

Changing config auto-evaluates whether the active account should switch.

Data Storage

Data is split into two files to prevent corruption from frequent writes:

~/.config/opencode/anthropic-multi-account-accounts.json - Tokens (changes rarely)

  • accounts - Array of accounts with access/refresh tokens

~/.config/opencode/anthropic-multi-account-state.json - Runtime state (changes frequently)

  • currentAccount - Currently active account name
  • usage - Per-account usage metrics with timestamps
  • requestCount - Total requests made through the plugin
  • lastPrimaryCheck - Timestamp of last recovery check

Comparison

| Tool | Multi-Account | Proactive Switching | Header-Based Metrics | Mid-Session Switch | OpenCode Plugin | |------|--------------|--------------------|--------------------|-------------------|----------------| | oc-anthropic-multi-account | Yes (unlimited) | Yes (threshold-based) | Yes (3 metrics) | Yes | Yes | | anthropic-multi-auth | Yes | No (session-sticky) | No (quota API check) | No | Yes | | OpenCode built-in | Single account | No | No | N/A | Yes |

License

MIT