Skip to content

sasha-computer/pi-multi-claude-code

Repository files navigation

Multi Claude Code

Switch between multiple Anthropic OAuth accounts in pi. Personal, enterprise, work, side-project -- name them whatever you want, add as many as you need, and swap between them mid-conversation.

Directional fallback chains keep your accounts isolated: enterprise can fall back to personal on rate-limit, but personal never touches enterprise. You control which direction requests flow.

How it works

flowchart TD
    subgraph pi["pi session"]
        User(["You send a message"])
        MCC["multi-claude-code provider"]
        Base["Built-in anthropic-messages provider"]
    end

    subgraph accounts["Account Pool"]
        A1["personal"]
        A2["enterprise"]
        A3["side-project"]
    end

    User --> MCC
    MCC -->|"1. Pick active account"| accounts
    MCC -->|"2. Inject OAuth token"| Base
    Base -->|"3. Stream response"| Anthropic["Anthropic API"]

    subgraph fallback["On 429 Rate Limit"]
        direction LR
        RL["Rate-limited account"] -->|"follows fallback chain"| Next["Next allowed account"]
        Next -->|"retry"| Base2["Retry request"]
    end

    Anthropic -.->|"429"| fallback
Loading
flowchart LR
    subgraph chain["Example: fallback chains"]
        direction LR
        E["enterprise"] -->|"can fall back to"| P["personal"]
        E -->|"can fall back to"| S["side-project"]
        P -.-x|"no fallback"| E
        S -.-x|"no fallback"| E
    end

    style P fill:#2d4a3e,stroke:#4a7a62
    style E fill:#4a3a2d,stroke:#7a6a52
    style S fill:#2d3a4a,stroke:#527a8a
Loading

The extension registers a provider called multi-claude-code that mirrors every Anthropic model. On each request, it:

  1. Picks the active account (your manual selection, or the last used)
  2. Refreshes the OAuth token if it's about to expire
  3. Passes the token to the built-in anthropic-messages provider
  4. If the API returns a 429 before any tokens stream, follows the account's fallback chain and retries (up to 5 hops)

Tokens are injected per-request, not configured globally. That's why /mcc-use works instantly, even mid-session.

Install

pi install npm:pi-multi-claude-code

Or load directly from a local checkout:

pi -e ./index.ts

Restart pi after installing.

Setup walkthrough

1. Add your accounts

Labels are freeform. Call them whatever makes sense to you.

/mcc-login personal

Your browser opens to Anthropic's OAuth page. Log in, authorize, paste the code back into pi. Repeat for each account:

/mcc-login enterprise
/mcc-login side-project

2. Configure fallback chains

By default, every account has no fallback. If it gets rate-limited, the request fails. This is the safe default.

You opt in to fallback per account. The syntax is /mcc-fallback <source> <target1> <target2> ...:

/mcc-fallback enterprise personal side-project

This means: if enterprise hits a rate limit, try personal first, then side-project. Order matters.

Your personal account has no fallback configured, so personal work never lands on enterprise. That's the whole point.

To see what's configured:

/mcc-fallback

To clear a fallback (back to fail-on-limit):

/mcc-fallback enterprise

3. Select the provider

Open the model picker with /model and choose any model under the multi-claude-code provider. These are the same Anthropic models you already use, just routed through the extension.

4. Switch accounts

Interactive picker:

/mcc-use

Or switch directly:

/mcc-use personal

Or press Ctrl+Shift+A to cycle through accounts without leaving the editor -- same feel as Ctrl+P for models.

The status bar updates immediately to reflect the active account. If a fallback fires mid-session, it updates there too.

Commands

Command Description
/mcc-login <label> Add an account. Opens Anthropic OAuth in your browser.
/mcc-use [label] Switch accounts. No label opens an interactive picker.
/mcc-fallback [source targets...] Set or view fallback chains. No args shows all chains.
/mcc-status All accounts with token expiry, rate-limit cooldowns, and fallback config.
/mcc-remove <label> Delete an account from the pool.

Keyboard shortcuts

Shortcut Action
Ctrl+Shift+A Cycle to the next account in order

Storage

Account credentials are stored in ~/.pi/agent/multi-claude-code.json. This file contains OAuth refresh tokens. Treat it like a password file.

Rate-limit behavior

When the Anthropic API returns a 429 (or similar overload error) before any tokens have streamed:

  1. The current account gets a 1-hour cooldown
  2. The extension checks the account's fallbackTo list
  3. If a fallback account is available and not also rate-limited, it retries the request
  4. If no fallback is configured or all fallbacks are exhausted, the error surfaces to you
  5. Cooldowns clear automatically. /mcc-status shows remaining time.

If tokens have already started streaming when an error occurs, the extension does not retry (it would lose partial output). The error passes through as-is.

Development

npm install
npm run tsgo    # type-check
npm run test    # run tests

Load the extension from source for development:

pi -e ./index.ts

License

MIT

About

Switch between multiple Anthropic OAuth accounts in pi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors