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

pi-openai-switcher

v0.1.3

Published

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

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.