Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(context): report effective window (200k default, 1M only for [1m]) instead of Models-API capability

enesf5c341205ce8
diff --git a/src/main/model-window.ts b/src/main/model-window.ts
index 2a5c585eb..ebcac2546 100644
--- a/src/main/model-window.ts
+++ b/src/main/model-window.ts
@@ -1,67 +1,32 @@
-// Resolves a Claude model id → its context window (max input tokens).
-// Precedence: in-memory cache → Anthropic Models API (max_input_tokens) → static table
-// → 200k default. Runs in the main process; reuses the OAuth token from claude-usage.
-import { resolveClaudeAccessToken } from './claude-usage'
+// Resolves a Claude model id → its EFFECTIVE context window (max input tokens).
+//
+// Claude Code's effective window is 200k by default and 1M only for extended-context
+// ("[1m]") models — the same default ccstatusline and Claude Code's own status line use.
+// The Anthropic Models API's max_input_tokens reports the model's *capability* (1M for
+// opus/sonnet), not the session's *effective* window, so it is intentionally NOT consulted
+// here — using it understated fill ~5x. Resolution is fully synchronous (no network).
-const MODELS_URL = 'https://api.anthropic.com/v1/models/'
-const OAUTH_BETA = 'oauth-2025-04-20'
-const FETCH_TIMEOUT_MS = 8000
const DEFAULT_WINDOW = 200_000
+const LARGE_WINDOW = 1_000_000
-// Known windows from the Anthropic model catalog; substring match so dated/suffixed ids resolve.
-const STATIC: Array<[RegExp, number]> = [
- [/haiku/i, 200_000],
- [/opus|sonnet|fable|mythos/i, 1_000_000]
-]
+// Matches a "1m" extended-context marker as a standalone token anywhere in the id, e.g.
+// "[1m]", "-1m", " 1m ", or a trailing "1m". Plain ids like "claude-opus-4-8" do not match.
+const ONE_M = /(^|[^a-z0-9])1m([^a-z0-9]|$)/i
-/** Best-effort window from the static table; 200k if nothing matches. */
+/** Effective context window for a model id: 1M only for [1m] models, else 200k. */
export function staticWindowFor(model: string | null): number {
- if (model) {
- for (const [re, win] of STATIC) if (re.test(model)) return win
- }
- return DEFAULT_WINDOW
+ return model && ONE_M.test(model) ? LARGE_WINDOW : DEFAULT_WINDOW
}
-const cache = new Map<string, number>()
-const requested = new Set<string>()
-
-/** Synchronous best guess: cached API value if present, else the static table. */
+/** Synchronous best guess for the model's window (no cache/network needed). */
export function cachedWindowFor(model: string | null): number {
- if (model && cache.has(model)) return cache.get(model) as number
return staticWindowFor(model)
}
/**
- * Resolve a model's window from the Models API and cache it. Fired once per model id
- * (self-gates on cache/requested). On any failure, caches the static-table value so we
- * don't refetch every tick. Never throws.
+ * Kept only for call-site compatibility with context-tail.ts. Window resolution is now fully
+ * synchronous via cachedWindowFor/staticWindowFor, so there is nothing to resolve — no-op.
*/
-export async function resolveModelWindow(model: string | null): Promise<void> {
- if (!model || cache.has(model) || requested.has(model)) return
- requested.add(model)
- let resolved = staticWindowFor(model)
- try {
- const token = await resolveClaudeAccessToken()
- if (token) {
- const ctrl = new AbortController()
- const t = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS)
- const res = await fetch(MODELS_URL + encodeURIComponent(model), {
- signal: ctrl.signal,
- cache: 'no-cache',
- headers: {
- authorization: `Bearer ${token}`,
- 'anthropic-beta': OAUTH_BETA,
- 'anthropic-version': '2023-06-01'
- }
- }).finally(() => clearTimeout(t))
- if (res.ok) {
- const data = (await res.json()) as Record<string, unknown>
- const max = data.max_input_tokens
- if (typeof max === 'number' && max > 0) resolved = max
- }
- }
- } catch {
- // network/parse failure — keep the static fallback
- }
- cache.set(model, resolved)
+export async function resolveModelWindow(_model: string | null): Promise<void> {
+ // intentional no-op
}