Include per-API-call token usage (`last`) in turn.completed JSONL events

Resolved 💬 3 comments Opened Apr 12, 2026 by aroytman Closed May 16, 2026

What variant of Codex are you using?

CLI

What feature would you like to see?

When using codex exec, the turn.completed JSONL event reports cumulative session token totals. This makes it impossible to determine current context window utilization ... the cumulative numbers grow across API calls and quickly exceed the context window size (e.g. 6.9M cumulative input_tokens against a 272K window).

The interactive CLI doesn't have this problem because it uses the per-request data from ThreadTokenUsage.last internally. But that field is discarded when converting to the exec JSONL output ... only .total is emitted.

Adding the most recent request's token usage to the turn.completed event would bring exec output to parity with the interactive experience for context window tracking. Something like:

{"type":"turn.completed","usage":{...},"last_usage":{"input_tokens":248301,...}}

The data is already available in ThreadTokenUsage.last ... it just needs to be carried through to the JSONL output in event_processor_with_jsonl_output.rs (usage_from_last_total).

Additional Information

This affects any programmatic use of codex exec that wants to display or act on context window utilization.

Additional information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗