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

@hieplp/pi-account-switcher

v0.3.1

Published

Pi extension for quickly switching between multiple accounts/API keys per provider.

Downloads

448

Readme

Pi Account Switcher

Switch between multiple API keys and accounts — per provider — inside Pi. No more manual env-var juggling.

claude/work  ·  claude/personal  ·  openai/team  ·  gemini/testing

Install

From GitHub (recommended)

pi install git:github.com/hieplp/pi-account-switcher

From npm

pi install npm:@hieplp/pi-account-switcher

Test without installing

pi -e git:github.com/hieplp/pi-account-switcher

Project-local install (writes to .pi/settings.json)

pi install -l git:github.com/hieplp/pi-account-switcher

Run from a local checkout

npm install
pi -e ./src/extension.ts

After installing, reload Pi and add your first account:

/reload
/accounts:add

Local development command prefix

If you have the npm package installed and also run a local checkout, set PI_ACCOUNT_SWITCHER_COMMAND_PREFIX before launching Pi to avoid command-name collisions:

PI_ACCOUNT_SWITCHER_COMMAND_PREFIX=dev pi -e ./src/extension.ts

The local commands will be registered as /dev:accounts:list, /dev:accounts:add, etc. The prefix may include the trailing colon (dev:) or omit it (dev).


Commands

Accounts

| Command | Description | | -------------------- | --------------------------------------------------------------- | | /accounts:add | Add a new account interactively | | /accounts:switch | Switch to any account (interactive picker or by ID) | | /accounts:peers | Switch to another account within the current provider | | /accounts:subagent | Set account for the next spawned subagent | | /accounts:edit | Edit label, provider, id, or credential source | | /accounts:remove | Delete an account | | /accounts:oauth | Import the current Pi /login OAuth session as a named account | | /accounts:dirs | Manage working directories for CWD-based auto-select |

Providers

| Command | Description | | ------------------- | -------------------------------- | | /providers:add | Add a reusable custom provider | | /providers:list | List custom providers | | /providers:edit | Edit a custom provider | | /providers:remove | Remove an unused custom provider |

Models

| Command | Description | | ---------------- | -------------------------------------------------------- | | /models:list | List all available models and switch to the selected one | | /models:add | Add a custom model config to the current provider | | /models:remove | Remove a custom model config |

System

| Command | Description | | ---------------- | -------------------------------------------------------- | | /system:reset | Delete all accounts, providers, and state | | /system:export | Export all accounts, providers, and state to a JSON file | | /system:import | Import accounts, providers, and state from a JSON file |


Adding Accounts

Run /accounts:add and the wizard will ask for:

  1. Provider — pick a built-in or custom provider
  2. Label — a friendly display name (e.g. Claude — Work)
  3. Account ID — a unique slug (e.g. claude-work)
  4. Credential env var — e.g. ANTHROPIC_API_KEY
  5. Secret source — one of:
    • Pasted API key (stored in plaintext — prefer the options below)
    • Existing environment variable
    • File path
    • Shell command
    • 1Password op:// reference

If the account ID already exists, Pi will ask whether to replace it, enter a new ID, or cancel.


OAuth Accounts (Claude, Codex, etc.)

For subscription providers, use Pi's built-in login first, then import it as a named account:

/login

Complete browser/device login, then:

/accounts:oauth

Give it a label like Claude — Work. Repeat for as many accounts as you need — each gets its own saved credentials. Switch between them any time with /accounts:switch.

OAuth credentials are read from ~/.pi/agent/auth.json and written back to Pi's live auth storage on switch.


Directory-based Auto-Select

The extension can automatically activate the right account based on your current working directory. Each account can list directory paths (dirs) — the longest prefix match wins. A defaultAccountId at the config level serves as the fallback. Use /accounts:dirs to manage directories interactively.

See USAGE.md for full details on the activation cascade, configuration, and examples.


Custom Providers

Define a provider once, reuse it across accounts:

/providers:add

Custom providers are stored at ~/.pi/account-switcher/providers.json and support all Pi model-provider fields:

{
  "providers": {
    "acme": {
      "name": "Acme AI",
      "baseUrl": "https://api.acme.test/v1",
      "api": "openai-completions",
      "apiKey": "ACME_API_KEY",
      "envKeys": ["ACME_API_KEY"],
      "aliases": ["acme-ai"],
      "models": [{ "id": "acme-coder", "name": "Acme Coder" }]
    }
  }
}

Removing a provider is blocked while any account uses it — edit or remove those accounts first.


Export / Import

Back up or migrate your full configuration with two commands:

/system:export          # prompts for a path, defaults to ~/pi-account-switcher-export.json
/system:export ~/backup.json  # export to a specific path

The export file contains all accounts, providers, and active-selection state as a single JSON bundle. To restore on another machine (or after a reset):

/system:import          # prompts for a path, defaults to ~/pi-account-switcher-export.json
/system:import ~/backup.json  # import from a specific path

Warning: import replaces all existing data. A confirmation prompt is shown before anything is written.


Config Reference

Accounts — ~/.pi/account-switcher/accounts.json

{
  "switchMode": "env",
  "defaultAccountId": "claude-work",
  "accounts": [
    {
      "id": "claude-work",
      "label": "Claude — Work",
      "provider": "anthropic",
      "dirs": ["/home/user/Development/Work"],
      "env": {
        "ANTHROPIC_API_KEY": { "type": "env", "name": "ANTHROPIC_WORK_API_KEY" }
      }
    },
    {
      "id": "openai-personal",
      "label": "OpenAI — Personal",
      "provider": "openai",
      "dirs": ["/home/user/Projects/Client-A"],
      "env": {
        "OPENAI_API_KEY": { "type": "file", "path": "~/.keys/openai-personal.txt" }
      }
    }
  ]
}

Secret Sources

{ "type": "literal", "value": "sk-..." }
{ "type": "env",     "name": "MY_API_KEY" }
{ "type": "file",    "path": "~/.keys/key.txt" }
{ "type": "command", "command": "op read op://AI/Claude/api-key" }
{ "type": "op",      "reference": "op://AI/Claude/api-key" }

A plain string is treated as a literal; strings starting with op:// are resolved via op read.

State — ~/.pi/account-switcher/state.json

Tracks the selected account and model per Pi session. Each Pi session gets its own key — no global active-account state.

{
  "sessions": {
    "abc123": { "activeAccountId": "claude-work" },
    "def456": { "activeAccountId": "openai-personal", "activeModelId": "gpt-4", "activeModelProvider": "openai" }
  }
}

When Pi starts, the extension derives a session key from Pi's session file and restores that session's saved state. Sessions with no saved state fall back to CWD-based auto-select or defaultAccountId.

Legacy flat-format state ({ "activeAccountId": "..." }) is automatically migrated to the session-keyed format on first load.

Session entries are automatically cleaned up: entries inactive for stateCleanupDays (default 30, configurable in accounts.json) are pruned, with a hard cap of 500 entries.


Credential Caching

On switch, the extension updates process.env, Pi's live API-key overrides, and Pi's OAuth auth storage. If a provider still uses old credentials, run /reload or restart Pi.


License

MIT — see LICENSE.