Skip to content

Show token usage breakdown at the end of codex exec #29272

Open

Description

@vjain419

Summary

Human-readable codex exec output currently prints only one effective token count when a run finishes.

It should show the same detailed token summary as interactive Codex: effective total, non-cached input, cached input, output, and reasoning output.

User impact

A single combined number does not show whether usage came from new context, poor cache reuse, generated output, or reasoning.

Users must select --json in advance and process JSONL to obtain information already available internally.

Current behavior

A completed human-readable run ends with output similar to:

tokens used
1,234

The displayed value is the blended total: non-cached input plus output. Cached input and reasoning output are hidden.

Expected behavior

Show the detailed breakdown, for example:

Token usage: total=1,234 input=900 (+ 5,000 cached) output=334 (reasoning 120)

The exact layout may retain the existing codex exec section style, but its fields and accounting semantics should match interactive Codex.

Minimal reproduction

  1. Run codex exec "Reply with one sentence.".
  2. Wait for completion.
  3. Observe that the final token summary contains only one number.
  4. Compare with interactive Codex or the turn.completed.usage event from codex exec --json.

Notes from code/docs review

The human-output processor retains the full ThreadTokenUsage, but reduces it to blended_total() before printing.

The JSONL processor already exposes input, cached-input, output, and reasoning-output fields. The interactive CLI already formats these values into the requested summary. No protocol or backend change appears necessary.

Why this is not covered by existing issues

Activity

  1. added
    enhancementNew feature or request
    CLIIssues related to the Codex CLI
    execIssues related to the `codex exec` subcommand
    rate-limitsIssues related to rate limits, quotas, and token usage reporting
    on Jun 20, 2026
  2. Necmttn commented on Jun 21, 2026

    @Necmttn

    The human-readable footer should include both buckets and provenance. Example fields: total charged/effective, input uncached, input cached, output, reasoning output, and usage_source=provider_final|estimate|partial.

    That matters for codex exec because users often run it in scripts and only see the final text. If cached or reasoning tokens are hidden, people misdiagnose cache misses or model-effort changes as ordinary output growth. JSONL can stay richer, but the terminal summary should preserve the same accounting semantics.


    Generated with ax.

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

    CLIIssues related to the Codex CLIenhancementNew feature or requestexecIssues related to the `codex exec` subcommandrate-limitsIssues related to rate limits, quotas, and token usage reporting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions