Skip to content

feat(sidebar): display input/cache tokens with cache percentage in context panel#1356

Open
walker83 wants to merge 1 commit into
XiaomiMiMo:mainfrom
walker83:feat/context-cache-display
Open

feat(sidebar): display input/cache tokens with cache percentage in context panel#1356
walker83 wants to merge 1 commit into
XiaomiMiMo:mainfrom
walker83:feat/context-cache-display

Conversation

@walker83

Copy link
Copy Markdown

What

Enhance the right-side Context panel to display a breakdown of non-cached input tokens vs cached tokens, along with the cache hit percentage.

Before:

Context
123,456 tokens
45% used
$1.23 spent

After:

Context
123,456 tokens (45%)
Input 100K · Cache 23K
19% cached
$1.23 spent

Why

Cache read pricing is 1/5 to 1/10 of regular input pricing (e.g. Anthropic: $0.30/M vs $3.00/M tokens). Users need immediate visibility into their cache hit ratio to optimize costs.

How

  • Modified context.tsx sidebar plugin to extract input, cache (read + write), and cachePercent from the last assistant message tokens
  • Merged tokens and context percentage into one line to save space
  • Added conditional display for cache breakdown using Locale.number() compact format (1K/1.5M)
  • cachePercent is Math.round(cache / totalInput * 100) with denominator guard (totalInput > 0)
  • The cache block only renders when input > 0 || cache > 0

Compatibility

This feature works on both MiMo-Code and OpenCode — the change is in the shared TUI sidebar plugin (packages/opencode/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx) and uses only the existing AssistantMessage.tokens data model which is identical across both codebases.

…ntext panel

Show breakdown of non-cached input tokens vs cached tokens in the right-side
Context panel. The cache percentage (cache / total input) helps users instantly
gauge how much their API calls benefit from cache pricing.

Works on both MiMo-Code and OpenCode.
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.

1 participant