Skip to content

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

Closed

Description

@aroytman

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

Activity

  1. added
    enhancement
    on Apr 12, 2026
  2. added
    CLI
    exec
    context
    on Apr 12, 2026
  3. removed
    CLI
    context
    on Apr 12, 2026
  4. aroytman commented on Apr 12, 2026

    @aroytman
    Author

    Not a duplicate. Those issues describe user confusion caused by the exact gap this feature request addresses ... the exec JSONL only exposes cumulative totals, making it impossible to determine per-request context window usage. Adding last_usage to turn.completed would prevent that class of confusion entirely.

  5. etraut-openai commented on May 16, 2026

    @etraut-openai
    Contributor

    This feature hasn't received enough upvotes, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementexec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions