Fix Claude context usage normalization for UI meter, Fixes #2034#2551
Fix Claude context usage normalization for UI meter, Fixes #2034#2551amitbet wants to merge 2 commits intopingdotgg:mainfrom
Conversation
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 <[email protected]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
ApprovabilityVerdict: 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. |

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:


after:
Checklist
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.usagetotals are no longer treated as context-window usage.normalizeClaudeTokenUsagenow prefers explicitly reported context-accurate fields (used_tokens/usedTokens/last_used_tokens/lastUsedTokens) and only clamps those tocontextWindow; when those fields are absent, oversizedtotal_tokensis preserved asusedTokens(andmaxTokensis omitted).On turn completion, accumulated
result.usageis 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
normalizeClaudeTokenUsagenow distinguishes between context-accurate usage (from directusedTokens/lastUsedTokensfields) and accumulated totals fromresult.usage, which can exceed the context window.usedTokensis clamped tocontextWindowandmaxTokensis included in the snapshot. When only accumulated totals exist, they are preserved unclamped andmaxTokensis omitted.ClaudeAdapter.ts, the call tonormalizeClaudeTokenUsagefor accumulatedresult.usageno longer passes acontextWindow, so those totals are never clamped.thread.token-usage.updatedevents for accumulated-only usage will no longer includemaxTokens, andusedTokensmay exceed the context window size.Macroscope summarized ee63cc2.