Skip to content

Commit 77845ff

Browse files
committed
Document oc-chatgpt-multi-auth authentication support
1 parent 8b9eec6 commit 77845ff

2 files changed

Lines changed: 71 additions & 5 deletions

File tree

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ Download the latest `.dmg` file from the [**Releases**](https://github.com/opggi
5858
| **GitHub Copilot** | Quota-based | Multi-account, daily history, overage tracking, auth source labels |
5959

6060
### OpenCode Plugins
61+
- **ChatGPT / Codex**
62+
- `ndycode/oc-chatgpt-multi-auth`
63+
- Reads `~/.opencode/openai-codex-accounts.json` and `~/.opencode/projects/*/openai-codex-accounts.json`
64+
- Also understands plugin-managed OpenCode `auth.json` fields such as `idToken`, `accountIdOverride`, and `organizationIdOverride`
6165
- **Antigravity/Gemini**
6266
- `NoeFabris/opencode-antigravity-auth` (writes `~/.config/opencode/antigravity-accounts.json`)
6367
- `jenslys/opencode-gemini-auth` (writes `google.oauth` in OpenCode `auth.json`)
@@ -75,8 +79,10 @@ Download the latest `.dmg` file from the [**Releases**](https://github.com/opggi
7579
- **Browser Cookies** - Chrome, Brave, Arc, Edge session cookies
7680
- Multiple accounts from different sources are automatically deduplicated and merged
7781
- **Codex**
82+
- **OpenCode + oc-chatgpt-multi-auth** - Auto-detected from OpenCode `auth.json` plus `~/.opencode/.../openai-codex-accounts.json`
7883
- **Codex for Mac** - Auto-detected through `~/.codex/auth.json`
7984
- **Codex CLI** - Auto-detected through `~/.codex/auth.json`
85+
- **codex-lb** - Auto-detected through `~/.codex-lb/`
8086
- **Claude Code CLI** - Keychain-based authentication detection
8187

8288
## Features
@@ -354,8 +360,8 @@ Quit (⌘Q)
354360
355361
## How It Works
356362

357-
1. **Token Discovery**: Reads authentication tokens from OpenCode's `auth.json` (with multi-path fallback)
358-
2. **Multi-Source Account Discovery**: For providers like GitHub Copilot, discovers accounts from multiple sources (OpenCode auth, CLI Keychain, VS Code config, browser cookies) and deduplicates by login/email
363+
1. **Token Discovery**: Reads authentication tokens from OpenCode's `auth.json` (with multi-path fallback), including plugin-managed OpenAI metadata
364+
2. **Multi-Source Account Discovery**: For providers like ChatGPT and GitHub Copilot, discovers accounts from multiple sources (OpenCode auth, OpenCode plugin files, CLI/Keychain/config stores, browser cookies) and deduplicates them by stable account metadata
359365
3. **Parallel Fetching**: Queries all provider APIs simultaneously using TaskGroup
360366
4. **Smart Caching**: Falls back to cached data on network errors
361367
5. **Graceful Degradation**: Shows available providers even if some fail
@@ -377,6 +383,13 @@ The app searches for `auth.json` in these locations (in order):
377383
2. `~/.local/share/opencode/auth.json` (default)
378384
3. `~/Library/Application Support/opencode/auth.json` (macOS fallback)
379385

386+
For ChatGPT/Codex multi-account setups, the app also searches:
387+
1. `~/.opencode/auth/openai.json`
388+
2. `~/.opencode/openai-codex-accounts.json`
389+
3. `~/.opencode/projects/*/openai-codex-accounts.json`
390+
391+
If `oc-chatgpt-multi-auth` is installed and OpenCode sets `provider.openai.options.baseURL` to a localhost proxy, OpenCode Bar still queries the direct ChatGPT usage endpoint by default. Only the explicit `opencode-bar.codex.usageURL` override changes the usage endpoint.
392+
380393
### GitHub Copilot not showing
381394
GitHub Copilot accounts are discovered from multiple sources (in priority order):
382395
1. **OpenCode auth**`copilot` entry in OpenCode `auth.json`

docs/AI_USAGE_API_REFERENCE.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
| Provider | Token File |
88
|----------|-----------|
99
| Claude | `~/.config/opencode/opencode-anthropic-auth/accounts.json`, `~/.local/share/opencode/auth.json`, `~/.config/claude-code/auth.json`, macOS Keychain (`Claude Code-credentials`, `Claude Code`) |
10-
| Codex, Copilot, Nano-GPT, MiniMax | `~/.local/share/opencode/auth.json` |
10+
| Codex / ChatGPT | `~/.local/share/opencode/auth.json`, `~/.opencode/auth/openai.json`, `~/.opencode/openai-codex-accounts.json`, `~/.opencode/projects/*/openai-codex-accounts.json`, `~/.codex/auth.json`, `~/.codex-lb/` |
11+
| Copilot, Nano-GPT, MiniMax | `~/.local/share/opencode/auth.json` |
1112
| Antigravity (Gemini) | `~/.config/opencode/antigravity-accounts.json` |
1213
| Antigravity (Local cache) | `~/Library/Application Support/Antigravity/User/globalStorage/state.vscdb` |
1314

@@ -69,15 +70,23 @@ The bundled [`scripts/query-claude.sh`](/Users/kargnas/projects/opencode-bar/scr
6970

7071
**Endpoint:** `GET https://chatgpt.com/backend-api/wham/usage`
7172

73+
OpenCode Bar uses the direct ChatGPT usage endpoint by default. If `oc-chatgpt-multi-auth` sets OpenCode's `provider.openai.options.baseURL` to a localhost proxy, that proxy is ignored for usage requests unless `opencode-bar.codex.usageURL` is explicitly configured.
74+
7275
```bash
7376
ACCESS=$(jq -r '.openai.access' ~/.local/share/opencode/auth.json)
74-
ACCOUNT_ID=$(jq -r '.openai.accountId' ~/.local/share/opencode/auth.json)
77+
ACCOUNT_ID=$(jq -r '
78+
.openai.accountIdOverride
79+
// .openai.organizationIdOverride
80+
// .openai.accountId
81+
' ~/.local/share/opencode/auth.json)
7582

7683
curl -s "https://chatgpt.com/backend-api/wham/usage" \
7784
-H "Authorization: Bearer $ACCESS" \
7885
-H "ChatGPT-Account-Id: $ACCOUNT_ID"
7986
```
8087

88+
For `oc-chatgpt-multi-auth` account files, prefer the canonical ChatGPT account ID from the access token claims when present. The plugin's `accountId` may be an organization ID (`org-*`) for the selected workspace, while the JWT claim `https://api.openai.com/auth.chatgpt_account_id` is the stable per-account identifier.
89+
8190
**Response:**
8291
```json
8392
{
@@ -398,7 +407,13 @@ Client Secret: Set GEMINI_CLIENT_SECRET environment variable
398407
"access": "eyJ...",
399408
"refresh": "rt_...",
400409
"expires": 1770563557150,
401-
"accountId": "uuid"
410+
"accountId": "uuid",
411+
"idToken": "eyJ...",
412+
"multiAccount": true,
413+
"accountIdOverride": "org-selected-account",
414+
"organizationIdOverride": "org-selected-account",
415+
"accountIdSource": "org",
416+
"accountLabel": "Personal [id:abc123]"
402417
},
403418
"github-copilot": {
404419
"type": "oauth",
@@ -413,6 +428,44 @@ Client Secret: Set GEMINI_CLIENT_SECRET environment variable
413428
}
414429
```
415430

431+
`oc-chatgpt-multi-auth` may leave `accountId` unset in `auth.json` and instead store the selected workspace in `accountIdOverride` / `organizationIdOverride`. OpenCode Bar derives the canonical ChatGPT account ID from the OpenAI JWT claims and keeps the override value as additional metadata when needed.
432+
433+
### OpenCode ChatGPT Multi-Auth (`~/.opencode/projects/*/openai-codex-accounts.json`)
434+
435+
```json
436+
{
437+
"version": 3,
438+
"accounts": [
439+
{
440+
"accountId": "org-example-account",
441+
"organizationId": "org-example-account",
442+
"accountIdSource": "org",
443+
"accountLabel": "Personal [id:abc123]",
444+
"email": "user@example.com",
445+
"refreshToken": "oaistb_rt_...",
446+
"accessToken": "eyJ...",
447+
"expiresAt": 1776088595278
448+
},
449+
{
450+
"accountId": "058af373-bff1-4490-98b7-2a71290ae604",
451+
"accountIdSource": "token",
452+
"accountLabel": "Token account [id:0ae604]",
453+
"email": "user@example.com",
454+
"refreshToken": "oaistb_rt_...",
455+
"accessToken": "eyJ...",
456+
"expiresAt": 1776088595278
457+
}
458+
],
459+
"activeIndex": 0,
460+
"activeIndexByFamily": {
461+
"gpt-5.4": 0,
462+
"gpt-5.4-mini": 0
463+
}
464+
}
465+
```
466+
467+
OpenCode Bar reads every entry in these files, canonicalizes account IDs from the JWT claims, and merges duplicates with the OpenCode auth, Codex native auth, and `codex-lb` sources.
468+
416469
### Antigravity Accounts (`~/.config/opencode/antigravity-accounts.json`)
417470

418471
```json

0 commit comments

Comments
 (0)