omp packages

pi-multi-accounts0.2.1

Pi extension: switch between several Claude Pro/Max OAuth logins with /account, and use extra ChatGPT (Codex) logins as parallel openai-codex-<name> providers

nvminhtue Published 18 days ago MIT ~323 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-multi-accounts

A Pi extension for people with more than one subscription:

  • Claude: keep multiple Claude Pro/Max OAuth accounts for Pi's built-in /login and switch between them with a single /account command. Pi stores exactly one anthropic credential; this extension saves additional logins next to it and swaps the active one on demand.
  • Codex: use extra ChatGPT (Codex) logins as parallel providers (openai-codex-<name>) next to Pi's built-in openai-codex. Nothing is switched: pick the account's model with /model.

Install

# local checkout
pi install /absolute/path/to/pi-multi-accounts

# or from git
pi install git:github.com/<user>/pi-multi-accounts

Then run /reload (or restart Pi).

Migrating from the standalone extensions / the old package

  • Remove ~/.pi/agent/extensions/codex-accounts.ts and ~/.pi/agent/extensions/claude-accounts.ts if present. Otherwise the commands and providers are registered twice.
  • Remove old pi-claude-accounts package entries from your Pi settings.
  • ~/.pi/agent/claude-accounts.json is kept: your saved Claude accounts continue to work.

Usage

Command What it does
/account Pick a Claude account from a list and switch to it
/account <name> Switch to the saved Claude account <name>
/account save <name> Save the current Anthropic /login under <name>
/account list List Claude accounts (● active, ○ inactive) and Codex providers (login state)
/account remove <name> Forget a saved Claude account (auth.json is not changed)
/account help Show command help

Switch, save and remove work on Claude accounts only. Codex providers are only listed.

Aliases: add = save, ls = list, rm = remove, use/switch = switch.

The footer shows claude: <name> for the active saved account, or claude: unsaved login when the login in auth.json is not saved yet.

Logging in to a second account

  1. /login with your first Claude account, then /account save work.

  2. Run /login again. Pi reuses the browser's existing claude.ai session, so you would simply get the same account back. To avoid that, do one of:

    • open the login URL Pi prints in a private/incognito window, or
    • use a different browser profile, or
    • sign out of claude.ai first.

    Copy the login URL Pi prints into the private window and sign in with the second account.

  3. /account save personal.

  4. Run /account list and check that the emails differ.

Codex accounts

  1. For each extra ChatGPT account, log in with the Codex CLI into its own folder: CODEX_HOME=~/.codex-<name> codex login.
  2. In Pi, run /login and choose "OpenAI Codex ()". This imports the tokens from ~/.codex-<name>/auth.json; no browser is involved.
  3. Pick the model with /model, e.g. openai-codex-<name>/<model>. The provider has the same models as the built-in openai-codex.

The Codex auth file stays the source of truth: on refresh the extension first adopts newer tokens found in the file (e.g. refreshed by the Codex CLI); otherwise it refreshes with the file's refresh token and writes the rotated tokens back. New ~/.codex-* folders are discovered at load time, so run /reload after creating one.

How it works (Claude)

  • Pi keeps a single anthropic entry in ~/.pi/agent/auth.json. Switching replaces that entry and leaves other providers untouched.
  • Saved logins live in ~/.pi/agent/claude-accounts.json (mode 0600).
  • Writes happen under the same auth.json.lock directory lock that Pi's proper-lockfile uses, so Pi and the extension never write at the same time.
  • Refresh tokens rotate. When Pi refreshes the active token, the extension copies the new one back into the right slot on session_start, after each agent_end, and during every switch.
  • To tell whose token is whose, it asks https://api.anthropic.com/api/oauth/profile for the account id/email. If that lookup fails, it falls back gracefully (matching on the refresh token, or asking you when ownership is unclear).

Caveats

  • auth.json is shared: switching affects every running Pi session.
  • It relies on Pi internals (the auth.json format and its lock directory). Tested with Pi 0.99.2.
  • The Anthropic profile endpoint is unofficial and may change.
  • The OpenAI token endpoint and client id used for Codex refresh are unofficial and may change.
  • The Codex CLI and Pi share each Codex refresh token (single use); if both refresh at once, one of them may need codex login and /login again.
  • claude-accounts.json contains refresh tokens. Keep it private and never commit it.

Development

npm install
npm run check   # typecheck + tests

Layout:

src/index.ts                  entry point: registers Codex providers, then the /account command
src/claude.ts                 Claude account switching (no build step)
src/codex.ts                  Codex parallel providers
test/account.test.mjs         node:test suite for /account (temp PI_CODING_AGENT_DIR and HOME, no network)
test/codex.test.mjs           node:test suite for the Codex providers (stubbed fetch, no network)

License

MIT