Skip to content

Conversation

Copy link

Copilot AI commented Aug 31, 2025

Implements comprehensive usage statistics that are automatically displayed and logged after each turn completes, addressing the need for better visibility into token consumption and costs.

What's Added

Visual Display in TUI:
After each turn completes, users now see a formatted summary including:

  • 📊 Turn Completed header with current turn statistics
  • 🔄 This Turn section showing input/output/reasoning tokens and estimated cost
  • 📈 Session Total section showing cumulative usage and context window percentage

Session Logging:
Structured JSON logs are written to the session log file containing:

  • Detailed token counts (input, cached, output, reasoning) for both turn and session
  • Estimated cost calculations based on typical model pricing
  • Context window usage metrics
  • Session ID for correlation

Example Output

📊  Turn Completed
🔄  This Turn
  • Input: 282 (+ 13473 cached)
  • Output: 2709
  • Reasoning: 2176
  • Turn Total: 2991
  • Estimated Cost: ~$0.1710

📈  Session Total
  • Session ID: c7df96da-daec-4fe9-aed9-3cd19b7a6192
  • Total Input: 61473 (+ 423266 cached)
  • Total Output: 7412
  • Session Total: 68885
  • Context Usage: 487223/400000 (122%)

Implementation Details

  • Minimal Integration: Hooks into existing TaskCompleteEvent handling without disrupting current flow
  • Cost Estimation: Uses placeholder pricing (~$0.03/$0.06 per 1K tokens) that can be made model-specific later
  • Smart Display: Only shows statistics when non-zero token usage occurs
  • Existing Infrastructure: Leverages current token tracking and session logging systems
  • Test Coverage: Updated snapshot test to include new output format

The feature provides immediate visibility into token consumption patterns and helps users understand the cost implications of their interactions with Codex.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: iainlowe <3978+iainlowe@users.noreply.github.com>
Copilot AI changed the title [WIP] after each turn is completed, output a log that gives usage statistics: tokens used up/down, cost of turn, current token/usage cap, etc Add turn completion usage statistics logging and display Aug 31, 2025
Copilot AI requested a review from iainlowe August 31, 2025 23:43
@iainlowe iainlowe marked this pull request as ready for review August 31, 2025 23:43
Copilot AI review requested due to automatic review settings August 31, 2025 23:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements comprehensive usage statistics tracking that automatically displays turn completion metrics in the TUI and logs structured data to session files, providing visibility into token consumption and estimated costs.

  • Adds visual display of token usage and cost estimates after each turn completion
  • Implements structured JSON logging of detailed usage statistics to session logs
  • Integrates seamlessly with existing token tracking infrastructure

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
codex-rs/tui/tests/fixtures/ideal-binary-response.txt Updates test fixture to include new turn completion statistics display format
codex-rs/tui/src/session_log.rs Adds logging function for turn completion statistics to session log
codex-rs/tui/src/history_cell.rs Implements display formatting and cost estimation for turn completion statistics
codex-rs/tui/src/chatwidget.rs Integrates turn completion statistics into the chat workflow and event handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

iainlowe and others added 2 commits August 31, 2025 19:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@iainlowe iainlowe merged commit cf41716 into main Aug 31, 2025
@iainlowe iainlowe deleted the copilot/fix-32f53ede-00b2-4868-ae78-a59a7019dd14 branch August 31, 2025 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants