respect CLAUDE_CODE_AUTO_COMPACT_WINDOW user setting

This commit is contained in:
Jonathan Berg 2026-10-08 10:33:11 -07:00
parent c77b81c503
commit 0c7340b4bb
2 changed files with 17 additions and 4 deletions

View file

@ -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)
}
}
}

View file

@ -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 {