docs/codex.md
Codex has three automatic usage data paths (OAuth API, web dashboard, CLI RPC) plus a manual CLI PTY diagnostic parser and a local cost-usage scanner. The OAuth API is the default app source when credentials are available; web access is optional for dashboard extras.
codex app-server.primary + openai-web.Usage source picker:
--source auto)codex app-server.~/.codex/auth.json (or $CODEX_HOME/auth.json).auth.json; when native credentials are stale,
the explicit OAuth path delegates recovery to the Codex CLI, which owns that file. If the CLI is unavailable,
the OAuth error is surfaced instead of mutating the shared file.GET https://chatgpt.com/backend-api/wham/usage (default) with Authorization: Bearer <token>.GET https://chatgpt.com/backend-api/wham/rate-limit-reset-credits using the same account-scoped OAuth context;
the CLI requests it only when optional credits are included.rate_limit.primary_window / secondary_window map to the session/weekly lanes.additional_rate_limits[] (model-specific limits such as GPT-5.3-Codex-Spark) map to named
UsageSnapshot.extraRateWindows entries. Spark uses stable codex-spark / codex-spark-weekly ids and
Codex Spark 5-hour / Codex Spark Weekly titles. When the field is absent, the snapshot is unchanged.$CODEX_HOME, native Codex auth wins first, followed by legacy ~/.config/codex/auth.json,
then OpenCode's ~/.local/share/opencode/auth.json (or the equivalent XDG_DATA_HOME path).$CODEX_HOME remains isolated; it never borrows credentials from those external locations.auth.json without a cross-writer publication contract. Stale native
credentials can delegate to the CLI recovery path, while stale external credentials fail closed in every mode.
Automatic mode also suppresses unscoped CLI fallback whenever a managed workspace is selected. Explicit
managed-account workspace selection is stored in CodexBar's private managed-account metadata; it never edits the
source auth.json or publishes an account_id change back to another application's credential file.~/.codexbar/config.json with
providers[].codexProfileHomePaths.~/, and point at a Codex home that contains auth.json.CODEX_HOME.Example:
{
"id": "codex",
"codexProfileHomePaths": [
"~/.codex-work",
"~/.codex-personal"
]
}
chatgpt.com in a hidden WebView and can materially increase battery or network usage.https://chatgpt.com/codex/settings/usage.WKWebView with a per-account WKWebsiteDataStore.
~/Library/Cookies/Cookies.binarycookies~/Library/Application Support/Google/Chrome/*/Cookies~/Library/Application Support/Firefox/Profiles/*/cookies.sqlitechatgpt.com, openai.com.com.steipete.codexbar.cache (account cookie.codex, source + timestamp).
Reused before re-importing from browsers.Cookie: header from a chatgpt.com request in Preferences → Providers → Codex.client-bootstrap JSON in HTML (or __NEXT_DATA__).OpenAIDashboardScrapeScript + OpenAIDashboardParser):
codex -s read-only -a untrusted app-server.initialize (client name/version)account/readaccount/rateLimits/readcodex app-server process's stdin and escalates from SIGTERM to
SIGKILL after a bounded grace period, so the stdout reader unwinds and unresponsive children cannot linger.wham/usage JSON body in the error text.codex executable, CodexBar records the launch failure and skips background CLI
launches for 30 minutes. Use a manual refresh after reinstalling or unblocking codex to retry immediately.codex
is absent from the shell PATH.codex --version works in Terminal, check which -a codex for stale duplicate installs, then run
npm install -g --include=optional @openai/codex@latest before retrying Add Account./status)CodexBarCLI usage --source cli do not launch bare Codex TUI.codex TUI can start interactive auth and open browser tabs./status output:
Credits: line5h limit line → percent + reset textWeekly limit line → percent + reset text~/.codex/auth.json (JWT claims: email + plan).account/rateLimits/read → credits balance.Credits: from saved/manual /status output.CODEX_HOME session history.$CODEX_HOME
(or ~/.codex) independently of quota, OAuth, web-dashboard, and administrator access.CostUsagePricing rates.~/.codex/sessions/YYYY/MM/DD/*.jsonl~/.codex/archived_sessions/*.jsonl (flat; date inferred from filename when present)$CODEX_HOME/sessions/... + $CODEX_HOME/archived_sessions/... if CODEX_HOME is set.~/.pi/agent/sessions/**/*.jsonl~/.omp/agent/sessions/**/*.jsonlevent_msg token_count entries and turn_context model markers; when both are present,
turn_context is authoritative for the model bucket.openai-codex assistant usage to Codex.~/Library/Caches/CodexBar/cost-usage/codex-v11.json~/Library/Caches/CodexBar/cost-usage/pi-sessions-v7.jsonSettings → Usage & Spend performs a separate fixed 30-day scan for every visible Codex account. Each request freezes
the account source, exact Codex home, authentication fingerprint, and cache identity before scanning. A missing or
invalid home is omitted; it never falls back to ambient ~/.codex or to the global Codex token snapshot.
These account rows intentionally exclude pi and OMP sessions because their history is machine-local rather than owned by one Codex account. The normal Codex cost menu and CLI scan continue to include supported pi-compatible history. The dashboard labels its values as local estimates and keeps currencies separate.
Sources/CodexBarCore/OpenAIWeb/*Sources/CodexBarCore/UsageFetcher.swift,
Sources/CodexBarCore/Providers/Codex/CodexStatusProbe.swiftSources/CodexBarCore/CostUsageFetcher.swift,
Sources/CodexBarCore/PiSessionCostScanner.swift,
Sources/CodexBarCore/PiSessionCostCache.swift,
Sources/CodexBarCore/Vendored/CostUsage/*