GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [FEATURE]:Token Usage & Cache Hit Dashboard per Session · Issue #42295 · anomalyco/opencode

[FEATURE]:Token Usage & Cache Hit Dashboard per Session #42295

New issue
Copy link
New issue
Copy link
Closed as duplicate
Closed as duplicate
[FEATURE]:Token Usage & Cache Hit Dashboard per Session#42295
Copy link
Assignees
neriousy

Description

@GuixJoy
GuixJoy
opened on Aug 13, 2026
Issue body actions

Describe the enhancement you want to request

Add a live token usage and cache analytics panel visible during an active OpenCode session. This would display:

  • Total tokens consumed in the current session (input + output separately)
  • Cache hit count and cache hit ratio as a percentage
  • Estimated cost for the current session based on the model being used
  • A per-message breakdown showing tokens used per exchange

Right now there is no visibility into how much context is being consumed during a session. This creates two problems. First, developers have no idea when they are approaching context limits until the model starts degrading in quality. Second, there is no way to evaluate whether caching is actually working effectively across a session.

A token usage panel solves both. It helps developers make informed decisions about when to start a new session, which parts of their workflow are token-heavy, and whether their cache configuration is performing as expected.

This is especially useful for long agentic sessions where token consumption compounds quickly and cost visibility matters.

Reacted by Wanci

Activity

  1. github-actions
    assigned
    neriousy
    on Aug 13, 2026
  2. github-actions commented on Aug 13, 2026

    @github-actions
    github-actionsBot
    on Aug 13, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue might be a duplicate of existing issues. Please check:

    • [FEATURE]: /usage — dedicated session token & cost report (alias /cost) #41915: /usage — dedicated session token & cost report (alias /cost) — very similar request for a per-session token/cost breakdown command
    • [FEATURE]: Show cached vs fresh token breakdown in context meter #34298: Show cached vs fresh token breakdown in context meter — covers the cache hit ratio display
    • [FEATURE]: Display token usage information in the TUI #13003: Display token usage information in the TUI — earlier request for live token usage visibility in the TUI
    • [FEATURE]: Session context usage (similar to /context in Claude) #6152: Session context usage (similar to /context in Claude) — overlapping request for context/token usage panel
  3. VladSmr commented on Oct 2, 2026

    @VladSmr
    VladSmr
    on Oct 2, 2026
    More actions

    A per-session version of this exists as a plugin: /context-breakdown renders a
    per-category dashboard (system prompt, tool schemas, user/assistant, reasoning,
    tool args, residual) for the session and all its subagent sessions. The new /cx
    panel in the terminal TUI adds a largest-contributors view — which message,
    tool call or tool result eats the most, measured from the live message list.

    Cache read/write participates in the native overflow metric, though the category
    breakdown doesn't split it out separately yet.

    opencode-context-indicator — still in a testing stage; with your help and
    feedback we can make it better together. Dual V1 + V2, tested against 2.0.22,
    everything local (no uploads, no extra LLM calls).

    https://github.com/VladSmr/opencode-context-indicator
    npm: opencode-context-indicator

    Reacted by Wanci
  4. Songwanci commented on Oct 28, 2026

    @Songwanci
    Songwanci
    on Oct 28, 2026
    More actions

    Per-message token breakdown in the desktop app

    The desktop app shows session-level totals today (e.g. 101k · $4.55 next to the context ring, added by #53785), and the Review → Context panel aggregates the session. But there is still no way to see per-message token usage anywhere in the app.

    This is exactly the "per-message breakdown showing tokens used per exchange" that this issue asks for. I'd like to request it for the desktop app specifically:

    For each assistant message, show its own:

    • input (uncached)
    • output
    • reasoning
    • cache read / write
    • cost

    My use case: I'm on a free/metered token quota and need to know which individual messages are consuming the most tokens. Session totals don't tell me that — I need the per-message figure to find the outliers.

    Context / related:

    • feat(desktop): show session tokens and cost on the session view #53785 added session-level tokens + cost to the session view header.
    • [FEATURE]: desktop: show cross-session token totals and cache hit rate in the Context panel #58024 asks for cross-session totals and cache hit rate in the Context panel.
    • This issue ([FEATURE]:Token Usage & Cache Hit Dashboard per Session #42295) is the one that covers the per-message breakdown.

    The data already exists per message (session_message.data.tokens in the V2 database, and message.data.tokens in V1), so this is purely a presentation gap.

    A per-message row in the session view, or a click-to-expand on each message, would be ideal. Thanks!

    Reacted by Wanci
  5. opencodejr commented on Oct 28, 2026

    @opencodejr
    opencodejrBot
    on Oct 28, 2026
    Contributor
    More actions

    Thanks for the request, @GuixJoy! To restate it: you'd like a live usage panel for the current session that shows input and output tokens separately, how often the cache was hit and the hit ratio, the estimated cost, and the tokens used by each exchange. Maintainers will consider it.

    Some of this already exists in v2:

    • The TUI sidebar's Context block shows the current context size, the % of the model's context window used, and the session cost.
    • Setting "debug": { "turn_tokens": true } in ~/.config/opencode/cli.json adds a per-turn table of new and cached tokens under each response, and flags likely cache busts.
    • The desktop app's Context panel shows input, output, reasoning and cache read/write tokens and the cost.

    Until then, you can get the rest in the TUI with a small plugin. It adds a Usage block to the session sidebar with input and output totals, cache read/write, cache hits per turn, the share of prompt tokens served from cache, the cost, and the last few turns:

    // ~/.config/opencode/plugins/session-usage/tui.tsx
    import { Plugin } from "@opencode/plugin/tui"
    import { createMemo, For, Show } from "solid-js"
    
    const money = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" })
    const n = (value: number) => value.toLocaleString()
    
    export default Plugin.define({
      id: "local.session-usage",
      setup(context) {
        const theme = context.theme
        const perTurn = context.options.turns === undefined ? 5 : Number(context.options.turns)
        return context.ui.slot({
          append: "sidebar.content",
          render: (props) => {
            const turns = createMemo(() =>
              context.data.session.message
                .list(props.sessionID)
                .flatMap((message) => (message.type === "assistant" && message.tokens ? [message.tokens] : [])),
            )
            const totals = createMemo(() =>
              turns().reduce(
                (sum, t) => ({
                  input: sum.input + t.input,
                  output: sum.output + t.output + t.reasoning,
                  read: sum.read + t.cache.read,
                  write: sum.write + t.cache.write,
                  hits: sum.hits + (t.cache.read > 0 ? 1 : 0),
                }),
                { input: 0, output: 0, read: 0, write: 0, hits: 0 },
              ),
            )
            const ratio = () => {
              const t = totals()
              const prompt = t.input + t.read + t.write
              return prompt > 0 ? Math.round((t.read / prompt) * 100) : 0
            }
            return (
              <Show when={turns().length > 0}>
                <box>
                  <text fg={theme.text.base}>
                    <b>Usage</b>
                  </text>
                  <text fg={theme.text.muted}>In {n(totals().input)} · Out {n(totals().output)}</text>
                  <text fg={theme.text.muted}>
                    Cache {n(totals().read)} read · {n(totals().write)} write
                  </text>
                  <text fg={theme.text.muted}>
                    Cache hits {totals().hits}/{turns().length} turns · {ratio()}% of prompt
                  </text>
                  <text fg={theme.text.muted}>{money.format(context.data.session.cost(props.sessionID))} spent</text>
                  <Show when={perTurn > 0}>
                    <For each={turns().slice(-perTurn)}>
                      {(t) => (
                        <text fg={theme.text.muted}>
                          · {n(t.input + t.cache.read + t.cache.write)} in ({n(t.cache.read)} cached) / {n(t.output + t.reasoning)} out
                        </text>
                      )}
                    </For>
                  </Show>
                </box>
              </Show>
            )
          },
        })
      },
    })

    To install it, save the file as tui.tsx in a folder such as ~/.config/opencode/plugins/session-usage/. Then add that folder's absolute path to plugins in ~/.config/opencode/cli.json and restart the TUI. The turns option sets how many recent turns are listed, and 0 hides the list:

    {
      "plugins": [
        { "package": "/home/you/.config/opencode/plugins/session-usage", "options": { "turns": 5 } }
      ]
    }

    The input and output totals add up every assistant step in the session. "% of prompt" is cache reads divided by all prompt tokens (fresh input plus cache read and write).

    Related issues:

    • [FEATURE]: /usage — dedicated session token & cost report (alias /cost) #41915: a /usage command with per-message and cumulative token and cost accounting
    • [FEATURE]: desktop: show cross-session token totals and cache hit rate in the Context panel #58024: cache hit rate and totals across sessions in the desktop Context panel
    • [FEATURE]: v2: show per-step and per-turn cost in the token usage view #53121: per-step and per-turn cost in the debug.turn_tokens view
    • [FEATURE]: split token usage inside a step (system, schemas, each tool result, reasoning, output) #58716: a breakdown of the tokens inside a single step
  6. neriousy commented on Nov 13, 2026

    @neriousy
    neriousy
    on Nov 13, 2026
    Member
    More actions

    Thanks! This asks for the same per-session, per-message token and cost breakdown as #41915, so I'm closing it as a duplicate. Some of it already exists: the desktop header shows session tokens and cost (#53785), and the TUI's debug.turn_tokens setting shows new vs cached tokens per step. A cache hit rate in the desktop Context panel is tracked in #58024.

  7. neriousy
    closed this as a duplicateof [FEATURE]: /usage — dedicated session token & cost report (alias /cost) #41915 on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @neriousy
    neriousy

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.