Skip to content

fix(server): refresh Claude context meter after compact - #5

Closed
matsvarn wants to merge 2 commits into
mainfrom
cursor/claude-compact-meter-fallback-4df3
Closed

matsvarn wants to merge 2 commits into
mainfrom
cursor/claude-compact-meter-fallback-4df3

Conversation

@matsvarn

Copy link
Copy Markdown
Owner

After Claude /compact, the composer context meter stayed at the pre-compaction value (and could snap back to full) because compact boundaries with missing post_tokens never emitted thread.token-usage.updated, and later task_progress events ratcheted usedTokens from cumulative total_tokens.

This refreshes the meter from getContextUsage when compact metadata is unusable, and stops task-progress from overwriting a known used-token reading.

Fixes pingdotgg#4650

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 16, 2026 18:17
…ens is missing

Claude compact_boundary events can omit or zero post_tokens, and the adapter
dropped usage updates instead of querying getContextUsage. The composer meter
then kept the pre-compaction usedTokens.

Keep the cheap post_tokens path. Fall back to the existing context-usage query
only when metadata is unusable, and emit no fabricated usage when that query
is absent or fails.

Co-authored-by: Mats Varnskühler <imMxts@users.noreply.github.com>
Task progress reports cumulative spend, often from subagents. Writing that
total into usedTokens through Math.max made the context meter unable to
drop after compact and snap back to full. Keep the last active reading and
only advance totalProcessedTokens.

Co-authored-by: Mats Varnskühler <imMxts@users.noreply.github.com>
@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Aug 16, 2026
@matsvarn matsvarn closed this Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: context meter ratchets up and never reflects /compact — task_progress writes cumulative tokens into usedTokens via Math.max

2 participants