Skip to content

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

Description

@xixiaofinland

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"
  }
}

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Feb 10, 2026
  2. github-actions commented on Feb 10, 2026

    @github-actions
    Contributor

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

    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

  3. chimon2000 commented on Mar 12, 2026

    @chimon2000

    I would find Option 4 extremely useful.

  4. ke7in-zz commented on Mar 15, 2026

    @ke7in-zz

    Make the cli status customizable like claude code

  5. ForceConstant commented on Apr 6, 2026

    @ForceConstant

    I would agree, option 4 would be great.

  6. ThomasCarca commented on Apr 14, 2026

    @ThomasCarca

    This should probably rely on OTEL which is a feature being asked/discussed within the community and has yet to be fully supported.

  7. eduardosanzb commented on Apr 15, 2026

    @eduardosanzb

    I think also would be amazing to show an estimate in how many tokens the current message im about to send will be.

    this is because sometimes i paste logs and i would like to change model if i know i will trigger compactation (e.g. to mimo )

  8. assigned and unassigned on Apr 26, 2026
  9. removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on May 3, 2026
  10. zhumengzhu commented on Jun 10, 2026

    @zhumengzhu

    Two sidebar plugins already cover most of these use cases today:

    Both read from api.state.session, so the data pipeline is already established —
    no new tracking logic needed on the OpenCode side.

  11. VictorVow commented on Jul 7, 2026

    @VictorVow

    Seems to be implemented now as a Status Bar Display:

    Image
  12. Xyz00777 commented on Jul 9, 2026

    @Xyz00777

    no this shows only the current context size and when known the cost amount

  13. liudongyan13701205717-source commented on Aug 9, 2026

    @liudongyan13701205717-source

    Free-tier / pay-as-you-go users need this visibility most, especially to decide when to compact. I'd also settle for the /usage command (Option 2) as the MVP.

  14. Xyz00777 commented on Aug 9, 2026

    @Xyz00777

    i think its easy to also provide than a toogle to also show it in the status bar or the bottom area. I think the hard part is to get the information in the first place from all the different provider.
    But yeah i would also be happy if i could use /usage at lest and if it would than be exposed to some internal api at least, so i could let create a plugin to add it myself than.

  15. liudongyan13701205717-source commented on Aug 15, 2026

    @liudongyan13701205717-source

    +1, displaying token usage in the TUI is very useful for cost tracking; still relevant.

  16. angeloper86 commented on Sep 10, 2026

    @angeloper86

    hi! I built a small opencode TUI plugin: /context shows exactly how the built-in Context panel number is composed — input (no cache), output, reasoning, cache read/write, cache hit rate and cost — plus the session-wide total. When you delegate with task, it walks the child sessions and adds a Subagents block and a combined total (subagent usage is excluded from the parent's panel).
    Zero runtime dependencies, never calls an LLM, exact numbers (no estimates). Install with opencode plugin opencode-context-usage (restart after). Repo: https://github.com/angeloper86/opencode-context-usage — feedback and issues welcome!

  17. Blaze147 commented on Sep 23, 2026

    @Blaze147

    I just finished building this into the Context tab of the desktop app UI (still needs localization) on my fork and I'd like to submit it as a PR soon, but I built it as a frontend calculation and I'm now realizing the devs may wish to build it into the client backend/core instead.

    Regardless, dumping a short screen-recording of how I laid out the UI in case it helps. I should also note that I renamed the "Context" tab to "Stats" since that's a more accurate description now.

    I essentially decided to have two sets of token stats... one for the context and a second for the entire session. I overwhelmingly rely on the session stats and I have no idea why anyone would care about more than just total tokens used in the context and percentage used... but I don't see any point in removing those stats either. Maybe someone cares about the other stuff.

    GIF:
    image

  18. neriousy commented on Oct 1, 2026

    @neriousy
    Member

    The OpenCode v2 TUI shows token usage. The sidebar Context panel shows tokens, the percentage of the context window used, and cost. The prompt footer shows context usage too.

    Added in #19347 and carried into v2 in #31049. A more detailed per-category breakdown (like Claude's /context) is tracked in #6152.

    Closing as completed. If something doesn't work on v2, please open a new issue.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions