From c01a4decbffdbcd7c8783245e5cb71296d1766c8 Mon Sep 17 00:00:00 2001 From: megaproxy Date: Thu, 28 May 2026 23:09:15 +0100 Subject: [PATCH] Context bar: show absolute tokens, assume 1M window (% wasn't reliable) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The transcript doesn't record the 200k-vs-1M window (model id is bare, e.g. claude-opus-4-7; the [1m] in /context is display-only), so the <200k→200k guess overstated the % for 1M users (a 42k session read 21% instead of 4%). Fix: the indicator label now shows the absolute token count (accurate regardless of window), and the fill bar assumes 1M (the common case here; a 200k-only user would just see the bar read low while the token number stays correct). Co-Authored-By: Claude Opus 4.8 (1M context) --- src/lib/layout/LeafPane.tsx | 6 +++--- src/lib/usage.ts | 22 ++++++++++------------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/lib/layout/LeafPane.tsx b/src/lib/layout/LeafPane.tsx index 2e0a3ce..0cef00a 100644 --- a/src/lib/layout/LeafPane.tsx +++ b/src/lib/layout/LeafPane.tsx @@ -12,9 +12,9 @@ import { type LeafNode, resolveFontSize, type LeafShellSpec } from "./tree"; import { useOrchestration } from "./orchestration"; import { contextLabel, - contextPercent, contextColor, contextFraction, + formatTokens, } from "../../lib/usage"; import XtermPane from "../../components/XtermPane"; import type { SpawnSpec } from "../../ipc"; @@ -597,12 +597,12 @@ export default function LeafPane({ leaf }: { leaf: LeafNode }) { - {contextPercent(ctx)}% + {formatTokens(ctx.contextTokens)} )} diff --git a/src/lib/usage.ts b/src/lib/usage.ts index f4584f1..6fb2530 100644 --- a/src/lib/usage.ts +++ b/src/lib/usage.ts @@ -4,18 +4,18 @@ import type { SessionContext } from "../ipc"; -const WINDOW_STANDARD = 200_000; const WINDOW_LARGE = 1_000_000; /** - * Context-window size for a session. The transcript's model id doesn't encode - * the 200k-vs-1M variant, so we infer: a session whose prompt has already - * exceeded 200k must be running the 1M-context window. Approximate near the - * boundary, but correct for the cases that matter (a small session reads - * against 200k; a large one against 1M). + * Assumed context window. The transcript does NOT record whether a session + * runs the 200k or 1M window (the model id is bare, e.g. `claude-opus-4-7` — + * the `[1m]` that claude's /context shows is display-only), so the % can't be + * computed reliably. We assume 1M (the common case here) for the fill bar, and + * the indicator LABEL shows the absolute token count, which is accurate + * regardless of the real window — that's the figure to trust. */ -export function contextWindow(contextTokens: number): number { - return contextTokens > WINDOW_STANDARD ? WINDOW_LARGE : WINDOW_STANDARD; +export function contextWindow(_contextTokens: number): number { + return WINDOW_LARGE; } /** Fraction (0..1) of the inferred window currently occupied. */ @@ -41,9 +41,7 @@ export function formatTokens(n: number): string { return String(n); } -/** e.g. "~274k / 1M" for a tooltip. */ +/** e.g. "274k tokens · ~27% of 1M (last turn)" for a tooltip. */ export function contextLabel(s: SessionContext): string { - const w = contextWindow(s.contextTokens); - const wLabel = w >= 1_000_000 ? "1M" : "200k"; - return `~${formatTokens(s.contextTokens)} / ${wLabel}`; + return `${formatTokens(s.contextTokens)} tokens · ~${contextPercent(s)}% of 1M (last turn)`; }