Skip to content

fix: fill context bar against soft limit, reconcile token figure#62

Merged
tmck-code merged 2 commits into
mainfrom
fix/context-bar-soft-limit-fill
Jun 5, 2026
Merged

fix: fill context bar against soft limit, reconcile token figure#62
tmck-code merged 2 commits into
mainfrom
fix/context-bar-soft-limit-fill

Conversation

@tmck-code
Copy link
Copy Markdown
Owner

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-supplied used_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 the soft_limit argument became dead code inside _ctx_fill_ratio.

A second, related inconsistency: the bar's displayed token figure used total_input_tokens while the fill came from used_percentage, so the number and the fill could disagree (e.g. 428 shown next to an 11%-filled bar).

Changes

  • Restore soft-limit-relative fill while keeping f514d3a's improvement (host-accurate, input-only token count). _ctx_fill_ratio now converts used_percentage back to an absolute count via context_window_size, then divides by soft_limit. Reaches 100% at the soft limit again; the window-headroom figure stays as the parenthetical (N%).
  • Reconcile the displayed figure with the fill. New _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 host used_percentage rescaled to the window; falls back to total_input_tokens; clamps to >= 0; excludes output tokens.
  • Docs: updated 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.
  • Snapshots: regenerated the three claude-dark golden fixtures (fill shifted 8%->11% on the example; wide figure now 16.0K).

Checklist

  • Tests added or updated for new/changed behaviour
  • (bug fixes) a regression test now covers the situation so it can't come back

Screenshots / recording

Before After

Benchmark

Command Mean [ms] Min [ms] Max [ms] Relative
main 65.6 ± 1.6 62.2 70.3 1.00
PR 68.6 ± 4.9 64.2 99.3 1.05 ± 0.08

Within noise — the PR adds only one small helper call; the 1.05x reflects outliers (PR σ 4.9ms, max 99ms).

System info

Key Value
OS Linux archlinux 7.0.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 23 May 2026 14:21:20 +0000 x86_64 GNU/Linux
Claude Code 2.1.165 (Claude Code)
Terminal TERM=tmux-256color TERM_PROGRAM=tmux SHELL=/bin/bash COLORTERM=truecolor
Locale LANG=en_AU.UTF-8 LC_ALL=
Python Python 3.13.1
uv uv 0.11.14 (x86_64-unknown-linux-gnu)

🤖 Generated with Claude Code

Test and others added 2 commits June 6, 2026 03:58
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>
@tmck-code tmck-code marked this pull request as ready for review June 5, 2026 18:01
@tmck-code tmck-code merged commit 46bd1af into main Jun 5, 2026
6 checks passed
@tmck-code tmck-code deleted the fix/context-bar-soft-limit-fill branch June 5, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant