feat(exec): emit rate_limits in exec mode JSONL output
Summary
codex exec mode always yields rate_limits: null in rollout JSONL and in TokenCount events, making it impossible to display real-time usage percentages in tooling (e.g., VS Code status bar extensions).
The latest source code in codex-rs/exec/src/event_processor_with_jsonl_output.rs (L156-167) already handles RateLimitsUpdated correctly — it checks ev.rate_limits and emits ThreadEvent::RateLimitsUpdated when present. However, ev.rate_limits is always None at runtime in exec mode.
Root Cause Analysis
I traced the data flow through the source:
- HTTP headers parsed —
codex-rs/codex-api/src/rate_limits.rsparsesx-codex-primary-used-percent,x-codex-secondary-used-percent, etc. intoRateLimitSnapshot - Event emitted —
ResponseEvent::RateLimits(snapshot)is sent to the event stream - State stored —
SessionState.latest_rate_limitsis set viaset_rate_limits()incodex-rs/core/src/state/session.rs:117 - TokenCountEvent created —
send_token_count_event()incodex-rs/core/src/codex.rs:3718readsstate.token_info_and_rate_limits()and populatesTokenCountEvent { info, rate_limits } - Exec handler ready —
event_processor_with_jsonl_output.rs:160checksif let Some(rate_limits) = ev.rate_limits.clone()and emitsThreadEvent::RateLimitsUpdated
But ev.rate_limits is always None.
Two possible causes:
- (A) The API server does not send
x-codex-*response headers for exec-mode sessions (different from vscode/app-server mode) - (B) The npm-published binary (v0.114.0) predates the
RateLimitsUpdatedhandler code
Evidence
Rollout JSONL from exec mode (v0.114.0, 2026-03-15):
{
"type": "event_msg",
"payload": {
"type": "token_count",
"info": { "total_token_usage": { "input_tokens": 12065, "output_tokens": 3253, "total_tokens": 15318 } },
"rate_limits": null
}
}
Rollout JSONL from vscode mode (2025-10-16, via ChatGPT Cursor extension):
{
"type": "event_msg",
"payload": {
"type": "token_count",
"info": null,
"rate_limits": {
"primary": { "used_percent": 0.0, "window_minutes": 299, "resets_in_seconds": 17940 },
"secondary": { "used_percent": 6.0, "window_minutes": 10079, "resets_in_seconds": 275281 }
}
}
}
Request
- Confirm whether the API intentionally omits
x-codex-*headers for exec-mode sessions - If intentional, add an alternative mechanism (e.g., a
--show-rate-limitsflag or acodex usagesubcommand) to retrieve current rate limit status - If unintentional, ensure parity so exec mode receives the same
x-codex-*headers as vscode mode
Use Case
I'm building a VS Code status bar extension that displays Codex usage (session count, token consumption, rate limit %). Currently limited to SQLite-based estimates because exec mode provides no real rate_limits data. Having the actual used_percent from OpenAI would make the display accurate.
Environment
- Codex CLI: v0.114.0 (
npm i -g @openai/codex) - Plan: ChatGPT Team
- Platform: macOS (Apple Silicon)
- Source ref:
event_processor_with_jsonl_output.rsL156-167
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗