[FEATURE]: Display token usage information in the TUI #8999

Open
opened 2026-02-16 18:11:21 -05:00 by yindo · 1 comment
Owner

Originally created by @xixiaofinland on GitHub (Feb 10, 2026).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

Currently, token usage information (input tokens, output tokens, remaining budget) is tracked internally but not visible to users in the OpenCode TUI. This makes it difficult for users to:

  • Monitor costs in real-time during conversations
  • Understand context window consumption
  • Track usage against budget limits
  • Make informed decisions about when to compact sessions

Proposed Solution

Display token usage information in the OpenCode TUI interface. Possible implementation approaches:

Option 1: Status Bar Display
Add token usage to the bottom status bar (similar to how file path or mode is displayed):

┌─────────────────────────────────────────────────┐
│ [Build Mode]  Tokens: 19.9K/1M (980K remaining) │
└─────────────────────────────────────────────────┘

Option 2: New /usage or /tokens Command
Add a slash command that displays detailed token usage:

/usage

Current Session:
  Input tokens:     12,450
  Output tokens:     7,477
  Cached tokens:     5,200
  Total:            19,927 / 1,000,000
  Remaining:       980,073 (98%)
  
Estimated cost: $0.05 (using claude-sonnet-4-5)

Option 3: Toggle-able Detail View
Add a keybind (e.g., ctrl+x t for tokens) to toggle token usage display in the conversation view, showing per-message token counts.

Option 4: Combination Approach

  • Lightweight display in status bar for at-a-glance monitoring
  • Detailed /usage command for comprehensive breakdown
  • Optional per-message display via toggle

Benefits

  1. Cost Awareness: Users can monitor spending in real-time, especially important for pay-as-you-go models
  2. Budget Management: Helps users stay within monthly limits (especially relevant for OpenCode Zen users with spending caps)
  3. Context Window Management: Users can see when they're approaching token limits and need to compact
  4. Transparency: Makes the AI interaction more transparent and understandable
  5. Educational: Helps users learn which operations consume more tokens

Additional Context

The token usage data is already being tracked (visible in system messages on the backend), so this feature would primarily involve exposing existing data to the UI rather than implementing new tracking logic.

Related Features

  • Ties into the existing /compact command by helping users understand when compaction is needed
  • Complements OpenCode Zen's monthly usage limits feature
  • Could integrate with the auto-compaction feature (compaction.auto config)

Suggested Configuration

Allow users to customize this via config:

{
  "tui": {
    "show_token_usage": true,
    "token_display_format": "compact"
  }
}
Originally created by @xixiaofinland on GitHub (Feb 10, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request ### Problem Currently, token usage information (input tokens, output tokens, remaining budget) is tracked internally but not visible to users in the OpenCode TUI. This makes it difficult for users to: - Monitor costs in real-time during conversations - Understand context window consumption - Track usage against budget limits - Make informed decisions about when to compact sessions ### Proposed Solution Display token usage information in the OpenCode TUI interface. Possible implementation approaches: **Option 1: Status Bar Display** Add token usage to the bottom status bar (similar to how file path or mode is displayed): ``` ┌─────────────────────────────────────────────────┐ │ [Build Mode] Tokens: 19.9K/1M (980K remaining) │ └─────────────────────────────────────────────────┘ ``` **Option 2: New `/usage` or `/tokens` Command** Add a slash command that displays detailed token usage: ``` /usage Current Session: Input tokens: 12,450 Output tokens: 7,477 Cached tokens: 5,200 Total: 19,927 / 1,000,000 Remaining: 980,073 (98%) Estimated cost: $0.05 (using claude-sonnet-4-5) ``` **Option 3: Toggle-able Detail View** Add a keybind (e.g., `ctrl+x t` for tokens) to toggle token usage display in the conversation view, showing per-message token counts. **Option 4: Combination Approach** - Lightweight display in status bar for at-a-glance monitoring - Detailed `/usage` command for comprehensive breakdown - Optional per-message display via toggle ### Benefits 1. **Cost Awareness**: Users can monitor spending in real-time, especially important for pay-as-you-go models 2. **Budget Management**: Helps users stay within monthly limits (especially relevant for OpenCode Zen users with spending caps) 3. **Context Window Management**: Users can see when they're approaching token limits and need to compact 4. **Transparency**: Makes the AI interaction more transparent and understandable 5. **Educational**: Helps users learn which operations consume more tokens ### Additional Context The token usage data is already being tracked (visible in system messages on the backend), so this feature would primarily involve exposing existing data to the UI rather than implementing new tracking logic. ### Related Features - Ties into the existing `/compact` command by helping users understand when compaction is needed - Complements OpenCode Zen's monthly usage limits feature - Could integrate with the auto-compaction feature (`compaction.auto` config) ### Suggested Configuration Allow users to customize this via config: ```json { "tui": { "show_token_usage": true, "token_display_format": "compact" } } ```
yindo added the discussion label 2026-02-16 18:11:21 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 10, 2026):

This issue might be a duplicate of or closely related to existing feature requests. Please check these issues:

  • #10575: Add /context command to display session token usage
  • #10354: Near-Real-Time Token and Cost Visibility
  • #6152: Session context usage (similar to /context in Claude)
  • #9281: Add unified usage tracking via /usage
  • #6767: Implement /stats command for visual usage insights

These all propose similar solutions for displaying token usage and cost information, with some variation in approach (command-based vs. status bar vs. visual stats). You may want to review how these align with your proposal and consolidate efforts if appropriate.

For keybind-related aspects (like Option 3's suggested ctrl+x t toggle), also check the pinned keybinds documentation: #4997

@github-actions[bot] commented on GitHub (Feb 10, 2026): This issue might be a duplicate of or closely related to existing feature requests. Please check these issues: - #10575: Add /context command to display session token usage - #10354: Near-Real-Time Token and Cost Visibility - #6152: Session context usage (similar to /context in Claude) - #9281: Add unified usage tracking via /usage - #6767: Implement /stats command for visual usage insights These all propose similar solutions for displaying token usage and cost information, with some variation in approach (command-based vs. status bar vs. visual stats). You may want to review how these align with your proposal and consolidate efforts if appropriate. For keybind-related aspects (like Option 3's suggested `ctrl+x t` toggle), also check the pinned keybinds documentation: #4997
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8999