← Back to PRs

#18886: fix(status): prefer configured contextTokens over model metadata

by BinHPdev open 2026-02-17 05:08 View on GitHub →
channel: mattermost commands size: XS
## 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