Files
Mario Hernandez 262da50f98 fix(context-timeline): detect Opus 1M context window dynamically (#548)
CONTEXT_LIMIT was hardcoded at 200_000 tokens. Users on Claude Opus 4.7
with the 1M context window (model: "opus[1m]") saw the dashboard report
80–90% usage when actual usage was 16–18%, producing constant false
alarms and making the meter unusable on long sessions.

Replace the constant with _detect_context_limit(cwd) which resolves the
limit in this order:

1. CONTEXT_TIMELINE_LIMIT env var (explicit override).
2. "[1m]" / "[1000k]" / "[200k]" suffix in the model field of
   <cwd>/.claude/settings.json or ~/.claude/settings.json.
3. 200_000 fallback (current behaviour).

The limit is resolved once per _Builder instance, not per update tick,
so there is no per-event filesystem cost.

No new dependencies (still stdlib only). Default behaviour is unchanged
for users without [1m] in settings.

Verified live on a real Opus 1M session of ~178K tokens: meter went
from 89% (red, false alarm) to 17.9% (cyan, correct).
2026-04-27 20:10:27 -04:00
..