opencode-openai-sub-switcher
v1.0.7
Published
Multi-account OpenAI authentication plugin for OpenCode. Supports multiple ChatGPT Plus/Pro accounts with easy switching.
Downloads
585
Maintainers
Readme
opencode-openai-sub-switcher
OpenCode plugin for saving and switching between multiple OpenAI OAuth subscriptions that OpenCode already authenticated.
It does not replace OpenCode auth.
It snapshots the current openai auth entry from OpenCode, stores multiple saved variants locally, and restores one when you switch.
Install
npm install -g opencode-openai-sub-switcher
opencode-openai-sub-switcher-installThen fully restart OpenCode.
No plugin entry in opencode.json is required. The installer writes a local wrapper file into ~/.config/opencode/plugins/, and OpenCode auto-loads plugins from that directory.
Files installed
~/.config/opencode/plugins/opencode-openai-sub-switcher.ts~/.config/opencode/commands/switch-sub.md~/.config/opencode/commands/list-subs.md~/.config/opencode/commands/save-sub.md~/.config/opencode/commands/rename-sub.md~/.config/opencode/commands/remove-sub.md
Uninstall
opencode-openai-sub-switcher-uninstallQuick Start
- Log into OpenCode with OpenAI normally.
- Run
/save-subto save the current OpenAI snapshot. - Run
/switch-subto switch to another saved subscription. - Repeat
/save-subwhenever you want to keep a newly logged-in subscription.
Demo
Typical flow:
/save-sub
/connect
/save-sub
/list-subs
/switch-subExample result:
Saved accounts:
- d*****r@o*****k.com (team)
- d*****r@o*****k.com (plus)
- d*****[email protected] (team) *The * marks the currently active OpenAI snapshot.
Slash Commands
/switch-sub- switch to another saved OpenAI subscription/list-subs- list saved subscriptions/save-sub- save the current OpenCode OpenAI auth snapshot/rename-sub- rename a saved subscription/remove-sub- remove a saved subscription
These commands use the plugin tools under the hood and ask short follow-up questions when needed.
CLI
Save current account:
opencode-openai-sub-switcher addList saved accounts:
opencode-openai-sub-switcher listSwitch by saved id:
opencode-openai-sub-switcher switch <id>Rename or remove:
opencode-openai-sub-switcher rename <id> "Work"
opencode-openai-sub-switcher remove <id>OpenCode Tools
The plugin also exposes these tools inside OpenCode:
list_openai_accountssave_current_openai_accountswitch_openai_accountrename_openai_accountremove_openai_account
How It Works
- Snapshots are stored in
~/.opencode/multi-openai-accounts.jsonwith0600permissions. - Only the
openaisubtree is restored into~/.local/share/opencode/auth.json. - Other providers in
auth.jsonare preserved. - OpenCode continues to own login and token refresh.
- The plugin only stores, lists, renames, removes, and restores saved OpenAI snapshots.
- Listing, switching, and startup do not auto-save credentials. Saving is explicit via
/save-subor CLIadd.
Identity Model
Saved entries are deduplicated by accountId + sub.
That means:
- same OpenAI subscription and same identity updates the existing saved entry
- same OpenAI subscription but different identity can be saved as a separate entry
Privacy
- CLI and tool output is redacted by default.
- Raw auth snapshots stay local and unmodified so switching still works.
Disable redaction locally if you want full output:
export OPENCODE_OPENAI_SUB_SWITCHER_REDACT=falseSecurity Notes
- Removed automatic backup recovery for deleted snapshots, so removed entries are not retained in a
.bakfile. - Uninstall also removes the local snapshot registry files from
~/.opencode/. - Raw tokens are still stored locally, unencrypted, with
0600file permissions.
Accepted false values:
false0offno
Troubleshooting
If slash commands do not appear:
- Run
opencode-openai-sub-switcher-installagain. - Fully quit OpenCode.
- Reopen OpenCode.
If a new login does not create a new saved entry:
- it likely resolved to the same
accountId + subas an existing saved entry - logins only become separate saved entries when that identity key differs
License
MIT
