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-auth-switcher

v0.2.1

Published

OpenCode auth plugin for multi-account Anthropic Claude Max rotation with automatic failover.

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:

  1. Multi-account rotation — maintains a pool of OAuth accounts and selects the best one on each request
  2. Real-time metric capture — reads Anthropic's rate-limit response headers on every API call (no manual pinging needed)
  3. 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 your primary account (first account = always preferred)
oc-auth-switcher add primary

# Add fallback accounts
oc-auth-switcher add fallback-1
oc-auth-switcher add fallback-2

Each 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. When the primary account exceeds the utilization threshold, the plugin switches to the next available fallback. When the primary recovers, it switches back.

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 | | config [options] | View/modify thresholds and check interval | | switch <name> | Manually switch to a specific 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)
oc-auth-switcher config --thresholds 90,80,70

# Set primary recovery check interval (default: 60 min)
oc-auth-switcher config --interval 30

# Reset to defaults
oc-auth-switcher config --reset

Data 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

  • The first account in the pool is always "primary" (preferred)
  • When the primary exceeds any utilization threshold, switch to the first fallback under threshold
  • If all fallbacks are also over threshold, pick the one with the lowest utilization score
  • When on a fallback, periodically check if the primary has recovered (configurable interval)
  • Auth failures trigger a 1-hour cooldown per account
  • Token refresh is handled automatically with retry and fallback 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 build

Publishing to npm

npm login
npm publish

The 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-tags

Updating the ex-machina dependency

bun update @ex-machina/opencode-anthropic-auth
bun run build
# Test, then publish

License

MIT