oc-chatgpt-multi-auth 5.4.3 → 5.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,939 +1,148 @@
1
- # OpenAI Codex Auth Plugin for OpenCode
1
+ # oc-chatgpt-multi-auth
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/oc-chatgpt-multi-auth.svg)](https://www.npmjs.com/package/oc-chatgpt-multi-auth)
4
4
  [![npm downloads](https://img.shields.io/npm/dw/oc-chatgpt-multi-auth.svg)](https://www.npmjs.com/package/oc-chatgpt-multi-auth)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
6
 
6
- OAuth plugin for OpenCode that lets you use ChatGPT Plus/Pro rate limits with models like `gpt-5.4`, `gpt-5-codex`, and `gpt-5.1-codex-max` (plus optional/manual `gpt-5.4-pro`, entitlement-gated Spark IDs, and legacy Codex aliases).
7
+ Use your ChatGPT Plus/Pro subscription inside OpenCode with OAuth login, GPT-5/Codex model presets, and multi-account failover.
7
8
 
8
- > [!NOTE]
9
- > **Renamed from `opencode-openai-codex-auth-multi`** — If you were using the old package, update your config to use `oc-chatgpt-multi-auth` instead. The rename was necessary because OpenCode blocks plugins containing `opencode-openai-codex-auth` in the name.
9
+ `oc-chatgpt-multi-auth` is an OpenCode plugin for developers who want ChatGPT-backed GPT-5 and Codex workflows in OpenCode without switching to separate Platform API credentials for personal use. It uses the same official OAuth flow as the Codex CLI, adds model templates for current GPT-5 families, and can rotate across multiple ChatGPT accounts when one account is rate-limited or unavailable.
10
10
 
11
- ## What You Get
11
+ ## What This Project Does
12
12
 
13
- - **GPT-5.4, GPT-5 Codex, GPT-5.1 Codex Max** and all GPT-5.x variants via ChatGPT OAuth
14
- - **Multi-account support** Add up to 20 ChatGPT accounts, health-aware rotation with automatic failover
15
- - **Per-project accounts** Each project gets its own account storage (new in v4.10.0)
16
- - **Workspace-aware identity persistence** Keeps workspace/org identity stable across token refresh and verify-flagged restore flows
17
- - **Click-to-switch** — Switch accounts directly from the OpenCode TUI
18
- - **Beginner command toolkit** — Guided onboarding with `codex-help`, `codex-setup`, `codex-doctor`, and `codex-next`
19
- - **Account metadata controls** — Per-account labels, tags, and notes with quick filtering
20
- - **Safer backup/import flow** — Timestamped exports, import dry-run preview, and conditional pre-import backups when existing accounts are present
21
- - **Startup preflight summary** — One-line health/readiness summary at plugin startup with suggested next step
22
- - **Strict tool validation** — Automatically cleans schemas for compatibility with strict models
23
- - **Auto-update notifications** — Get notified when a new version is available
24
- - **21 template model presets** — Full variant system with reasoning levels (none/low/medium/high/xhigh)
25
- - **Prompt caching** — Session-based caching for faster multi-turn conversations
26
- - **Usage-aware errors** — Friendly messages with rate limit reset timing
27
- - **Plugin compatible** — Works alongside other OpenCode plugins (oh-my-opencode, dcp, etc.)
13
+ - Adds an OpenCode plugin that authenticates with ChatGPT Plus/Pro through official OAuth
14
+ - Ships ready-to-use model templates for `gpt-5.4`, `gpt-5-codex`, and related GPT-5 families
15
+ - Routes requests through a stateless Codex-compatible request pipeline with automatic token refresh
16
+ - Supports multi-account rotation, per-project account storage, and guided onboarding commands
28
17
 
29
- ---
30
-
31
- <details open>
32
- <summary><b>Terms of Service Warning — Read Before Installing</b></summary>
33
-
34
- > [!CAUTION]
35
- > This plugin uses OpenAI's official OAuth authentication (the same method as OpenAI's official Codex CLI) for personal development use with your ChatGPT Plus/Pro subscription.
36
- >
37
- > **This plugin is for personal development only:**
38
- > - Not for commercial services, API resale, or multi-user applications
39
- > - For production use, see [OpenAI Platform API](https://platform.openai.com/)
40
- >
41
- > **By using this plugin, you acknowledge:**
42
- > - This is an unofficial tool not endorsed by OpenAI
43
- > - Users are responsible for compliance with [OpenAI's Terms of Use](https://openai.com/policies/terms-of-use/)
44
- > - You assume all risks associated with using this plugin
45
-
46
- </details>
47
-
48
- ---
49
-
50
- ## Installation
51
-
52
- <details open>
53
- <summary><b>For Humans</b></summary>
54
-
55
- **Option A: Let an LLM do it**
56
-
57
- Paste this into any LLM agent (Claude Code, OpenCode, Cursor, etc.):
58
-
59
- ```
60
- Install the oc-chatgpt-multi-auth plugin and add the OpenAI model definitions to ~/.config/opencode/opencode.json by following: https://raw.githubusercontent.com/ndycode/oc-chatgpt-multi-auth/main/README.md
61
- ```
62
-
63
- **Option B: One-command install**
18
+ ## Quick Start
64
19
 
65
20
  ```bash
21
+ # 1. Install or refresh the plugin config
66
22
  npx -y oc-chatgpt-multi-auth@latest
67
- ```
68
-
69
- This writes the config to `~/.config/opencode/opencode.json`, backs up existing config, and clears the plugin cache.
70
-
71
- > Want legacy config (OpenCode v1.0.209 and below)? Add `--legacy` flag.
72
-
73
- **Option C: Manual setup**
74
-
75
- 1. **Add the plugin** to `~/.config/opencode/opencode.json`:
76
-
77
- ```json
78
- {
79
- "plugin": ["oc-chatgpt-multi-auth@latest"]
80
- }
81
- ```
82
-
83
- 2. **Login** with your ChatGPT account:
84
-
85
- ```bash
86
- opencode auth login
87
- ```
88
-
89
- 3. **Add models** — Copy the [full configuration](#models) below
90
-
91
- 4. **Use it:**
92
23
 
93
- ```bash
94
- opencode run "Hello" --model=openai/gpt-5.4 --variant=medium
95
- ```
24
+ # 2. Sign in with ChatGPT Plus/Pro
25
+ opencode auth login
96
26
 
97
- </details>
98
-
99
- <details>
100
- <summary><b>For LLM Agents</b></summary>
101
-
102
- ### Step-by-Step Instructions
103
-
104
- 1. Edit the OpenCode configuration file at `~/.config/opencode/opencode.json`
105
-
106
- > **Note**: This path works on all platforms. On Windows, `~` resolves to your user home directory (e.g., `C:\Users\YourName`).
107
-
108
- 2. Add the plugin to the `plugin` array:
109
- ```json
110
- {
111
- "plugin": ["oc-chatgpt-multi-auth@latest"]
112
- }
113
- ```
114
-
115
- 3. Add the model definitions from the [Full Models Configuration](#full-models-configuration-copy-paste-ready) section
116
-
117
- 4. Set `provider` to `"openai"` and choose a model
118
-
119
- ### Verification
120
-
121
- ```bash
122
- opencode run "Hello" --model=openai/gpt-5.4 --variant=medium
27
+ # 3. Run a prompt in OpenCode
28
+ opencode run "Explain this repository" --model=openai/gpt-5.4 --variant=medium
123
29
  ```
124
30
 
125
- </details>
126
-
127
- ---
128
-
129
- ## Models
130
-
131
- ### Model Reference
132
-
133
- | Model | Variants | Notes |
134
- |-------|----------|-------|
135
- | `gpt-5.4` | none, low, medium, high, xhigh | Latest GPT-5.4 with reasoning levels and 1,000,000 context window |
136
- | `gpt-5.4-pro` | low, medium, high, xhigh | Optional manual model for deeper reasoning; when `unsupportedCodexPolicy=fallback`, fallback includes `gpt-5.4-pro -> gpt-5.4` (also 1,000,000 context window) |
137
- | `gpt-5-codex` | low, medium, high | Canonical Codex model for code generation (default: high) |
138
- | `gpt-5.3-codex-spark` | low, medium, high, xhigh | Spark IDs are supported by the plugin, but access is entitlement-gated by account/workspace |
139
- | `gpt-5.1-codex-max` | low, medium, high, xhigh | Maximum context Codex |
140
- | `gpt-5.1-codex` | low, medium, high | Standard Codex |
141
- | `gpt-5.1-codex-mini` | medium, high | Lightweight Codex |
142
- | `gpt-5.1` | none, low, medium, high | GPT-5.1 base model |
31
+ What the installer does:
143
32
 
144
- Config templates intentionally omit Spark model IDs by default to reduce entitlement failures on unsupported accounts. Add Spark manually only if your workspace is entitled.
33
+ - writes `~/.config/opencode/opencode.json`
34
+ - backs up an existing config before changing it
35
+ - clears the cached plugin copy so OpenCode reinstalls the latest package
145
36
 
146
- Legacy and snapshot aliases supported by the plugin:
147
- - `gpt-5`, `gpt-5-mini`, `gpt-5-nano` normalize to `gpt-5.4`
148
- - `gpt-5.4-2026-03-05` and `gpt-5.4-pro-2026-03-05` (including effort suffix variants) normalize to their stable families
37
+ ## Example Usage
149
38
 
150
- If your OpenCode runtime supports global auto-compaction settings, set:
151
- - `model_context_window = 1000000`
152
- - `model_auto_compact_token_limit = 900000`
153
-
154
- **Using variants:**
155
39
  ```bash
156
- # Modern OpenCode (v1.0.210+)
157
- opencode run "Hello" --model=openai/gpt-5.4 --variant=high
158
-
159
- # Legacy OpenCode (v1.0.209 and below)
160
- opencode run "Hello" --model=openai/gpt-5.4-high
161
- ```
40
+ # General GPT-5 workflow
41
+ opencode run "Summarize the failing test and suggest a fix" --model=openai/gpt-5.4 --variant=medium
162
42
 
163
- <details>
164
- <summary><b>Full Models Configuration (Copy-Paste Ready)</b></summary>
165
-
166
- Add this to your `~/.config/opencode/opencode.json`:
167
-
168
- ```json
169
- {
170
- "$schema": "https://opencode.ai/config.json",
171
- "plugin": ["oc-chatgpt-multi-auth@latest"],
172
- "provider": {
173
- "openai": {
174
- "options": {
175
- "reasoningEffort": "medium",
176
- "reasoningSummary": "auto",
177
- "textVerbosity": "medium",
178
- "include": ["reasoning.encrypted_content"],
179
- "store": false
180
- },
181
- "models": {
182
- "gpt-5.4": {
183
- "name": "GPT 5.4 (OAuth)",
184
- "limit": { "context": 1000000, "output": 128000 },
185
- "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
186
- "variants": {
187
- "none": { "reasoningEffort": "none" },
188
- "low": { "reasoningEffort": "low" },
189
- "medium": { "reasoningEffort": "medium" },
190
- "high": { "reasoningEffort": "high" },
191
- "xhigh": { "reasoningEffort": "xhigh" }
192
- }
193
- },
194
- "gpt-5-codex": {
195
- "name": "GPT 5 Codex (OAuth)",
196
- "limit": { "context": 272000, "output": 128000 },
197
- "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
198
- "variants": {
199
- "low": { "reasoningEffort": "low" },
200
- "medium": { "reasoningEffort": "medium" },
201
- "high": { "reasoningEffort": "high" }
202
- },
203
- "options": {
204
- "reasoningEffort": "high",
205
- "reasoningSummary": "detailed"
206
- }
207
- },
208
- "gpt-5.1-codex-max": {
209
- "name": "GPT 5.1 Codex Max (OAuth)",
210
- "limit": { "context": 272000, "output": 128000 },
211
- "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
212
- "variants": {
213
- "low": { "reasoningEffort": "low" },
214
- "medium": { "reasoningEffort": "medium" },
215
- "high": { "reasoningEffort": "high" },
216
- "xhigh": { "reasoningEffort": "xhigh" }
217
- }
218
- },
219
- "gpt-5.1-codex": {
220
- "name": "GPT 5.1 Codex (OAuth)",
221
- "limit": { "context": 272000, "output": 128000 },
222
- "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
223
- "variants": {
224
- "low": { "reasoningEffort": "low" },
225
- "medium": { "reasoningEffort": "medium" },
226
- "high": { "reasoningEffort": "high" }
227
- }
228
- },
229
- "gpt-5.1-codex-mini": {
230
- "name": "GPT 5.1 Codex Mini (OAuth)",
231
- "limit": { "context": 272000, "output": 128000 },
232
- "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
233
- "variants": {
234
- "medium": { "reasoningEffort": "medium" },
235
- "high": { "reasoningEffort": "high" }
236
- }
237
- },
238
- "gpt-5.1": {
239
- "name": "GPT 5.1 (OAuth)",
240
- "limit": { "context": 272000, "output": 128000 },
241
- "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
242
- "variants": {
243
- "none": { "reasoningEffort": "none" },
244
- "low": { "reasoningEffort": "low" },
245
- "medium": { "reasoningEffort": "medium" },
246
- "high": { "reasoningEffort": "high" }
247
- }
248
- }
249
- }
250
- }
251
- }
252
- }
43
+ # Codex-focused workflow
44
+ opencode run "Refactor the retry logic and update the tests" --model=openai/gpt-5-codex --variant=high
253
45
  ```
254
46
 
255
- Optional Spark model block (manual add only when entitled):
256
- ```json
257
- "gpt-5.3-codex-spark": {
258
- "name": "GPT 5.3 Codex Spark (OAuth)",
259
- "limit": { "context": 272000, "output": 128000 },
260
- "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] },
261
- "variants": {
262
- "low": { "reasoningEffort": "low" },
263
- "medium": { "reasoningEffort": "medium" },
264
- "high": { "reasoningEffort": "high" },
265
- "xhigh": { "reasoningEffort": "xhigh" }
266
- }
267
- }
268
- ```
269
-
270
- For legacy OpenCode (v1.0.209 and below), use `config/opencode-legacy.json` which has individual model entries like `gpt-5.4-low`, `gpt-5.4-medium`, etc.
271
-
272
- </details>
273
-
274
- ---
275
-
276
- ## Multi-Account Setup
277
-
278
- Add multiple ChatGPT accounts for higher combined quotas. The plugin uses **health-aware rotation** with automatic failover and supports up to 20 accounts.
279
-
280
- ```bash
281
- opencode auth login # Run again to add more accounts
282
- ```
47
+ ## Usage Notice
283
48
 
284
- ---
285
-
286
- ## Account Management Tools
287
-
288
- The plugin provides built-in tools for managing your OpenAI accounts. These are available directly in OpenCode just ask the agent or type the tool name.
289
-
290
- > **Note:** Tools were renamed from `openai-accounts-*` to `codex-*` in v4.12.0 for brevity.
291
-
292
- ### codex-list
293
-
294
- List all configured accounts with status badges.
295
-
296
- ```text
297
- codex-list
298
- ```
299
-
300
- Filter by tag:
301
-
302
- ```text
303
- codex-list tag="work"
304
- ```
305
-
306
- Shows account labels, IDs, tags, active state, and rate-limit/cooldown markers.
307
-
308
- ---
309
-
310
- ### codex-switch
311
-
312
- Switch to a different account. If `index` is omitted and your terminal supports menus, an interactive picker opens.
313
-
314
- ```text
315
- codex-switch index=2
316
- ```
317
-
318
- or:
319
-
320
- ```text
321
- codex-switch
322
- ```
323
-
324
- ---
325
-
326
- ### codex-label
327
-
328
- Set or clear a display label for an account. Useful for workspace naming.
329
-
330
- ```text
331
- codex-label index=2 label="Work"
332
- ```
333
-
334
- Clear:
335
-
336
- ```text
337
- codex-label index=2 label=""
338
- ```
339
-
340
- If `index` is omitted in interactive terminals, a picker opens.
341
-
342
- ---
343
-
344
- ### codex-tag
345
-
346
- Set or clear comma-separated tags for filtering and grouping.
347
-
348
- ```text
349
- codex-tag index=2 tags="work,team-a"
350
- ```
351
-
352
- Clear:
353
-
354
- ```text
355
- codex-tag index=2 tags=""
356
- ```
357
-
358
- Use tags with `codex-list tag="work"`.
359
-
360
- ---
361
-
362
- ### codex-note
363
-
364
- Set or clear a short per-account note for reminders.
365
-
366
- ```text
367
- codex-note index=2 note="primary for weekday daytime usage"
368
- ```
369
-
370
- Clear:
371
-
372
- ```text
373
- codex-note index=2 note=""
374
- ```
375
-
376
- ---
377
-
378
- ### codex-help
379
-
380
- Show beginner-friendly command guidance. Optional topic filter:
381
-
382
- ```text
383
- codex-help
384
- codex-help topic="backup"
385
- ```
386
-
387
- Available topics: `setup`, `switch`, `health`, `backup`, `dashboard`, `metrics`.
388
-
389
- ---
390
-
391
- ### codex-setup
392
-
393
- Show readiness checklist for first-run onboarding and account health.
394
-
395
- ```text
396
- codex-setup
397
- ```
398
-
399
- Open guided wizard (menu-driven when terminal supports it, checklist fallback otherwise):
400
-
401
- ```text
402
- codex-setup wizard=true
403
- ```
404
-
405
- ---
406
-
407
- ### codex-doctor
408
-
409
- Run diagnostics with actionable findings.
410
-
411
- ```text
412
- codex-doctor
413
- codex-doctor deep=true
414
- ```
415
-
416
- Apply safe auto-fixes (`--fix` equivalent):
417
- - Refreshes tokens where possible
418
- - Persists refreshed credentials
419
- - Switches active account to the healthiest eligible account
420
-
421
- ```text
422
- codex-doctor fix=true
423
- ```
424
-
425
- ---
426
-
427
- ### codex-next
428
-
429
- Show the single most recommended next action based on current account/runtime state.
430
-
431
- ```text
432
- codex-next
433
- ```
434
-
435
- ---
436
-
437
- ### codex-status
438
-
439
- Show detailed status including rate limits and health scores.
440
-
441
- ```text
442
- codex-status
443
- ```
444
-
445
- ---
446
-
447
- ### codex-metrics
448
-
449
- Show live runtime metrics (request counts, latency, errors, retries, and safe mode).
450
-
451
- ```text
452
- codex-metrics
453
- ```
454
-
455
- ---
456
-
457
- ### codex-health
458
-
459
- Check if all account tokens are still valid (read-only check).
460
-
461
- ```text
462
- codex-health
463
- ```
464
-
465
- ---
466
-
467
- ### codex-refresh
468
-
469
- Refresh all OAuth tokens and save them to disk. Use this after long idle periods.
470
-
471
- ```text
472
- codex-refresh
473
- ```
474
-
475
- `codex-health` validates. `codex-refresh` validates + refreshes + persists.
476
-
477
- ---
478
-
479
- ### codex-remove
480
-
481
- Remove an account entry. If `index` is omitted and your terminal supports menus, an interactive picker opens.
482
-
483
- ```text
484
- codex-remove index=3
485
- ```
486
-
487
- or:
488
-
489
- ```text
490
- codex-remove
491
- ```
492
-
493
- ---
494
-
495
- ### codex-export
496
-
497
- Export accounts to JSON for backup/migration.
498
-
499
- Explicit path:
500
-
501
- ```text
502
- codex-export path="~/backup/accounts.json"
503
- ```
504
-
505
- Auto timestamped backup path (default behavior when `path` is omitted):
506
-
507
- ```text
508
- codex-export
509
- ```
510
-
511
- Generated paths are stored in a `backups/` subdirectory near the active account storage file.
512
-
513
- ---
514
-
515
- ### codex-import
516
-
517
- Import accounts from a JSON file (dedupe-aware merge).
518
-
519
- Dry-run preview (no writes):
520
-
521
- ```text
522
- codex-import path="~/backup/accounts.json" dryRun=true
523
- ```
524
-
525
- Apply import:
526
-
527
- ```text
528
- codex-import path="~/backup/accounts.json"
529
- ```
49
+ > [!CAUTION]
50
+ > This project is for personal development use with your own ChatGPT Plus/Pro subscription.
51
+ >
52
+ > - It is not intended for commercial resale, shared multi-user access, or production services.
53
+ > - It uses official OAuth authentication, but it is an independent open-source project and is not affiliated with OpenAI.
54
+ > - For production applications, use the [OpenAI Platform API](https://platform.openai.com/).
55
+ > - You are responsible for complying with [OpenAI's Terms of Use](https://openai.com/policies/terms-of-use/).
530
56
 
531
- Before apply, the plugin creates an automatic timestamped pre-import backup when existing accounts are present. If backup creation fails, import apply is aborted.
57
+ ## Why This Exists
532
58
 
533
- ---
59
+ OpenCode users often want the same GPT-5 and Codex model experience they use in ChatGPT, but inside a local terminal workflow. This plugin exists to bridge that gap cleanly:
534
60
 
535
- ### codex-dashboard
61
+ - official OAuth instead of scraped cookies or unofficial auth flows
62
+ - OpenCode-ready model definitions instead of hand-rolled config every time
63
+ - account rotation and recovery features for people who work across multiple ChatGPT accounts or workspaces
536
64
 
537
- Show live account eligibility, retry budget usage, refresh queue metrics, and the recommended next step.
65
+ ## Features
538
66
 
539
- ```text
540
- codex-dashboard
541
- ```
67
+ - Official OAuth login flow compatible with ChatGPT Plus/Pro access
68
+ - GPT-5 and Codex model templates for modern and legacy OpenCode versions
69
+ - Multi-account rotation with health-aware failover
70
+ - Per-project account storage support
71
+ - Beginner-focused commands such as `codex-setup`, `codex-help`, `codex-doctor`, and `codex-next`
72
+ - Interactive account switching, labeling, tagging, and backup/import commands
73
+ - Stateless request handling with `reasoning.encrypted_content` for multi-turn sessions
74
+ - Request logging and troubleshooting hooks for debugging OpenCode integration issues
542
75
 
543
- ---
544
-
545
- ### Quick Reference
546
-
547
- | Tool | What It Does | Example |
548
- |------|--------------|---------|
549
- | `codex-help` | Command guide by topic | `codex-help topic="setup"` |
550
- | `codex-setup` | Readiness checklist/wizard | `codex-setup wizard=true` |
551
- | `codex-next` | Best next action | `codex-next` |
552
- | `codex-doctor` | Diagnostics and optional safe fixes | `codex-doctor fix=true` |
553
- | `codex-list` | List/filter accounts | `codex-list tag="work"` |
554
- | `codex-switch` | Switch active account | `codex-switch index=2` |
555
- | `codex-label` | Set/clear display label | `codex-label index=2 label="Work"` |
556
- | `codex-tag` | Set/clear tag list | `codex-tag index=2 tags="work,team-a"` |
557
- | `codex-note` | Set/clear account note | `codex-note index=2 note="night backup"` |
558
- | `codex-status` | Per-account health/rate limit detail | `codex-status` |
559
- | `codex-dashboard` | Live selection and retry view | `codex-dashboard` |
560
- | `codex-metrics` | Runtime metrics summary | `codex-metrics` |
561
- | `codex-health` | Validate token health (read-only) | `codex-health` |
562
- | `codex-refresh` | Refresh and persist tokens | `codex-refresh` |
563
- | `codex-remove` | Remove account entry | `codex-remove index=3` |
564
- | `codex-export` | Export account backups | `codex-export` |
565
- | `codex-import` | Dry-run or apply imports | `codex-import path="~/backup/accounts.json" dryRun=true` |
566
-
567
- ---
568
-
569
- ### Sample Output (codex-list)
570
-
571
- ```text
572
- Codex Accounts (3):
573
-
574
- [1] Account 1 (user@gmail.com, workspace:Work, tags:work,team-a) active
575
- [2] Account 2 (backup@email.com, tags:backup) ok
576
- [3] Account 3 (personal@email.com) rate-limited
577
-
578
- Storage: ~/.opencode/openai-codex-accounts.json
579
- ```
76
+ ## Common Workflows
580
77
 
581
- ## Rotation Behavior
78
+ - Personal coding sessions in OpenCode using `gpt-5.4` or `gpt-5-codex`
79
+ - Switching between personal and workspace-linked ChatGPT accounts
80
+ - Keeping separate account pools per project or monorepo
81
+ - Recovering from unsupported-model, auth, or rate-limit issues with guided commands
582
82
 
583
- **How rotation works:**
584
- - Health scoring tracks success/failure per account
585
- - Token bucket prevents hitting rate limits
586
- - Hybrid selection prefers healthy accounts with available tokens
587
- - Always retries when all accounts are rate-limited (waits for reset with live countdown)
588
- - 20% jitter on retry delays to avoid thundering herd
589
- - Auto-removes accounts after 3 consecutive auth failures (new in v4.11.0)
83
+ ## How It Works
590
84
 
591
- **Per-project accounts (v4.10.0+):**
85
+ The plugin sits between OpenCode and the ChatGPT-backed Codex workflow:
592
86
 
593
- By default, each project gets its own account storage namespace. This means you can keep different active accounts per project without writing account files into your repo. Works from subdirectories too; the plugin walks up to find the project root (v4.11.0). Disable with `perProjectAccounts: false` in your config.
87
+ 1. OpenCode loads the plugin and sends model requests through the plugin fetch pipeline.
88
+ 2. The plugin authenticates with ChatGPT OAuth and refreshes tokens when needed.
89
+ 3. Requests are normalized for the Codex backend and sent with `store: false`.
90
+ 4. The plugin chooses the best account/workspace candidate, retries intelligently, and preserves conversation continuity through encrypted reasoning state.
594
91
 
595
- **Storage locations:**
596
- - Per-project: `~/.opencode/projects/{project-key}/openai-codex-accounts.json`
597
- - Global (when per-project disabled): `~/.opencode/openai-codex-accounts.json`
92
+ See [Architecture](docs/development/ARCHITECTURE.md) for implementation details.
598
93
 
599
- ---
94
+ ## Installation
600
95
 
601
- ## Troubleshooting
96
+ Use the quick-start path above for the fastest setup. For full setup, local development installs, legacy OpenCode support, and verification steps, see [Getting Started](docs/getting-started.md).
602
97
 
603
- > **Quick reset**: Most issues can be resolved by deleting `~/.opencode/auth/openai.json` and running `opencode auth login` again.
98
+ If you are on OpenCode `v1.0.209` or earlier, use:
604
99
 
605
- ### Configuration Paths (All Platforms)
606
-
607
- OpenCode uses `~/.config/opencode/` on **all platforms** including Windows.
608
-
609
- | File | Path |
610
- |------|------|
611
- | Main config | `~/.config/opencode/opencode.json` |
612
- | Auth tokens | `~/.opencode/auth/openai.json` |
613
- | Multi-account (global) | `~/.opencode/openai-codex-accounts.json` |
614
- | Multi-account (per-project) | `~/.opencode/projects/{project-key}/openai-codex-accounts.json` |
615
- | Flagged accounts | `~/.opencode/openai-codex-flagged-accounts.json` |
616
- | Plugin config | `~/.opencode/openai-codex-auth-config.json` |
617
- | Debug logs | `~/.opencode/logs/codex-plugin/` |
618
-
619
- > **Windows users**: `~` resolves to your user home directory (e.g., `C:\Users\YourName`).
620
-
621
- ---
622
-
623
- <details>
624
- <summary><b>401 Unauthorized Error</b></summary>
625
-
626
- **Cause:** Token expired or not authenticated.
627
-
628
- **Solutions:**
629
- 1. Re-authenticate:
630
- ```bash
631
- opencode auth login
632
- ```
633
- 2. Check auth file exists:
634
- ```bash
635
- cat ~/.opencode/auth/openai.json
636
- ```
637
-
638
- </details>
639
-
640
- <details>
641
- <summary><b>Browser Doesn't Open for OAuth</b></summary>
642
-
643
- **Cause:** Port 1455 conflict or SSH/WSL environment.
644
-
645
- **Solutions:**
646
- 1. **Manual URL paste:**
647
- - Re-run `opencode auth login`
648
- - Select **"ChatGPT Plus/Pro (manual URL paste)"**
649
- - Paste the full redirect URL (including `#code=...`) after login
650
-
651
- 2. **Check port availability:**
652
- ```bash
653
- # macOS/Linux
654
- lsof -i :1455
655
-
656
- # Windows
657
- netstat -ano | findstr :1455
658
- ```
659
-
660
- 3. **Stop Codex CLI if running** — Both use port 1455
661
-
662
- </details>
663
-
664
- <details>
665
- <summary><b>Model Not Found</b></summary>
666
-
667
- **Cause:** Missing provider prefix or config mismatch.
668
-
669
- **Solutions:**
670
- 1. Use `openai/` prefix:
671
- ```bash
672
- # Correct
673
- --model=openai/gpt-5.4
674
-
675
- # Wrong
676
- --model=gpt-5.4
677
- ```
678
-
679
- 2. Verify model is in your config:
680
- ```json
681
- { "models": { "gpt-5.4": { ... } } }
682
- ```
683
-
684
- </details>
685
-
686
- <details>
687
- <summary><b>Unsupported Codex Model for ChatGPT Account</b></summary>
688
-
689
- **Error example:** `Bad Request: {"detail":"The 'gpt-5.3-codex-spark' model is not supported when using Codex with a ChatGPT account."}`
690
-
691
- **Cause:** Active workspace/account is not entitled for the requested Codex model.
692
-
693
- **Solutions:**
694
- 1. Re-auth to refresh workspace selection (most common Spark fix):
695
- ```bash
696
- opencode auth login
697
- ```
698
- 2. Add another entitled account/workspace. The plugin will try remaining accounts/workspaces before model fallback.
699
- 3. Enable automatic fallback only if you want degraded-model retries when Spark is not entitled:
700
- ```bash
701
- CODEX_AUTH_UNSUPPORTED_MODEL_POLICY=fallback opencode
702
- ```
703
- 4. Use custom fallback chain in `~/.opencode/openai-codex-auth-config.json`:
704
- ```json
705
- {
706
- "unsupportedCodexPolicy": "fallback",
707
- "fallbackOnUnsupportedCodexModel": true,
708
- "unsupportedCodexFallbackChain": {
709
- "gpt-5.4-pro": ["gpt-5.4"],
710
- "gpt-5-codex": ["gpt-5.2-codex"],
711
- "gpt-5.3-codex": ["gpt-5-codex", "gpt-5.2-codex"],
712
- "gpt-5.3-codex-spark": ["gpt-5-codex", "gpt-5.3-codex", "gpt-5.2-codex"]
713
- }
714
- }
715
- ```
716
- 5. Verify effective upstream model when needed:
717
- ```bash
718
- ENABLE_PLUGIN_REQUEST_LOGGING=1 CODEX_PLUGIN_LOG_BODIES=1 opencode run "ping" --model=openai/gpt-5.3-codex-spark
719
- ```
720
- The UI can keep showing your selected model while fallback is applied internally.
721
-
722
- </details>
723
-
724
- <details>
725
- <summary><b>Rate Limit Exceeded</b></summary>
726
-
727
- **Cause:** ChatGPT subscription usage limit reached.
728
-
729
- **Solutions:**
730
- 1. Wait for reset (plugin shows timing in error message)
731
- 2. Add more accounts: `opencode auth login`
732
- 3. Switch to a different model family
733
-
734
- </details>
735
-
736
- <details>
737
- <summary><b>Multi-Turn Context Lost</b></summary>
738
-
739
- **Cause:** Old plugin version or missing config.
740
-
741
- **Solutions:**
742
- 1. Update plugin:
743
- ```bash
744
- npx -y oc-chatgpt-multi-auth@latest
745
- ```
746
- 2. Ensure config has:
747
- ```json
748
- {
749
- "include": ["reasoning.encrypted_content"],
750
- "store": false
751
- }
752
- ```
753
-
754
- </details>
755
-
756
- <details>
757
- <summary><b>OAuth Callback Issues (Safari/WSL/Docker)</b></summary>
758
-
759
- **Safari HTTPS-only mode:**
760
- - Use Chrome or Firefox instead, or
761
- - Temporarily disable Safari > Settings > Privacy > "Enable HTTPS-only mode"
762
-
763
- **WSL2:**
764
- - Use VS Code's port forwarding, or
765
- - Configure Windows → WSL port forwarding
766
-
767
- **SSH / Remote:**
768
100
  ```bash
769
- ssh -L 1455:localhost:1455 user@remote
770
- ```
771
-
772
- **Docker / Containers:**
773
- - OAuth with localhost redirect doesn't work in containers
774
- - Use SSH port forwarding or manual URL flow
775
-
776
- </details>
777
-
778
- ---
779
-
780
- ## Plugin Compatibility
781
-
782
- ### oh-my-opencode
783
-
784
- Works alongside oh-my-opencode. No special configuration needed.
785
-
786
- ```json
787
- {
788
- "plugin": [
789
- "oc-chatgpt-multi-auth@latest",
790
- "oh-my-opencode@latest"
791
- ]
792
- }
793
- ```
794
-
795
- ### @tarquinen/opencode-dcp
796
-
797
- List this plugin before dcp:
798
-
799
- ```json
800
- {
801
- "plugin": [
802
- "oc-chatgpt-multi-auth@latest",
803
- "@tarquinen/opencode-dcp@latest"
804
- ]
805
- }
101
+ npx -y oc-chatgpt-multi-auth@latest --legacy
806
102
  ```
807
103
 
808
- ### Plugins You Don't Need
809
-
810
- - **openai-codex-auth** — Not needed. This plugin replaces the original.
811
-
812
- ---
813
-
814
104
  ## Configuration
815
105
 
816
- Create `~/.opencode/openai-codex-auth-config.json` for optional settings:
817
-
818
- ### Model Behavior
819
-
820
- | Option | Default | What It Does |
821
- |--------|---------|--------------|
822
- | `requestTransformMode` | `native` | Request shaping mode: `native` keeps OpenCode payloads unchanged; `legacy` enables Codex compatibility rewrites |
823
- | `codexMode` | `true` | Legacy-only bridge prompt behavior (applies when `requestTransformMode=legacy`) |
824
- | `codexTuiV2` | `true` | Enables Codex-style terminal UI output (set `false` for legacy output) |
825
- | `codexTuiColorProfile` | `truecolor` | Terminal color profile for Codex UI (`truecolor`, `ansi256`, `ansi16`) |
826
- | `codexTuiGlyphMode` | `ascii` | Glyph mode for Codex UI (`ascii`, `unicode`, `auto`) |
827
- | `fastSession` | `false` | Forces low-latency settings per request (`reasoningEffort=none/low`, `reasoningSummary=auto`, `textVerbosity=low`) |
828
- | `fastSessionStrategy` | `hybrid` | `hybrid` speeds simple turns but keeps full-depth on complex prompts; `always` forces fast tuning on every turn |
829
- | `fastSessionMaxInputItems` | `30` | Max input items kept when fast tuning is applied |
830
-
831
- ### Account Settings (v4.10.0+)
832
-
833
- | Option | Default | What It Does |
834
- |--------|---------|--------------|
835
- | `perProjectAccounts` | `true` | Each project gets its own account storage namespace under `~/.opencode/projects/` |
836
- | `toastDurationMs` | `5000` | How long toast notifications stay visible (ms) |
837
- | `beginnerSafeMode` | `false` | Beginner-safe retry profile: conservative retry budget, disables all-accounts wait/retry, and caps all-accounts retries |
838
-
839
- ### Retry Behavior
840
-
841
- | Option | Default | What It Does |
842
- |--------|---------|--------------|
843
- | `retryProfile` | `balanced` | Global retry budget profile (`conservative`, `balanced`, `aggressive`) |
844
- | `retryBudgetOverrides` | `{}` | Per-class retry budget overrides (`authRefresh`, `network`, `server`, `rateLimitShort`, `rateLimitGlobal`, `emptyResponse`) |
845
- | `retryAllAccountsRateLimited` | `true` | Wait and retry when all accounts are rate-limited |
846
- | `retryAllAccountsMaxWaitMs` | `0` | Max wait time (0 = unlimited) |
847
- | `retryAllAccountsMaxRetries` | `Infinity` | Max retry attempts |
848
- | `unsupportedCodexPolicy` | `strict` | Unsupported-model behavior: `strict` (return entitlement error) or `fallback` (retry next model in fallback chain) |
849
- | `fallbackOnUnsupportedCodexModel` | `false` | Legacy fallback toggle mapped to `unsupportedCodexPolicy` (prefer using `unsupportedCodexPolicy`) |
850
- | `fallbackToGpt52OnUnsupportedGpt53` | `true` | Legacy compatibility toggle for the `gpt-5.3-codex -> gpt-5.2-codex` edge when generic fallback is enabled |
851
- | `unsupportedCodexFallbackChain` | `{}` | Optional per-model fallback-chain override (map of `model -> [fallback1, fallback2, ...]`) |
852
- | `fetchTimeoutMs` | `60000` | Request timeout to Codex backend (ms) |
853
- | `streamStallTimeoutMs` | `45000` | Abort non-stream parsing if SSE stalls (ms) |
854
-
855
- Default unsupported-model fallback chain (used when `unsupportedCodexPolicy` is `fallback`):
856
- - `gpt-5.4-pro -> gpt-5.4` (if `gpt-5.4-pro` is selected manually)
857
- - `gpt-5.3-codex -> gpt-5-codex -> gpt-5.2-codex`
858
- - `gpt-5.3-codex-spark -> gpt-5-codex -> gpt-5.3-codex -> gpt-5.2-codex` (applies if you manually select Spark model IDs)
859
- - `gpt-5.2-codex -> gpt-5-codex`
860
- - `gpt-5.1-codex -> gpt-5-codex`
861
-
862
- When `beginnerSafeMode` is enabled, runtime behavior is intentionally conservative:
863
- - Retry profile is forced to `conservative`
864
- - `retryAllAccountsRateLimited` is forced `false`
865
- - `retryAllAccountsMaxRetries` is capped to `1`
866
-
867
- ### Environment Variables
868
-
869
- ```bash
870
- DEBUG_CODEX_PLUGIN=1 opencode # Enable debug logging
871
- ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode # Log request metadata
872
- CODEX_PLUGIN_LOG_BODIES=1 opencode # Include raw request/response payloads in request logs (sensitive)
873
- CODEX_PLUGIN_LOG_LEVEL=debug opencode # Set log level (debug|info|warn|error)
874
- CODEX_AUTH_REQUEST_TRANSFORM_MODE=legacy opencode # Re-enable legacy Codex request rewrites
875
- CODEX_MODE=0 opencode # Temporarily disable bridge prompt
876
- CODEX_TUI_V2=0 opencode # Disable Codex-style UI (legacy output)
877
- CODEX_TUI_COLOR_PROFILE=ansi16 opencode # Force UI color profile
878
- CODEX_TUI_GLYPHS=unicode opencode # Override glyph mode (ascii|unicode|auto)
879
- CODEX_AUTH_PREWARM=0 opencode # Disable startup prewarm (prompt/instruction cache warmup)
880
- CODEX_AUTH_FAST_SESSION=1 opencode # Enable faster response defaults
881
- CODEX_AUTH_FAST_SESSION_STRATEGY=always opencode # Force fast mode for all prompts
882
- CODEX_AUTH_FAST_SESSION_MAX_INPUT_ITEMS=24 opencode # Tune fast-mode history window
883
- CODEX_AUTH_BEGINNER_SAFE_MODE=1 opencode # Enable beginner-safe runtime profile
884
- CODEX_AUTH_RETRY_PROFILE=aggressive opencode # Override retry profile (ignored when beginner safe mode is on)
885
- CODEX_AUTH_RETRY_ALL_RATE_LIMITED=0 opencode # Disable all-accounts wait-and-retry
886
- CODEX_AUTH_RETRY_ALL_MAX_WAIT_MS=30000 opencode # Cap all-accounts wait duration
887
- CODEX_AUTH_RETRY_ALL_MAX_RETRIES=1 opencode # Cap all-accounts retry attempts
888
- CODEX_AUTH_UNSUPPORTED_MODEL_POLICY=fallback opencode # Enable generic unsupported-model fallback
889
- CODEX_AUTH_FALLBACK_UNSUPPORTED_MODEL=1 opencode # Legacy fallback toggle (prefer policy var above)
890
- CODEX_AUTH_FALLBACK_GPT53_TO_GPT52=0 opencode # Disable only the legacy gpt-5.3 -> gpt-5.2 edge
891
- CODEX_AUTH_FETCH_TIMEOUT_MS=120000 opencode # Override request timeout
892
- CODEX_AUTH_STREAM_STALL_TIMEOUT_MS=60000 opencode # Override SSE stall timeout
893
- ```
894
-
895
- For all options, see [docs/configuration.md](docs/configuration.md).
896
-
897
- ---
898
-
899
- ## Documentation
106
+ Detailed configuration lives outside this README:
900
107
 
901
- - [Getting Started](docs/getting-started.md) Complete installation guide
902
- - [Configuration](docs/configuration.md) All configuration options
903
- - [Troubleshooting](docs/troubleshooting.md) Common issues and fixes
904
- - [Architecture](docs/development/ARCHITECTURE.md) — How the plugin works
108
+ - [Getting Started](docs/getting-started.md) for install and first-run setup
109
+ - [Configuration Reference](docs/configuration.md) for config keys, env vars, and fallback behavior
110
+ - [Config Templates](config/README.md) for modern vs legacy OpenCode examples
905
111
 
906
- ---
112
+ ## Troubleshooting
907
113
 
908
- ## Credits
114
+ Start here if the plugin does not load or authenticate correctly:
909
115
 
910
- - [numman-ali/opencode-openai-codex-auth](https://github.com/numman-ali/opencode-openai-codex-auth) by [numman-ali](https://github.com/numman-ali) — Original plugin
911
- - [ndycode](https://github.com/ndycode) — Multi-account support and maintenance
116
+ - [Troubleshooting](docs/troubleshooting.md)
117
+ - [Privacy & Data Handling](docs/privacy.md)
118
+ - [FAQ](docs/faq.md)
119
+ - [Security Policy](SECURITY.md)
912
120
 
913
- ## License
121
+ Common first checks:
914
122
 
915
- MIT License. See [LICENSE](LICENSE) for details.
123
+ - confirm `"plugin": ["oc-chatgpt-multi-auth@latest"]` is present in your OpenCode config
124
+ - rerun `opencode auth login`
125
+ - inspect `~/.opencode/logs/codex-plugin/` after running one request with `ENABLE_PLUGIN_REQUEST_LOGGING=1`
916
126
 
917
- <details>
918
- <summary><b>Legal</b></summary>
127
+ ## FAQ
919
128
 
920
- ### Intended Use
129
+ Short answers for the most common questions live in [docs/faq.md](docs/faq.md), including:
921
130
 
922
- - Personal / internal development only
923
- - Respect subscription quotas and data handling policies
924
- - Not for production services or bypassing intended limits
131
+ - who this plugin is for
132
+ - which OpenCode versions it supports
133
+ - how the modern and legacy config templates differ
134
+ - when to use this plugin versus the OpenAI Platform API
925
135
 
926
- ### Warning
136
+ ## Contributing
927
137
 
928
- By using this plugin, you acknowledge:
138
+ Contributions are welcome if they keep the project accurate, maintainable, and aligned with its personal-use scope.
929
139
 
930
- - **Terms of Service risk** — This approach may violate ToS of AI model providers
931
- - **No guarantees** — APIs may change without notice
932
- - **Assumption of risk** — You assume all legal, financial, and technical risks
140
+ - [Contributing Guide](CONTRIBUTING.md)
141
+ - [Code of Conduct](CODE_OF_CONDUCT.md)
142
+ - [Security Policy](SECURITY.md)
933
143
 
934
- ### Disclaimer
144
+ ## License
935
145
 
936
- - Not affiliated with OpenAI. This is an independent open-source project.
937
- - "ChatGPT", "GPT-5", "Codex", and "OpenAI" are trademarks of OpenAI, L.L.C.
146
+ MIT. See [LICENSE](LICENSE).
938
147
 
939
- </details>
148
+ ChatGPT, GPT-5, Codex, and OpenAI are trademarks of OpenAI, L.L.C.