Include token_count events in non-interactive session files

Resolved 💬 2 comments Opened Jan 22, 2026 by tedzhao26 Closed Feb 23, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What feature would you like to see?

Interactive sessions in Codex CLI don't emit token_count events to session JSONL files, making it impossible for third-party tools like @ccusage/codex to track token usage.

Current Behavior

When running Codex interactively (not via codex exec), the session files only contain:

  • session_meta
  • turn_context
  • response_item
  • event_msg with types like user_message, turn_aborted

Missing: event_msg with payload.type: "token_count"

Expected Behavior

Based on issue #5276, Codex should emit token_count events like:

{
  "timestamp": "...",
  "type": "event_msg",
  "payload": {
    "type": "token_count",
    "info": {
      "total_token_usage": { "input_tokens": ..., "output_tokens": ..., ... },
      "last_token_usage": { ... }
    }
  }
}

Environment

  • Codex CLI: 0.88.0
  • macOS Darwin 25.2.0
  • Model: gpt-5.2-codex

Use Case

Third-party usage tracking tools (ccusage, etc.) rely on parsing session files to provide cost analysis without requiring API admin keys. Without token_count events, these tools report "No Codex usage data found."

Additional Information

I've verified this across multiple interactive sessions - none contain token_count events. The sessions were short but included both completed and aborted turns.

View original on GitHub ↗

2 Comments

tedzhao26 · 7 months ago

Update: After further testing, I found that codex exec mode does emit token_count events correctly:

{"type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":8408,"cached_input_tokens":1664,"output_tokens":7,...}}}}

The issue appears to be specific to interactive TUI sessions - those don't emit token_count events to the session JSONL files, only user_message and turn_aborted event types.

This means @ccusage/codex works correctly for codex exec usage but not for interactive sessions.

etraut-openai contributor · 6 months ago

This feature request hasn't received any upvotes, so I'm closing it.