Repository navigation
fix: filter all-zero context_window frames to prevent Context Bar 0k flash - #371
Closed
KorenKrita wants to merge 1 commit into
Closed
KorenKrita wants to merge 1 commit into
KorenKrita wants to merge 1 commit into
Conversation
Owner
|
@KorenKrita Was this fixed upstream in Claude Code or is it still a valid issue? |
Contributor
Author
|
@sirmalloc The issue is still present. #370 and #425 fix the same root cause (transient all-zero Compared to the compaction counter miscount, the Context Bar flash is admittedly less impactful (cosmetic flicker rather than incorrect data), but the bug is still there. If you'd like to merge this fix, feel free to reopen — I can rebase onto the latest main. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Claude Code occasionally emits transient
context_windowstatus JSON frames where all usage fields are zero mid-session:{ "context_window_size": 200000, "total_input_tokens": 0, "total_output_tokens": 0, "current_usage": { "input_tokens": 0, "output_tokens": 0, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0 }, "used_percentage": 0, "remaining_percentage": 100 }These all-zero frames cause the Context Bar widget to briefly flash
0k/200k (0%)before the next valid frame restores the correct display. WithrefreshInterval: 10, the statusline polls frequently enough to sample these intermediate frames.Observed in practice: a burst of 7-30 consecutive all-zero frames within a single second, all with identical zero content, while the actual session has ~111k tokens in use.
Solution
Filter all-zero usage frames at the data source layer in
getContextWindowMetrics(). Whenused_percentage === 0ANDusedTokensis 0 or null, returnnullfor all usage fields (usedTokens,contextLengthTokens,usedPercentage,remainingPercentage,cachedTokens,totalTokens). KeepwindowSize,totalInputTokens, andtotalOutputTokensintact since those are independently valid.When the Context Bar widget receives
nullforcontextLengthTokens, it falls through totokenMetrics.contextLength(parsed from the session transcript JSONL file), which contains the real token count. This eliminates the 0k flash without any caching or state management overhead.Why this approach
context-window.tsused_percentageis 0 butcurrent_usage.input_tokens > 0, the data is preserved (not a true all-zero frame)Test plan
current_usageobject, scalarcurrent_usage=0, and non-zero usage withused_percentage=0