From c77b81c5036b593314cdf24133731ebfcede39a4 Mon Sep 17 00:00:00 2001 From: Jonathan Berg Date: Wed, 7 Oct 2026 16:09:35 -0700 Subject: [PATCH 1/2] Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to whatever the models context window is --- cmd/launch/claude.go | 6 +++++- cmd/launch/claude_test.go | 37 ++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/cmd/launch/claude.go b/cmd/launch/claude.go index 1a9700b9e..6fd116def 100644 --- a/cmd/launch/claude.go +++ b/cmd/launch/claude.go @@ -178,7 +178,11 @@ func (c *Claude) modelEnvVars(model string) []string { if isCloudModelName(model) { if l, ok := lookupCloudModelLimit(model); ok { - env = append(env, "CLAUDE_CODE_AUTO_COMPACT_WINDOW="+strconv.Itoa(l.Context)) + window := strconv.Itoa(l.Context) + env = append(env, + "CLAUDE_CODE_MAX_CONTEXT_TOKENS="+window, + "CLAUDE_CODE_AUTO_COMPACT_WINDOW="+window, + ) } } diff --git a/cmd/launch/claude_test.go b/cmd/launch/claude_test.go index 2c688ead6..4bfeeba93 100644 --- a/cmd/launch/claude_test.go +++ b/cmd/launch/claude_test.go @@ -430,6 +430,8 @@ printf '%s\n' "${CLAUDE_CODE_AUTO_MODE_SERVER-unset}" "$ANTHROPIC_DEFAULT_SONNET func TestClaudeModelEnvVars(t *testing.T) { c := &Claude{} + windowKeys := []string{"CLAUDE_CODE_MAX_CONTEXT_TOKENS", "CLAUDE_CODE_AUTO_COMPACT_WINDOW"} + envMap := func(envs []string) map[string]string { m := make(map[string]string) for _, e := range envs { @@ -453,8 +455,10 @@ func TestClaudeModelEnvVars(t *testing.T) { if got["CLAUDE_CODE_SUBAGENT_MODEL"] != "llama3.2" { t.Errorf("SUBAGENT = %q, want llama3.2", got["CLAUDE_CODE_SUBAGENT_MODEL"]) } - if got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"] != "" { - t.Errorf("AUTO_COMPACT_WINDOW = %q, want empty for local models", got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"]) + for _, key := range windowKeys { + if v, ok := got[key]; ok { + t.Errorf("%s = %q, want unset for local models", key, v) + } } }) @@ -472,22 +476,33 @@ func TestClaudeModelEnvVars(t *testing.T) { if got["CLAUDE_CODE_SUBAGENT_MODEL"] != "" { t.Errorf("SUBAGENT = %q, want empty", got["CLAUDE_CODE_SUBAGENT_MODEL"]) } - if got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"] != "" { - t.Errorf("AUTO_COMPACT_WINDOW = %q, want empty", got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"]) + for _, key := range windowKeys { + if v, ok := got[key]; ok { + t.Errorf("%s = %q, want unset", key, v) + } } }) - t.Run("sets auto compact window for known cloud models", func(t *testing.T) { - got := envMap(c.modelEnvVars("glm-5:cloud")) - if got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"] != "202752" { - t.Errorf("AUTO_COMPACT_WINDOW = %q, want 202752", got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"]) + t.Run("sets context and auto compact windows for known cloud models", func(t *testing.T) { + for model, want := range map[string]string{ + "glm-5:cloud": "202752", + "kimi-k2.6:cloud": "262144", + } { + got := envMap(c.modelEnvVars(model)) + for _, key := range windowKeys { + if got[key] != want { + t.Errorf("%s: %s = %q, want %s", model, key, got[key], want) + } + } } }) - t.Run("does not set auto compact window for unknown cloud models", func(t *testing.T) { + t.Run("does not set windows for unknown cloud models", func(t *testing.T) { got := envMap(c.modelEnvVars("unknown-model:cloud")) - if got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"] != "" { - t.Errorf("AUTO_COMPACT_WINDOW = %q, want empty", got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"]) + for _, key := range windowKeys { + if v, ok := got[key]; ok { + t.Errorf("%s = %q, want unset", key, v) + } } }) } From 0c7340b4bb3d396fb9da5cf841aaa1ef8ee318ee Mon Sep 17 00:00:00 2001 From: Jonathan Berg Date: Thu, 8 Oct 2026 10:33:11 -0700 Subject: [PATCH 2/2] respect CLAUDE_CODE_AUTO_COMPACT_WINDOW user setting --- cmd/launch/claude.go | 8 ++++---- cmd/launch/claude_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/launch/claude.go b/cmd/launch/claude.go index 6fd116def..ca96991b8 100644 --- a/cmd/launch/claude.go +++ b/cmd/launch/claude.go @@ -179,10 +179,10 @@ func (c *Claude) modelEnvVars(model string) []string { if isCloudModelName(model) { if l, ok := lookupCloudModelLimit(model); ok { window := strconv.Itoa(l.Context) - env = append(env, - "CLAUDE_CODE_MAX_CONTEXT_TOKENS="+window, - "CLAUDE_CODE_AUTO_COMPACT_WINDOW="+window, - ) + env = append(env, "CLAUDE_CODE_MAX_CONTEXT_TOKENS="+window) + if os.Getenv("CLAUDE_CODE_AUTO_COMPACT_WINDOW") == "" { + env = append(env, "CLAUDE_CODE_AUTO_COMPACT_WINDOW="+window) + } } } diff --git a/cmd/launch/claude_test.go b/cmd/launch/claude_test.go index 4bfeeba93..e89bc08ab 100644 --- a/cmd/launch/claude_test.go +++ b/cmd/launch/claude_test.go @@ -431,6 +431,7 @@ func TestClaudeModelEnvVars(t *testing.T) { c := &Claude{} windowKeys := []string{"CLAUDE_CODE_MAX_CONTEXT_TOKENS", "CLAUDE_CODE_AUTO_COMPACT_WINDOW"} + t.Setenv("CLAUDE_CODE_AUTO_COMPACT_WINDOW", "") envMap := func(envs []string) map[string]string { m := make(map[string]string) @@ -497,6 +498,18 @@ func TestClaudeModelEnvVars(t *testing.T) { } }) + t.Run("keeps the user's auto compact window but not their context window", func(t *testing.T) { + t.Setenv("CLAUDE_CODE_AUTO_COMPACT_WINDOW", "150000") + t.Setenv("CLAUDE_CODE_MAX_CONTEXT_TOKENS", "150000") + got := envMap(c.modelEnvVars("kimi-k2.6:cloud")) + if v, ok := got["CLAUDE_CODE_AUTO_COMPACT_WINDOW"]; ok { + t.Errorf("AUTO_COMPACT_WINDOW = %q, want left to the user's setting", v) + } + if got["CLAUDE_CODE_MAX_CONTEXT_TOKENS"] != "262144" { + t.Errorf("MAX_CONTEXT_TOKENS = %q, want 262144", got["CLAUDE_CODE_MAX_CONTEXT_TOKENS"]) + } + }) + t.Run("does not set windows for unknown cloud models", func(t *testing.T) { got := envMap(c.modelEnvVars("unknown-model:cloud")) for _, key := range windowKeys {