#18886: fix(status): prefer configured contextTokens over model metadata
channel: mattermost
commands
size: XS
Cluster:
Context Management Fixes
## Summary
When `contextTokens` is explicitly set in agent config (e.g. `1000000` for Claude Max), the status display still showed the model's built-in 200K context window instead of the configured 1M limit.
## Problem
In `status.summary.ts`, per-session context token resolution was:
```typescript
entry?.contextTokens ?? lookupContextTokens(model) ?? configContextTokens
```
The `lookupContextTokens(model)` call (returning the model catalog's 200K) took priority over `configContextTokens` (which contained the user's 1M setting).
## Solution
Extract the user's explicit `contextTokens` config and give it priority:
```typescript
entry?.contextTokens ?? explicitContextTokens ?? lookupContextTokens(model) ?? configContextTokens
```
Priority chain:
1. Per-session `contextTokens` (session-level override)
2. User's explicit `agents.defaults.contextTokens` config
3. Model's built-in context window from catalog
4. Config default (200K fallback)
## Changes
- `src/commands/status.summary.ts` — extract `explicitContextTokens` and give it priority in session resolution
## Test plan
- [x] `pnpm build` passes
- [x] Existing status redaction test passes
- [x] Manual verification: with `contextTokens: 1000000`, status should show `1000k` instead of `200k`
Closes #18696
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes the status display to prefer the user's explicitly configured `contextTokens` (e.g., 1M for Claude Max) over model catalog metadata (200K) when computing context window size for sessions. The change extracts `explicitContextTokens` from `cfg.agents?.defaults?.contextTokens` and inserts it into the per-session resolution chain with appropriate priority.
- The fix correctly addresses the reported issue where Claude Max users saw 200K instead of their configured 1M context window
- One edge case to consider: for sessions using a model different from the configured default, the global `explicitContextTokens` will override that session model's actual context window (e.g., a gpt-4o session would show 1M instead of 128K). Scoping the override to only apply when the session model matches the configured default would be more precise
- CHANGELOG entry is appropriate and well-formatted
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it fixes a clear priority bug in status display with a small, well-scoped change
- Score of 4 reflects a clean, targeted fix for a real user-facing issue. The change is minimal (two files, only logic change in one), the fallback chain is sound, and existing tests pass. Deducted one point for the edge case where mixed-model sessions could show an incorrect context window when a global contextTokens override is set.
- Minor attention on `src/commands/status.summary.ts` lines 130-135 — the `explicitContextTokens` override applies globally to all sessions regardless of their model, which may be inaccurate for mixed-model setups.
<sub>Last reviewed commit: fd3f0c9</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#18721: fix: prefer configured contextTokens over model catalog in status d...
by MisterGuy420 · 2026-02-17
87.2%
#19412: fix(status): prefer configured contextTokens over session entry
by rafaelipuente · 2026-02-17
85.4%
#17414: fix(sessions): refresh contextTokens when model override changes
by michaelbship · 2026-02-15
84.1%
#23299: fix(status): show runtime model context limit instead of stale sess...
by SidQin-cyber · 2026-02-22
84.0%
#15726: fix(sessions): use model contextWindow instead of agent contextToke...
by lailoo · 2026-02-13
82.8%
#11109: fix(tui): prefer config contextTokens over persisted session value
by marezgui · 2026-02-07
81.5%
#16478: fix(gateway): fall back to lookupContextTokens on model switch
by colddonkey · 2026-02-14
78.2%
#15126: fix(status): avoid false 100% context usage when totals mirror context
by AlexAnys · 2026-02-13
77.4%
#15632: fix: use provider-qualified key in MODEL_CACHE for context window l...
by linwebs · 2026-02-13
77.1%
#17604: fix(context): use getAvailable() to prevent cross-provider model ID...
by aldoeliacim · 2026-02-16
76.9%