Skip to content

feat(tui): display input/cache tokens with cache percentage in context panel#33933

Open
walker83 wants to merge 2 commits into
anomalyco:devfrom
walker83:context-cache-display
Open

feat(tui): display input/cache tokens with cache percentage in context panel#33933
walker83 wants to merge 2 commits into
anomalyco:devfrom
walker83:context-cache-display

Conversation

@walker83

@walker83 walker83 commented Jun 25, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Enhance the right-side Context panel to display a breakdown of non-cached input tokens vs cached tokens, along with the cache hit percentage. 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.

Changes in packages/tui/src/feature-plugins/sidebar/context.tsx:

  • Extract input (non-cached input tokens) and cache (cache read tokens) from the last assistant message tokens
  • Calculate cachePercent as cache.read / (input + cache.read) * 100 - the true cache hit ratio
  • Merge tokens and context percentage into one line
  • Conditional display for cache breakdown using Locale.number() compact format

Note: cache.write tokens represent cache misses that write to cache for future use, and are excluded from the cache hit percentage calculation since they are not input tokens served from cache.

How did you verify your code works?

Reviewed manually. The change is isolated to a single sidebar plugin file and uses existing AssistantMessage.tokens data. Follows patterns used by 15+ other files in the codebase.

Screenshots / recordings

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

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…t 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.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

- Extract computeContextState function for testability
- Cache hit percentage now correctly uses only cache.read tokens
- cache.write (cache misses) excluded from hit ratio calculation
- Add comprehensive unit tests for cache computation
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