fix: fill context bar against soft limit, reconcile token figure#62
Merged
Conversation
The context bar regressed in f514d3a: it began filling from the host `used_percentage`, which is measured against the full context window (e.g. 200K) rather than the soft limit (150K). The bar only reached 100% when the real window filled, and the `soft_limit` argument became dead code inside `_ctx_fill_ratio`. Restore soft-limit-relative fill while keeping f514d3a's good part (the host-accurate, input-only token count): convert `used_percentage` back to an absolute count via `context_window_size`, then divide by the soft limit. The window-headroom figure remains the parenthetical `(N%)`. Also reconcile the displayed token figure with the fill. Previously the label showed `total_input_tokens` while the bar filled from a different source, so they could disagree. Introduce `_ctx_used_tokens` as the single source of truth — figure, fill length, colour, and `(N%)` all derive from it, so they can never drift. Update CONTEXT.md (the bar's length now tracks the soft limit, not the window) and regenerate the claude-dark golden snapshots. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Context
The context fill bar stopped filling to 100% at the soft limit. Commit
f514d3a("use used_percentage for context bar fill") switched the bar to fill from the host-suppliedused_percentage, which Claude Code measures against the full context window (e.g. 200K) rather than the soft limit (150K, the compaction-risk threshold). As a result the bar only reached 100% when the real window filled, and thesoft_limitargument became dead code inside_ctx_fill_ratio.A second, related inconsistency: the bar's displayed token figure used
total_input_tokenswhile the fill came fromused_percentage, so the number and the fill could disagree (e.g.428shown next to an 11%-filled bar).Changes
f514d3a's improvement (host-accurate, input-only token count)._ctx_fill_rationow convertsused_percentageback to an absolute count viacontext_window_size, then divides bysoft_limit. Reaches 100% at the soft limit again; the window-headroom figure stays as the parenthetical(N%)._ctx_used_tokens(ctx)helper is the single source of truth — the displayed token figure, fill length, risk-zone colour, and(N%)all derive from it, so they can never drift. Prefers hostused_percentagerescaled to the window; falls back tototal_input_tokens; clamps to >= 0; excludes output tokens.CONTEXT.md— the bar's length now tracks the soft limit (correlated with colour), window capacity shows only as(N%); added a Used Tokens glossary entry and reworked the example dialogue.claude-darkgolden fixtures (fill shifted 8%->11% on the example; wide figure now16.0K).Checklist
Screenshots / recording
Benchmark
mainPRWithin noise — the PR adds only one small helper call; the 1.05x reflects outliers (PR σ 4.9ms, max 99ms).
System info
🤖 Generated with Claude Code