Skip to content

feat: support CCSTATUSLINE_CONTEXT_WINDOW_SIZE env override - #352

Merged
sirmalloc merged 3 commits into
sirmalloc:mainfrom
lmello:feat/context-window-env-override
Oct 30, 2026
Merged

sirmalloc merged 3 commits into
sirmalloc:mainfrom
lmello:feat/context-window-env-override

Conversation

@lmello

@lmello lmello commented May 1, 2026

Copy link
Copy Markdown
Contributor

Closes #345

Summary

  • Adds a CCSTATUSLINE_CONTEXT_WINDOW_SIZE env var that takes precedence over the context_window_size value Claude Code sends via the piped JSON.
  • Motivation: Claude Code hardcodes context_window_size to 200k for non-Claude models routed through custom proxies (e.g. mimo-v2.5-pro with a 1M window), so the piped value cannot be trusted for third-party models. Option 3 from the issue (fall back to model-name parsing) was avoided as it could regress Claude model users; this implements Option 2.
  • Accepts raw numbers, k/M suffixes, and underscore/comma separators: 1000000, 1M, 200k, 1_000_000, 1,000,000, 1.5M.

Implementation notes

  • Parsed result is cached at module scope keyed on the raw env string identity, so the hot-path render does not re-parse the regex on every status line refresh. Cache self-invalidates if the env var changes.
  • Regex is hoisted to a module-level constant.
  • Results rounding to under 1000 tokens are rejected (e.g. bare 1.5 would round to 2) to avoid silent misconfiguration.
  • Invalid values (empty, non-numeric, zero, negative) fall through to the existing behavior (piped value, then model-name parsing, then 200k default).

Test plan

  • bun run lint — passes
  • bun test — 1150 pass (6 new tests in model-context.test.ts covering env override precedence, suffix parsing, separators, decimals, whitespace, invalid values, and precedence over [1m] model suffix)
  • Manual: CCSTATUSLINE_CONTEXT_WINDOW_SIZE=1M with a piped payload containing context_window_size: 200000 shows the 1M window.

Claude Code hardcodes context_window_size to 200k for non-Claude models
(e.g. custom API proxies), so the piped JSON value cannot be trusted for
third-party models with larger windows. This env var takes precedence
over the piped value and accepts raw numbers, k/M suffixes, and
underscore/comma separators (e.g. 1M, 200k, 1_000_000).

The parsed result is cached at module scope keyed on the raw env string
so the hot-path render does not re-parse on every status line refresh.
Values that would round to under 1000 tokens are rejected to avoid
silent footguns like "1.5" producing a 2-token window.
@sirmalloc
sirmalloc merged commit a74aed3 into sirmalloc:main Oct 30, 2026
pcvelz added a commit to pcvelz/ccstatusline-usage that referenced this pull request Nov 2, 2026
Upstream: weekly limit timers (sirmalloc#768), prompt cache miss widgets (sirmalloc#770), context window size env override (sirmalloc#352, sirmalloc#407), windowed speed fixes (sirmalloc#769, sirmalloc#771), separator/renderer fixes (sirmalloc#773), custom-command styling (sirmalloc#775), clickable cwd links (sirmalloc#744), account email from live credentials (sirmalloc#724), cache timer reported expiry + short toggle (sirmalloc#576, sirmalloc#592), claude-status lock (sirmalloc#635, sirmalloc#772), dedup token metrics (sirmalloc#622, sirmalloc#725, sirmalloc#735).
Not adopted: sirmalloc#765 terminal width from COLUMNS with fixed reserve - the fork keeps flexMode/compactThreshold and tmux pane priority.

Hand edits outside conflicts:
- README.md: kept fork Configure flex separator behavior bullet and older-updates details wrapper; dropped upstream Related Projects additions (claude-eta)
- AGENTS.md: kept fork terminal width wording (sirmalloc#765 not adopted)
- src/types/FlexMode.ts, src/tui/components/TerminalWidthMenu.tsx, src/tui/components/__tests__/TerminalWidthMenu.test.ts, src/tui/components/TerminalOptionsMenu.tsx, src/tui/components/__tests__/TerminalOptionsMenu.test.ts: restored, fork keeps terminal width settings
- src/tui/App.tsx, src/tui/components/index.ts, src/types/index.ts: re-wired terminal width menu and FlexMode export
- src/types/StatusJSON.ts: dropped fork duplicate prompt_cache key, upstream schema is a superset
- src/utils/terminal.ts: COLUMNS source gated on non-tmux so tmux pane width keeps priority
- src/widgets/WeeklyLimitTimer.ts, src/utils/usage-prefetch.ts, src/widgets/__tests__/WeeklyLimitTimer.test.ts: compat fix - fableUsage/fableResetAt -> weeklyFableUsage/weeklyFableResetAt
- src/widgets/ApiUsage.tsx: compat fix - Context Bar honors effective context window (override, clamp, 1.0M format); Weekly renders a valid value despite a session error
- src/widgets/__tests__/ApiUsage.localModelFallback.test.ts: output tokens no longer counted in context (upstream sirmalloc#730)
- src/utils/__tests__/renderer-flex-width.test.ts, src/utils/__tests__/renderer-ansi.test.ts, src/utils/__tests__/gradient.test.ts, src/utils/__tests__/renderer-separator-collapse.test.ts, src/utils/__tests__/config.test.ts, src/tui/__tests__/App.test.ts: fork deviation - fork width model (flexMode, 6-column full reserve, kept settings, Terminal Width menu entry)
- src/utils/__tests__/default-colors.test.ts: fork deviation - accept ansi256:/hex: defaults
- src/utils/__tests__/usage-prefetch.test.ts: fork deviation - weekly usage comes from the API, fork widget imports from ApiUsage
- src/widgets/__tests__/CurrentWorkingDir.test.ts, src/widgets/__tests__/CustomCommand.test.ts: Settings literal gains flexMode/compactThreshold
- src/utils/__tests__/context-window.test.ts, src/utils/__tests__/jsonl-metrics.test.ts: restored fork tests upstream dropped
- docs/test-retirements.md: ledger for the dev-reload snapshot-path and RemoteControlStatus glyph (sirmalloc#605) tests upstream replaced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add user-configurable context window size override for non-Claude models

2 participants