What We Already Had
The local Codex CLI stores authentication metadata in ~/.codex/auth.json and session transcripts in ~/.codex/sessions.
This page captures the reasoning behind codex_nerve.py: where the account credentials come from,
which endpoint exposes usage windows, which headers matter, and why local session counting is only an optional supplement.
The local Codex CLI stores authentication metadata in ~/.codex/auth.json and session transcripts in ~/.codex/sessions.
A lightweight terminal view of account usage: 5-hour and weekly utilization, reset countdowns, plan information, and a rough local session count.
codex_nerve.py polls the usage endpoint, draws a curses dashboard, and optionally scans local session files for recent activity.
~/.codex/auth.json includes both an access_token and a refresh_token, so a stale copied token can be recovered without logging in again.
~/.codex/auth.json.
https://chatgpt.com/backend-api/wham/usage with the same two headers the CLI uses for account-level views.
~/.codex/sessions is scanned separately.
The dashboard’s network layer is intentionally small. The essential request is:
GET https://chatgpt.com/backend-api/wham/usage
Authorization: Bearer <access_token>
ChatGPT-Account-Id: <account_id>
Accept: application/json
That response provides the usage windows used by the TUI, including primary and secondary rate-limit windows, reset times, plan metadata, and code-review window information.
The installed Codex binary contains clear OAuth strings for token recovery, including
refresh_token, grant_type, application/x-www-form-urlencoded,
the ChatGPT client id app_EMoamEEZ73f0CkXaXp7hrann, and log messages like
“Access token expired, refreshing.”
Separately, the local token claims show iss=https://auth.openai.com and the
offline_access scope, which strongly suggests standard OAuth refresh semantics.
I verified the token endpoint from the OpenAI OIDC discovery document:
https://auth0.openai.com/oauth/token.
POST https://auth0.openai.com/oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token
refresh_token=<refresh_token from ~/.codex/auth.json>
client_id=app_EMoamEEZ73f0CkXaXp7hrann
codex_refresh_auth.py lets you inspect or run the same refresh explicitly.
The dashboard scans *.jsonl files under a configured sessions_dir and groups them into “last 5 hours,”
“last 7 days,” and “all time.” This is helpful for local machine awareness, but it is not the same thing as server-side account usage.
The helper script writes credentials into Codex/.local/accounts.ini, which is gitignored.
That keeps the live token file out of normal source control while still giving the dashboard a stable default path.
./Codex/codex_bootstrap_accounts.sh
python3 Codex/codex_refresh_auth.py --print-only
python3 Codex/codex_nerve.py