fix(claude): seed local-mode context window from the configured model (#1858) (#2088)

* fix(claude): seed local-mode context window from the configured model (#1858)

Local transcripts carry bare model ids and no usage.context_window, so
local Opus/Sonnet [1m] sessions fell back to the web's 200k heuristic
(190k denominator). At local launch, resolve the model Claude Code
starts with (--model, ANTHROPIC_MODEL, project local/project/user
settings) with its [1m] suffix intact, and stamp a 1M context_window on
assistant messages from that model. Subagent models are left alone.
Register PostModelSwitch in the local hook settings so /model switches
inside the TUI update the seed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(claude): honor --model and --setting-sources when seeding the local context window (#1858)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SSU-WEI HUANG
2026-10-26 10:00:12 +08:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 6b3912dc56
commit 6bf0a633bb
8 changed files with 159 additions and 6 deletions
@@ -13,6 +13,7 @@ describe('buildHookSettings', () => {
expect(settings.hooks.UserPromptSubmit?.[0].hooks[0].command).toBe('forward-cmd')
expect(settings.hooks.PreToolUse?.[0].matcher).toBe('*')
expect(settings.hooks.PreToolUse?.[0].hooks[0].command).toBe('forward-cmd')
expect(settings.hooks.PostModelSwitch?.[0].hooks[0].command).toBe('forward-cmd')
})
})
@@ -25,6 +25,7 @@ type HookSettings = {
UserPromptSubmit?: HookCommandConfig[];
PreToolUse?: HookCommandConfig[];
PermissionRequest?: HookCommandConfig[];
PostModelSwitch?: HookCommandConfig[];
PostToolUse?: HookCommandConfig[];
PostToolUseFailure?: HookCommandConfig[];
SessionEnd?: HookCommandConfig[];
@@ -38,8 +39,9 @@ export type HookSettingsOptions = {
/**
* Also forward UserPromptSubmit and PreToolUse hooks. Unlike SessionStart,
* their payloads carry `permission_mode`, letting HAPI track the mode the
* user picks inside the interactive TUI (shift+tab). Keep this off for the
* remote SDK process: these hooks block Claude while the forwarder runs,
* user picks inside the interactive TUI (shift+tab). PostModelSwitch
* tracks /model switches for the local context window. Keep this off for
* the remote SDK process: these hooks block Claude while the forwarder runs,
* and remote permission state is owned by the hub/RPC path anyway.
*/
trackPermissionMode?: boolean;
@@ -67,6 +69,7 @@ export function buildHookSettings(
if (trackPermissionMode || includeLocalPermissions) {
hooks.UserPromptSubmit = [commandHook];
hooks.PreToolUse = [{ matcher: '*', ...commandHook }];
hooks.PostModelSwitch = [commandHook];
}
if (includeLocalPermissions) {