From 3d00af2504a97f0189052cb189be28c242d100c2 Mon Sep 17 00:00:00 2001 From: Guy J Grigsby Date: Fri, 20 Nov 2026 21:00:59 +0000 Subject: [PATCH 1/3] internal/clients/claudecode: let Claude Code pick its model when Claude is offered A first headless `aperture claude` took the provider's first model, and on ai.corp that sorts to alibaba/qwen3.8-max. Claude Code in auto mode asks the API for server-side classification, Qwen returns none, and the session falls back to billed classifier requests with the "this session isn't eligible" notice. Once a release drops that fallback, every checked action would be prompted or denied. Taking the first Claude model instead would launch claude-haiku-4.5, an old small model, because the list is alphabetical. Leaving ANTHROPIC_MODEL unset lets Claude Code use its own current default, which Aperture resolves. Providers with no Claude model keep the first-model default. Revisit if providers advertise a preferred model, or if Claude Code's default stops resolving on some Aperture. --- internal/clients/claudecode/claudecode.go | 6 +++- .../clients/claudecode/claudecode_test.go | 33 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/internal/clients/claudecode/claudecode.go b/internal/clients/claudecode/claudecode.go index 1fbb226..d7e6c22 100644 --- a/internal/clients/claudecode/claudecode.go +++ b/internal/clients/claudecode/claudecode.go @@ -221,7 +221,11 @@ func (c *Client) resolve(g *config.Global, provider, model string) (config.Provi if model == "" && sameProvider && slices.Contains(models, last.LastModel) { model = last.LastModel } - if model == "" && len(models) > 0 { + // Claude Code picks its own default when the provider offers Claude. The + // first model sorts alphabetically and may not be Claude, and then auto + // mode's server-side classifier has nothing to answer it. + isClaude := func(m string) bool { return strings.Contains(m, "claude") } + if model == "" && len(models) > 0 && !slices.ContainsFunc(models, isClaude) { model = models[0] } return p, b, model, nil diff --git a/internal/clients/claudecode/claudecode_test.go b/internal/clients/claudecode/claudecode_test.go index 6ddf791..63f6e46 100644 --- a/internal/clients/claudecode/claudecode_test.go +++ b/internal/clients/claudecode/claudecode_test.go @@ -397,13 +397,13 @@ func TestSpec(t *testing.T) { } c := &Client{} - // Defaults: the first compatible provider, its first backend, its first model. + // Defaults: the first compatible provider, its first backend, Claude Code's own model. spec, err := c.Spec(newGlobal(), "", "", nil) if err != nil { t.Fatalf("Spec: %v", err) } - if spec.Env["ANTHROPIC_BASE_URL"] != testHost || spec.Env["ANTHROPIC_MODEL"] != "claude-opus" { - t.Errorf("default env = %v, want the Anthropic backend on its first model", spec.Env) + if _, ok := spec.Env["ANTHROPIC_MODEL"]; spec.Env["ANTHROPIC_BASE_URL"] != testHost || ok { + t.Errorf("default env = %v, want the Anthropic backend with no model set", spec.Env) } // Flags win, and passthrough args land after aperture's own. @@ -490,3 +490,30 @@ func TestSpec(t *testing.T) { t.Errorf("conflicting settings: %v, want the conflict named", err) } } + +func TestSpec_DefaultModel(t *testing.T) { + tests := []struct { + name string + models []string + want string + }{ + {name: "claude offered after a non-claude model", models: []string{"alibaba/qwen3.8-max", "anthropic/claude-haiku-4.5"}, want: ""}, + {name: "no claude offered", models: []string{"glm-5.1", "glm-5-turbo"}, want: "glm-5.1"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Setenv("HOME", t.TempDir()) + p := config.ProviderInfo{ID: "gw", Models: tt.models, SupportedEndpoints: map[string]bool{config.EndpointAnthropicMessages: true}} + g := &config.Global{ApertureHost: testHost, Providers: []config.ProviderInfo{p}} + + spec, err := (&Client{}).Spec(g, "", "", nil) + + if err != nil { + t.Fatalf("Spec: %v", err) + } + if got := spec.Env["ANTHROPIC_MODEL"]; got != tt.want { + t.Errorf("ANTHROPIC_MODEL = %q, want %q", got, tt.want) + } + }) + } +} From 19bb2f14ac708859a77a53ab837efe48af3a44ed Mon Sep 17 00:00:00 2001 From: Guy J Grigsby Date: Fri, 20 Nov 2026 21:16:33 +0000 Subject: [PATCH 2/3] internal/clients/claudecode: cover more model id shapes in the default model test --- internal/clients/claudecode/claudecode_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/clients/claudecode/claudecode_test.go b/internal/clients/claudecode/claudecode_test.go index 63f6e46..c288b7a 100644 --- a/internal/clients/claudecode/claudecode_test.go +++ b/internal/clients/claudecode/claudecode_test.go @@ -498,7 +498,14 @@ func TestSpec_DefaultModel(t *testing.T) { want string }{ {name: "claude offered after a non-claude model", models: []string{"alibaba/qwen3.8-max", "anthropic/claude-haiku-4.5"}, want: ""}, + {name: "claude offered last", models: []string{"deepseek/deepseek-v4-pro", "moonshotai/kimi-k3", "anthropic/claude-sonnet-5.5"}, want: ""}, + {name: "bare claude ids", models: []string{"claude-opus-5-5", "claude-sonnet-5-5"}, want: ""}, + {name: "claude fast variant", models: []string{"anthropic/claude-opus-5-5-fast"}, want: ""}, + {name: "bedrock inference profile", models: []string{"meta.llama4-maverick-17b-instruct-v1:0", "us.anthropic.claude-opus-4-1-20250805-v1:0"}, want: ""}, + {name: "vertex versioned id", models: []string{"gemini-3-pro", "claude-opus-4@20250514"}, want: ""}, {name: "no claude offered", models: []string{"glm-5.1", "glm-5-turbo"}, want: "glm-5.1"}, + {name: "no claude offered, prefixed ids", models: []string{"alibaba/qwen3.8-max", "deepseek/deepseek-v4-pro"}, want: "alibaba/qwen3.8-max"}, + {name: "no models", models: nil, want: ""}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 9f2863a50d0f2e98de8d82d223126a3095e46f75 Mon Sep 17 00:00:00 2001 From: Guy J Grigsby Date: Fri, 20 Nov 2026 21:16:53 +0000 Subject: [PATCH 3/3] internal/clients/claudecode: match Claude model ids case-insensitively A provider listing "Anthropic/Claude-Opus-5-5" next to "openai/gpt-5" got gpt-5 as the default, because the Claude check was case-sensitive. Aperture model ids are usually lowercase, but aliases come from operator config. --- internal/clients/claudecode/claudecode.go | 2 +- internal/clients/claudecode/claudecode_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/clients/claudecode/claudecode.go b/internal/clients/claudecode/claudecode.go index d7e6c22..12f70ed 100644 --- a/internal/clients/claudecode/claudecode.go +++ b/internal/clients/claudecode/claudecode.go @@ -224,7 +224,7 @@ func (c *Client) resolve(g *config.Global, provider, model string) (config.Provi // Claude Code picks its own default when the provider offers Claude. The // first model sorts alphabetically and may not be Claude, and then auto // mode's server-side classifier has nothing to answer it. - isClaude := func(m string) bool { return strings.Contains(m, "claude") } + isClaude := func(m string) bool { return strings.Contains(strings.ToLower(m), "claude") } if model == "" && len(models) > 0 && !slices.ContainsFunc(models, isClaude) { model = models[0] } diff --git a/internal/clients/claudecode/claudecode_test.go b/internal/clients/claudecode/claudecode_test.go index c288b7a..beb25da 100644 --- a/internal/clients/claudecode/claudecode_test.go +++ b/internal/clients/claudecode/claudecode_test.go @@ -503,6 +503,7 @@ func TestSpec_DefaultModel(t *testing.T) { {name: "claude fast variant", models: []string{"anthropic/claude-opus-5-5-fast"}, want: ""}, {name: "bedrock inference profile", models: []string{"meta.llama4-maverick-17b-instruct-v1:0", "us.anthropic.claude-opus-4-1-20250805-v1:0"}, want: ""}, {name: "vertex versioned id", models: []string{"gemini-3-pro", "claude-opus-4@20250514"}, want: ""}, + {name: "mixed case claude id", models: []string{"openai/gpt-5", "Anthropic/Claude-Opus-5-5"}, want: ""}, {name: "no claude offered", models: []string{"glm-5.1", "glm-5-turbo"}, want: "glm-5.1"}, {name: "no claude offered, prefixed ids", models: []string{"alibaba/qwen3.8-max", "deepseek/deepseek-v4-pro"}, want: "alibaba/qwen3.8-max"}, {name: "no models", models: nil, want: ""},