pi-openai-switcher

pi extension that switches ChatGPT Codex accounts when 5h or 1w usage limits are exhausted

Package details

extension

Install pi-openai-switcher from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-openai-switcher
Package
pi-openai-switcher
Version
0.1.3
Published
Apr 16, 2026
Downloads
493/mo · 22/wk
Author
faithless
License
MIT
Types
extension
Size
31.9 MB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./extensions"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi-openai-switcher

A pi extension that rotates the active openai-codex ChatGPT account before each prompt when the current account has exhausted either its 5h or 1w Codex usage window.

It uses the bundled Go tool at vendor/ChatGPTCheckUsage to:

  • inspect all configured ChatGPT accounts
  • refresh expired access tokens in memory
  • choose an account with remaining quota
  • hand pi a fresh runtime token for openai-codex

Files

  • extensions/openai-codex-account-switcher.ts — the pi extension
  • package.json — pi package manifest
  • vendor/ChatGPTCheckUsage — bundled usage checker used by the extension

Bundled CLI

The npm package includes:

  • prebuilt binaries in bin/ for:
    • Linux x64
    • Linux arm64
    • macOS x64
    • macOS arm64
    • Windows x64
  • the CLI source in vendor/ChatGPTCheckUsage

The extension uses the bundled binary by default, so users do not need Go installed on supported platforms.

If the current platform is unsupported, the extension can still fall back to go run when Go is available.

Go tool changes

The extension expects the usage checker to support:

go run . --accounts-path ./accounts.json --json --include-usable-access-token

That now returns structured JSON and includes the in-memory usable access token for each successfully refreshed account.

Account file

By default the extension reads:

  • ~/.pi/agent/pi-openai-switcher/accounts.json

This keeps account tokens out of the installed npm package directory.

You can override paths with:

  • PI_OPENAI_SWITCHER_BINARY_PATH
  • PI_OPENAI_SWITCHER_TOOL_DIR
  • PI_OPENAI_SWITCHER_ACCOUNTS_PATH
  • PI_OPENAI_SWITCHER_STATE_PATH

Adding accounts

Users are expected to add accounts through the bundled usage CLI's OAuth flow.

Recommended way inside pi

Use the extension command:

/chatgpt-add-account <name>

Example:

/chatgpt-add-account work

That command:

  • launches the bundled usage CLI
  • starts the ChatGPT OAuth login flow
  • opens the browser
  • saves the account into ~/.pi/agent/pi-openai-switcher/accounts.json

Manual way outside pi

You can also run the bundled binary directly from the installed package directory, or from the source checkout. The exact installed package path depends on how the package was installed, so the in-pi command is the recommended path.

From the source checkout, if you have Go installed:

cd vendor/ChatGPTCheckUsage
go run . --accounts-path ~/.pi/agent/pi-openai-switcher/accounts.json --add-account --name work

Usage

From this repo:

pi -e ./extensions/openai-codex-account-switcher.ts

Or install/load the package as a pi package.

Commands

  • /chatgpt-accounts — show account usage and which account is active
  • /chatgpt-add-account <name> — add an account through ChatGPT OAuth
  • /chatgpt-switch <name> — force-switch to a specific usable account and persist that preference across pi restarts

Behavior

When the current model provider is openai-codex, the extension:

  1. runs the bundled usage checker before each prompt
  2. keeps the current account if it still has quota
  3. otherwise switches to the best remaining account
  4. installs the selected access token as a runtime override for openai-codex

The footer status line shows the active account plus its 5h and 1w usage percentages.