fix(context-timeline): detect Opus 1M context window dynamically#548
Merged
davila7 merged 1 commit intoApr 28, 2026
Merged
Conversation
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).
|
@mario-hernandez is attempting to deploy a commit to the Daniel Avila's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
👋 Thanks for contributing, @mario-hernandez!This PR touches What happens next
While you wait
This is an automated message. No action is required from you right now — a maintainer will review soon. |
davila7
approved these changes
Apr 28, 2026
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.
Problem
CONTEXT_LIMITis hardcoded to200_000tokens incontext-timeline.py. Users on Claude Opus 4.7 with the 1M context window ("model": "opus[1m]"in~/.claude/settings.json) see the dashboard report 80–90% usage when actual usage is 16–18%, producing constant false alarms and making the meter unusable on long sessions.Fix
Replace the constant with
_detect_context_limit(cwd)which resolves the limit in this order:CONTEXT_TIMELINE_LIMITenv var — explicit override (e.g.export CONTEXT_TIMELINE_LIMIT=500000).[1m]/[1000k]/[200k]suffix in themodelfield of<cwd>/.claude/settings.jsonor~/.claude/settings.json.200_000fallback — current behaviour, untouched for users without[1m].The limit is resolved once per
_Builderinstance, not per update tick — zero per-event filesystem cost.Backwards compatibility
[1m]in settings.Verification
Tested live on a real Opus 1M session of ~178K tokens:
Resolution order also unit-tested:
int(env).claude/settings.jsonwith[1m]→1_000_000~/.claude/settings.jsonwith[1m]→1_000_000200_000Files changed
cli-tool/components/hooks/monitoring/context-timeline.py(+44, −8)Summary by cubic
Fixes incorrect context-usage reporting by dynamically detecting the model’s context window, so Opus 1M sessions show accurate percentages instead of false alarms. Replaces the hardcoded 200k limit with a detected value.
cli-tool/components/hooks/monitoring/context-timeline.py)._detect_context_limit(cwd): env varCONTEXT_TIMELINE_LIMIT→[1m]/[1000k]/[200k]in.claude/settings.json→200_000fallback.docs/components.jsonregeneration needed.CONTEXT_TIMELINE_LIMIT(int). No secrets.Written for commit 6c3750a. Summary will update on new commits. Review in cubic