Public overview of how the oc-codex-multi-auth OpenCode plugin installs config, handles ChatGPT Plus/Pro OAuth, routes Codex/GPT-5 requests, rotates local account pools, exposes diagnostics, and publishes TUI quota status.
oc-codex-multi-auth is an OpenCode plugin for ChatGPT OAuth-backed Codex and GPT-5 workflows.
- The
oc-codex-multi-authnpm bin is an installer, not a replacement for OpenCode. - OpenCode loads
dist/index.jsas the provider plugin entry. - The plugin registers 21
codex-*tools for setup, account switching, health checks, diagnostics, backup, keychain, and recovery. - OpenCode loads
dist/tui.jsas the TUI plugin for active-session quota status. - Request handling stays stateless for the ChatGPT-backed Codex API by enforcing
store: falseand preservingreasoning.encrypted_content. - Account, config, backup, log, and TUI quota state lives under
~/.opencodeand~/.config/opencode. - Per-project account pools are enabled by default under
~/.opencode/projects/<project-key>/....
package.json publishes one command:
oc-codex-multi-auth->scripts/install-oc-codex-multi-auth.js
The installer updates OpenCode config, backs up previous files, normalizes stale plugin entries from older package names, enables the TUI status plugin, writes compact or full model templates, and clears OpenCode's cached package copy so the next OpenCode start uses the latest plugin.
index.ts is the runtime entry OpenCode loads. It owns:
- OAuth login modes: browser callback, device code, and manual URL paste
- account manager lifecycle and local account storage
- request URL/body/header transformation
- health-aware account selection and workspace-aware routing
- retry budgets, circuit breaking, rate-limit backoff, and failover
- session recovery hooks and beginner-safe next-action guidance
ToolContextconstruction for thecodex-*registry
OpenCode calls the plugin through the provider fetch path.
OpenCode prompt
|
v
OpenCode provider system
|
| custom fetch()
v
oc-codex-multi-auth index.ts
|- rewrite OpenAI SDK URL to Codex/ChatGPT backend
|- shape body for native or legacy transform mode
|- force stream:true, store:false, reasoning.encrypted_content
|- select/refresh a healthy account
|- attach OAuth headers
|- handle SSE, errors, retries, fallback, and metrics
v
ChatGPT-backed Codex endpoint
Native mode keeps the host payload shape whenever possible. Legacy mode applies compatibility rewrites for older OpenCode/AI SDK behavior, including filtering unsupported item_reference payloads and stripping IDs that cannot be used with store: false.
lib/tools/index.ts builds the OpenCode tool map from 21 per-file factories under lib/tools/.
Common groups:
- setup:
codex-setup,codex-help,codex-next - daily account use:
codex-list,codex-switch,codex-status,codex-limits - account metadata:
codex-label,codex-tag,codex-note,codex-remove,codex-refresh - diagnostics and resilience:
codex-health,codex-metrics,codex-doctor,codex-diag,codex-diff - backup and secrets:
codex-export,codex-import,codex-keychain - interactive surface:
codex-dashboard
tui.ts exposes an OpenCode TUI plugin that reads the active account, shared quota cache, and direct usage endpoints when available. It shows compact prompt status during sessions and provides a quota details command without polluting the home prompt.
The storage layer uses V3 account files with migrations from older formats, atomic writes, keychain opt-in, import/export previews, flagged-account recovery, and per-project path resolution.
| State | Default path |
|---|---|
| OpenCode config | ~/.config/opencode/opencode.json |
| OpenCode TUI config | ~/.config/opencode/tui.json |
| OpenCode auth tokens | ~/.opencode/auth/openai.json |
| Plugin config | ~/.opencode/openai-codex-auth-config.json |
| Global account pool | ~/.opencode/oc-codex-multi-auth-accounts.json |
| Project account pool | ~/.opencode/projects/<project-key>/oc-codex-multi-auth-accounts.json |
| Flagged accounts | ~/.opencode/oc-codex-multi-auth-flagged-accounts.json |
| Logs | ~/.opencode/logs/codex-plugin/ |
- OpenCode remains the host runtime and provider loader.
- The canonical package/plugin name is
oc-codex-multi-auth. - OAuth callback port remains
1455. - ChatGPT-backed Codex requests require
store: false. - Multi-turn continuity depends on
reasoning.encrypted_contentand the host-supplied conversation history. - Credentials and account metadata stay local unless the user exports or migrates them.
- Diagnostic commands redact sensitive account/token details.
- The optional keychain backend must fall back without deleting JSON credentials silently.