| summary | read_when | ||||
|---|---|---|---|---|---|
Codex provider data sources: OpenAI web dashboard, Codex CLI RPC/PTY, credits, and local cost usage. |
|
Codex has four usage data paths (OAuth API, web dashboard, CLI RPC, CLI PTY) plus a local cost-usage scanner. The OAuth API is the default app source when credentials are available; web access is optional for dashboard extras.
- OAuth API (auth.json credentials).
- CLI RPC, with CLI PTY fallback when needed.
- If OpenAI cookies are enabled (Automatic or Manual), dashboard extras load in parallel and the source label becomes
primary + openai-web.
Usage source picker:
- Preferences → Providers → Codex → Usage source (Auto/OAuth/CLI).
- OpenAI web dashboard (when available).
- Codex CLI RPC, with CLI PTY fallback when needed.
- Reads OAuth tokens from
~/.codex/auth.json(or$CODEX_HOME/auth.json). - Refreshes access tokens when
last_refreshis older than 8 days. - Calls
GET https://chatgpt.com/backend-api/wham/usage(default) withAuthorization: Bearer <token>.
- Preferences → Providers → Codex → OpenAI cookies (Automatic or Manual).
- URL:
https://chatgpt.com/codex/settings/usage. - Uses an off-screen
WKWebViewwith a per-accountWKWebsiteDataStore.- Store key: deterministic UUID from the normalized email.
- WebKit store can hold multiple accounts concurrently.
- Cookie import (Automatic mode, when WebKit store has no matching session or login required):
- Safari:
~/Library/Cookies/Cookies.binarycookies - Chrome/Chromium forks:
~/Library/Application Support/Google/Chrome/*/Cookies - Firefox:
~/Library/Application Support/Firefox/Profiles/*/cookies.sqlite
- Domains loaded:
chatgpt.com,openai.com. - No cookie-name filter; we import all matching domain cookies.
- Safari:
- Cached cookies: Keychain cache
com.steipete.codexbar.cache(accountcookie.codex, source + timestamp). Reused before re-importing from browsers. - Manual cookie header:
- Paste the
Cookie:header from achatgpt.comrequest in Preferences → Providers → Codex. - Used when OpenAI cookies are set to Manual.
- Paste the
- Account match:
- Signed-in email extracted from
client-bootstrapJSON in HTML (or__NEXT_DATA__). - If Codex email is known and does not match, the web path is rejected.
- Signed-in email extracted from
- Web scrape payload (via
OpenAIDashboardScrapeScript+OpenAIDashboardParser):- Rate limits (5h + weekly) parsed from body text.
- Credits remaining parsed from body text.
- Code review remaining (%).
- Usage breakdown chart (Recharts bar data + legend colors).
- Credits usage history table rows.
- Credits purchase URL (best-effort).
- Errors surfaced:
- Login required or Cloudflare interstitial.
- Launches local RPC server:
codex -s read-only -a untrusted app-server. - JSON-RPC over stdin/stdout:
initialize(client name/version)account/readaccount/rateLimits/read
- Provides:
- Usage windows (primary + secondary) with reset timestamps.
- Credits snapshot (balance, hasCredits, unlimited).
- Account identity (email + plan type) when available.
- Runs
codexin a PTY viaTTYCommandRunner. - Default behavior: exit after each probe; Debug → "Keep CLI sessions alive" keeps it running between probes.
- Sends
/status, parses the rendered screen:Credits:line5h limitline → percent + reset textWeekly limitline → percent + reset text
- Retry once with a larger terminal size on parse failure.
- Detects update prompts and surfaces a "CLI update needed" error.
- Latest Codex usage snapshot (from RPC, if available).
~/.codex/auth.json(JWT claims: email + plan).- OpenAI dashboard signed-in email (cached).
- Last imported browser cookie email (cached).
- Web dashboard fills credits only when OAuth/CLI do not provide them.
- CLI RPC:
account/rateLimits/read→ credits balance. - CLI PTY fallback: parse
Credits:from/status.
- Source files:
~/.codex/sessions/YYYY/MM/DD/*.jsonl~/.codex/archived_sessions/*.jsonl(flat; date inferred from filename when present)- Or
$CODEX_HOME/sessions/...+$CODEX_HOME/archived_sessions/...ifCODEX_HOMEis set.
- Scanner:
- Parses
event_msgtoken_count entries andturn_contextmodel markers. - Computes input/cached/output token deltas and per-model cost.
- Parses
- Cache:
~/Library/Caches/CodexBar/cost-usage/codex-v1.json
- Window: last 30 days (rolling), with a 60s minimum refresh interval.
- Web:
Sources/CodexBarCore/OpenAIWeb/* - CLI RPC + PTY:
Sources/CodexBarCore/UsageFetcher.swift,Sources/CodexBarCore/Providers/Codex/CodexStatusProbe.swift - Cost usage:
Sources/CodexBarCore/CostUsageFetcher.swift,Sources/CodexBarCore/Vendored/CostUsage/*