Local OpenCode plugin that rotates between multiple Codex OAuth accounts for Codex-capable models.
- Routes OpenCode
openai/*requests through a local account registry. - Supports ChatGPT/Codex OAuth logins only. No API-key mode.
- Supports easy
login,remove,enable,disable,default, andstrategyaccount management. - Injects common Codex and GPT-5 coding model entries into the OpenCode
openaiprovider config. - Adds a
fastmodel variant that maps toserviceTier: "priority"/*-fastmodel IDs. - Defaults OpenCode requests to
reasoningEffort: "low"when no provider default is already set.
The plugin refreshes ChatGPT/Codex OAuth tokens and forwards OpenCode's Responses API traffic to the ChatGPT Codex backend.
- index.js
- lib/accounts.js
- lib/openai-fetch.js
- lib/oauth.js
- scripts/accounts.mjs
- opencode.example.jsonc
- Add the plugin to your OpenCode config:
- Create or import the account registry:
node ./scripts/accounts.mjs init
node ./scripts/accounts.mjs import-legacy- Add accounts:
node ./scripts/accounts.mjs login personal
node ./scripts/accounts.mjs login work- Choose how selection works:
node ./scripts/accounts.mjs strategy round-robin
node ./scripts/accounts.mjs default personal- Start OpenCode and pick models from the
openaiprovider, for example:
openai/gpt-5-codexopenai/gpt-5.1-codexopenai/gpt-5.1-codex-miniopenai/gpt-5.1-codex-maxopenai/gpt-5.2-codexopenai/gpt-5.4openai/gpt-5.4/fast
The default registry path is ~/.config/opencode/codex-accounts.json.
{
"version": 2,
"selection": {
"strategy": "round-robin",
"defaultAccountId": "personal"
},
"accounts": [
{
"id": "personal",
"label": "Personal",
"type": "oauth",
"accessToken": "...",
"refreshToken": "...",
"idToken": "...",
"accountId": "...",
"email": "you@example.com",
"expiresAt": 1777590611000,
"lastRefresh": "2026-04-20T23:10:10.889Z",
"enabled": true,
"includeModels": [],
"excludeModels": []
}
]
}node ./scripts/accounts.mjs list
node ./scripts/accounts.mjs login personal
node ./scripts/accounts.mjs import-legacy
node ./scripts/accounts.mjs remove work
node ./scripts/accounts.mjs disable personal
node ./scripts/accounts.mjs enable personal
node ./scripts/accounts.mjs default workRun those commands from the repository root, or replace ./scripts/accounts.mjs with the absolute path to the script.
OPENCODE_CODEX_ACCOUNTS_FILEoverrides the registry path.OPENCODE_CODEX_ACCOUNTforces a specific configured account for the current process.OPENCODE_CODEX_DEBUG=1enables plugin debug logging.OPENCODE_CODEX_REASONING_EFFORToverrides the default reasoning effort used when OpenCode does not set one.
- OAuth accounts are sent to
https://chatgpt.com/backend-api/codex/responseswith account-specific OAuth headers. - Unsupported non-OAuth entries are ignored if they appear in imported legacy registries.
- The
fastvariant maps request intent toserviceTier: "priority". On ChatGPT-backed Codex OAuth accounts, the backend currently reportsservice_tier: "auto"in responses even when the fast variant is requested.
{ "$schema": "https://opencode.ai/config.json", "plugin": [ [ "file:///absolute/path/to/opencode-codex", { "accountsPath": "~/.config/opencode/codex-accounts.json", "fastVariantName": "fast", "reasoningEffort": "low" } ] ] }