Skip to content

fix(claude): apply per-model compact windows at launch - #8688

Merged
lidge-jun merged 14 commits into
lidge-jun:devfrom
Djaler:fix/claude-per-model-compact-window
Nov 18, 2026
Merged

lidge-jun merged 14 commits into
lidge-jun:devfrom
Djaler:fix/claude-per-model-compact-window

Conversation

@Djaler

@Djaler Djaler commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix compact windows when switching between gateway models with different context limits in ocx claude. The generated global compact environment variable currently overrides Claude Code's per-model settings, allowing a smaller model to inherit a threshold above its input limit.

Pass session-only modelSettings from the live context-window map instead: preserve the common default for larger models and reserve 5% headroom for smaller eligible windows. No Claude Code settings files are written. Explicit compact env, --settings, and --autocompact remain authoritative; native fallback and Desktop behavior are unchanged.

Verification

  • macOS: bun scripts/test.ts --changed=origin/dev — 1,263 tests passed.
  • TypeScript, structure checks, privacy scan, and documentation build passed.
  • Real Claude Code 2.1.323 session: switched large → smaller → large model; /context changed 829.8k → 497.8k → 829.8k without restarting.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

  • Required local validation passed; commands, results, and any full-suite exception are documented.
  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • I resolved all correct Codex and CodeRabbit findings.
  • My PR is ready for review.

🤖 Generated with Claude Code

Generate session-only modelSettings from the live context-window map so model switches use a compact window below each smaller model's input limit. Preserve the common default for larger models without writing Claude Code settings files.

Keep explicit compact environment variables, --settings and --autocompact authoritative. Leave native fallback and Desktop launch paths unchanged.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (2/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 2/4).

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

2/4 boxes ticked.

Automatic draft conversion failed. Please convert this pull request to a draft manually until every box above is ticked.

Hygiene

✅ Deterministic PR hygiene checks passed.

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete five-file change on 297659a15ba39b0f00a8360151f7fb1833cdae16 and allowed the existing matching-head Cross-platform43418263770 and Catalog43418263738 runs. The helper is pure session-only argv/environment shaping, runs only on the routed launch path, preserves explicitly supplied compact/env/settings/autocompact policy and the positional delimiter, and leaves settings files unread/unwritten. Focused new cases cover those precedence boundaries and generated smaller-model windows; docs and the owning Claude contract were updated.

The author reports a real Claude2.1.323 switching probe; I have not independently run that native client. Other Cargo workloads prevented overlapping local validation. Hosted checks must complete, and final head-bound author readiness remains unchecked/Draft. This is ordinary source/contract review plus CI permission, not native interoperability certification or an approval/merge. No live Claude session/config or scan was touched.

@lidge-jun

Copy link
Copy Markdown
Owner

Merge-manager review: modelSettings.<model>.autoCompactWindow is a real Claude Code setting, so the design holds. One blocker: the --settings JSON built in src/cli/claude-context-settings.ts (24-36, called at src/cli/claude.ts:919) has no size bound. buildClaudeContextWindows registers up to four keys per routed model, and on Windows .cmd shims go through cmd.exe with caret escaping (src/lib/win-exec.ts:79), so a few dozen models can exceed the 8,191-character command line and ocx claude stops launching. Please (1) restrict keys to selectors Claude Code can pick (the gateway.models ids plus the slots the launcher writes), (2) fall back to the existing environment-variable injection when the serialized settings exceed a conservative budget (e.g. 4,000 chars on win32), with a test for the fallback, and (3) note in the docs that --settings now takes precedence over the user's own modelSettings/autoCompactWindow (or skip injection when the user has them). Then mark ready and tick the checklist.

@lidge-jun lidge-jun added the ci:full Run the four full Ubuntu test shards on this pull request label Nov 18, 2026
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration (lidge-jun, dev-only path in MAINTAINERS.md) at head 6c773ce6b7:

  • Review: independent gpt-6.2-sol review over four rounds; final verdict APPROVE. Maintainer pushes to this branch implemented the merge-manager request and fixed each finding:
    • generated --settings keys are limited to selectors Claude Code can pick;
    • on Windows, the launcher measures the escaped command line and falls back to the pre-PR environment-variable path above 7,000 characters (55-model case: 8,286 → 3,861);
    • Remote Control verbs (remote-control, rc, bridge, remote, sync) keep the original argv and env through a conservative exact-token rule;
    • compact-window precedence is documented correctly in all nine guides.
  • Ingwannu's earlier review was on an older head; its points are covered by the current-head review.
  • CI: every PR check succeeded on this head (ci:full).
  • dev union check: 2 commits behind dev 64bfd29355 (fix(link): restore Child file integrations before shutdown #8803, feat(anthropic): report monthly usage from extra_usage when no plan window is present #8889) with no overlapping files. A local merge is clean; typecheck, structure:check, claude-cli.test.ts (116/0), layout, Spanish docs and the file-size ratchet pass.
  • NOT RUN: native Windows (PR CI has no Windows shards); the next dev batch run covers it.

@lidge-jun
lidge-jun marked this pull request as ready for review November 18, 2026 23:16
@lidge-jun
lidge-jun self-requested a review as a code owner November 18, 2026 23:16
@lidge-jun
lidge-jun merged commit 191572b into lidge-jun:dev Nov 18, 2026
32 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T23:22:18.136515Z 6c773ce Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci:full Run the four full Ubuntu test shards on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants