Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

launch: add compact window for claude code (#14823)

Parth Sareen347f17b8d18e
diff --git a/cmd/launch/claude.go b/cmd/launch/claude.go
index 19ef49b01..3ed53cd1f 100644
--- a/cmd/launch/claude.go
+++ b/cmd/launch/claude.go
@@ -6,6 +6,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
+ "strconv"
"github.com/ollama/ollama/envconfig"
)
@@ -68,10 +69,18 @@ func (c *Claude) Run(model string, args []string) error {
// modelEnvVars returns Claude Code env vars that route all model tiers through Ollama.
func (c *Claude) modelEnvVars(model string) []string {
- return []string{
+ env := []string{
"ANTHROPIC_DEFAULT_OPUS_MODEL=" + model,
"ANTHROPIC_DEFAULT_SONNET_MODEL=" + model,
"ANTHROPIC_DEFAULT_HAIKU_MODEL=" + model,
"CLAUDE_CODE_SUBAGENT_MODEL=" + model,
}
+
+ if isCloudModelName(model) {
+ if l, ok := lookupCloudModelLimit(model); ok {
+ env = append(env, "CLAUDE_CODE_AUTO_COMPACT_WINDOW="+strconv.Itoa(l.Context))
+ }
+ }
+
+ return env
}
diff --git a/cmd/launch/claude_test.go b/cmd/launch/claude_test.go
index 689415b44..bdfa8ecbb 100644
--- a/cmd/launch/claude_test.go
+++ b/cmd/launch/claude_test.go
@@ -131,6 +131,9 @@ 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"])
+ }
})
t.Run("supports empty model", func(t *testing.T) {
@@ -147,5 +150,22 @@ 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"])
+ }
+ })
+
+ 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("does not set auto compact window 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"])
+ }
})
}