Skip to content

Add context_window override so the prompt %/compaction follow it live#137

Merged
chauncygu merged 1 commit into
mainfrom
context-window-config
Jun 4, 2026
Merged

Add context_window override so the prompt %/compaction follow it live#137
chauncygu merged 1 commit into
mainfrom
context-window-config

Conversation

@chauncygu
Copy link
Copy Markdown
Contributor

The prompt's context-usage % and the compaction trigger derive from the model's context window, which previously could only be a hardcoded provider default — and max_tokens (the OUTPUT cap) does not change it. Add a dedicated, session-settable override.

  • cc_config.py: new DEFAULTS key context_window (0 = use the model default).
  • providers.context_window_override(config): single source that parses the override (positive int wins; 0/unset/negative/non-numeric/bool -> 0).
  • compaction.get_context_limit(): honors the override, kept distinct from max_tokens. Bidirectional — smaller forces earlier compaction, larger corrects a stale default.
  • providers.py send paths: apply the same override to the per-call output-cap window (dynamic_cap_max_tokens) so %, compaction, and the cap stay consistent. No-op when unset, so existing behavior is unchanged.
  • /config context_window=: warns when it exceeds the model's real window (disables compaction -> API may reject oversized prompts) and notes it takes effect on the next prompt (no restart).

Read live each prompt, so changing model or context_window updates the % with no restart. Tests cover parsing, both-direction overrides, and that max_tokens is never read as the context window.

The prompt's context-usage % and the compaction trigger derive from the
model's context window, which previously could only be a hardcoded provider
default — and max_tokens (the OUTPUT cap) does not change it. Add a dedicated,
session-settable override.

- cc_config.py: new DEFAULTS key context_window (0 = use the model default).
- providers.context_window_override(config): single source that parses the
  override (positive int wins; 0/unset/negative/non-numeric/bool -> 0).
- compaction.get_context_limit(): honors the override, kept distinct from
  max_tokens. Bidirectional — smaller forces earlier compaction, larger
  corrects a stale default.
- providers.py send paths: apply the same override to the per-call output-cap
  window (dynamic_cap_max_tokens) so %, compaction, and the cap stay consistent.
  No-op when unset, so existing behavior is unchanged.
- /config context_window=<N>: warns when it exceeds the model's real window
  (disables compaction -> API may reject oversized prompts) and notes it takes
  effect on the next prompt (no restart).

Read live each prompt, so changing model or context_window updates the % with
no restart. Tests cover parsing, both-direction overrides, and that max_tokens
is never read as the context window.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chauncygu chauncygu merged commit eeaa2e9 into main Jun 4, 2026
6 checks passed
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.

1 participant