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
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.
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
/loginand switch between them with a single/accountcommand. Pi stores exactly oneanthropiccredential; 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-inopenai-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.tsand~/.pi/agent/extensions/claude-accounts.tsif present. Otherwise the commands and providers are registered twice. - Remove old
pi-claude-accountspackage entries from your Pi settings. ~/.pi/agent/claude-accounts.jsonis 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
/loginwith your first Claude account, then/account save work.Run
/loginagain. 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.
/account save personal.Run
/account listand check that the emails differ.
Codex accounts
- For each extra ChatGPT account, log in with the Codex CLI into its own folder:
CODEX_HOME=~/.codex-<name> codex login. - In Pi, run
/loginand choose "OpenAI Codex ()". This imports the tokens from~/.codex-<name>/auth.json; no browser is involved. - Pick the model with
/model, e.g.openai-codex-<name>/<model>. The provider has the same models as the built-inopenai-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
anthropicentry in~/.pi/agent/auth.json. Switching replaces that entry and leaves other providers untouched. - Saved logins live in
~/.pi/agent/claude-accounts.json(mode0600). - Writes happen under the same
auth.json.lockdirectory lock that Pi'sproper-lockfileuses, 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 eachagent_end, and during every switch. - To tell whose token is whose, it asks
https://api.anthropic.com/api/oauth/profilefor 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.jsonis shared: switching affects every running Pi session.- It relies on Pi internals (the
auth.jsonformat 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 loginand/loginagain. claude-accounts.jsoncontains 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