Skip to content

Fix Claude context usage normalization for UI meter, Fixes #2034#2551

Open
amitbet wants to merge 2 commits intopingdotgg:mainfrom
amitbet:fix/claude-context-meter
Open

Fix Claude context usage normalization for UI meter, Fixes #2034#2551
amitbet wants to merge 2 commits intopingdotgg:mainfrom
amitbet:fix/claude-context-meter

Conversation

@amitbet
Copy link
Copy Markdown

@amitbet amitbet commented May 6, 2026

What Changed

Treat Claude accumulated totals as processed-token telemetry unless a context-accurate used-token field is present, so context percentage indicators no longer pin to 100% on result-only snapshots.

Why

Bug Fix: when using ClaudeCode context usage is always 100%

UI Changes

before:
image
after:
image

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Adjusts token-usage normalization semantics for Claude results, which can affect UI context meters and downstream telemetry consumers if they relied on previous clamping behavior.

Overview
Fixes Claude token-usage snapshots so accumulated result.usage totals are no longer treated as context-window usage.

normalizeClaudeTokenUsage now prefers explicitly reported context-accurate fields (used_tokens/usedTokens/last_used_tokens/lastUsedTokens) and only clamps those to contextWindow; when those fields are absent, oversized total_tokens is preserved as usedTokens (and maxTokens is omitted).

On turn completion, accumulated result.usage is normalized without passing a context window, so it’s treated as processed-token telemetry unless a prior task-progress snapshot provided context-accurate usage. Tests were updated to assert the new “keep oversized totals” behavior.

Reviewed by Cursor Bugbot for commit ee63cc2. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix Claude context usage normalization to preserve oversized token totals in UI meter

  • normalizeClaudeTokenUsage now distinguishes between context-accurate usage (from direct usedTokens/lastUsedTokens fields) and accumulated totals from result.usage, which can exceed the context window.
  • When context-accurate usage is available, usedTokens is clamped to contextWindow and maxTokens is included in the snapshot. When only accumulated totals exist, they are preserved unclamped and maxTokens is omitted.
  • In ClaudeAdapter.ts, the call to normalizeClaudeTokenUsage for accumulated result.usage no longer passes a contextWindow, so those totals are never clamped.
  • Behavioral Change: thread.token-usage.updated events for accumulated-only usage will no longer include maxTokens, and usedTokens may exceed the context window size.

Macroscope summarized ee63cc2.

Treat Claude accumulated totals as processed-token telemetry unless a context-accurate used-token field is present, so context percentage indicators no longer pin to 100% on result-only snapshots.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a8ee4eab-24c5-425a-9dd0-1e98c7530e2d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels May 6, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4410cbb. Configure here.

Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts Outdated
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 6, 2026

Approvability

Verdict: Approved

Straightforward bug fix for UI token meter display. Changes are limited to normalization logic for how token usage is shown, with corresponding test updates confirming the expected behavior.

You can customize Macroscope's approvability policy. Learn more.

@amitbet amitbet changed the title Fix Claude context usage normalization for UI meter Fix Claude context usage normalization for UI meter, Fixes #2034 May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants