provider: reading Claude Code's settings while routed takes the stashed tier models with it
What changed: when Claude Code's settings.json points at the gateway, readClaudeSettings swaps in what routing stashed. It took the endpoint, token and main model but left the claude.env.<VAR> keys behind — the tier models (ANTHROPIC_DEFAULT_*_MODEL), ANTHROPIC_SMALL_FAST_MODEL and CLAUDE_CODE_SUBAGENT_MODEL that routing set aside with them (internal/agent/claude.go, "back with it when magpie steps out"). The import entry then offered only the main model where stepping out would have restored six more. The claude.env.* keys now come back with the three, as Disconnect would put them. Run: go test -tags nogui -run 'TestClaudeImportWhileRoutedTakesTheStashedEnv|TestClaudeConfigDirImport|TestImport' ./internal/provider/ green; the new test red on the parent (models [claude-sonnet-5] miss claude-sonnet-5-x); gofmt -l clean; go vet and build green on darwin (nogui), linux (nogui) and windows. Not run: the GUI suite; trayimage cgo and ld warnings on darwin are known noise. Generated-by: GLM-5.3-Flash (ZCode)
This commit is contained in:
@@ -528,7 +528,16 @@ func readClaudeSettings(path string) ([]AppImport, error) {
|
||||
if b, err := os.ReadFile(filepath.Join(filepath.Dir(Path()), "stash.json")); err == nil {
|
||||
json.Unmarshal(b, &st)
|
||||
}
|
||||
// what routing put aside is what stepping out would put back:
|
||||
// the endpoint, token and main model, and with them the
|
||||
// models of the user's own the tiers and subagents ran on
|
||||
// (claude.env.<VAR>, internal/agent/claude.go)
|
||||
env = map[string]any{"ANTHROPIC_BASE_URL": st["claude.base_url"], "ANTHROPIC_AUTH_TOKEN": st["claude.auth_token"], "ANTHROPIC_MODEL": st["claude.model"]}
|
||||
for k, v := range st {
|
||||
if name, ok := strings.CutPrefix(k, "claude.env."); ok && v != "" {
|
||||
env[name] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
base, _ := env["ANTHROPIC_BASE_URL"].(string)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -509,3 +510,49 @@ func TestGeminiURLIsItsHost(t *testing.T) {
|
||||
t.Fatalf("the relay's import entry: %+v", it)
|
||||
}
|
||||
}
|
||||
|
||||
// While magpie routes Claude Code, its settings.json points at the
|
||||
// gateway and what the user had there stands by in the stash. The import
|
||||
// reads the stash back as magpie stepping out would put it back: the
|
||||
// tier and subagent models beside the endpoint, token and main model.
|
||||
func TestClaudeImportWhileRoutedTakesTheStashedEnv(t *testing.T) {
|
||||
isolate(t)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
t.Setenv("MAGPIE_ADDR", "127.0.0.1:49999")
|
||||
path := claudeSettingsPath()
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// routed: magpie wrote its own address and key over the user's relay
|
||||
if err := os.WriteFile(path, []byte(`{"env":{"ANTHROPIC_BASE_URL":"http://127.0.0.1:49999","ANTHROPIC_AUTH_TOKEN":"sk-magpie"}}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(Path()), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stash := map[string]string{
|
||||
"claude.base_url": "https://relay.example.com/anthropic",
|
||||
"claude.auth_token": "sk-claude",
|
||||
"claude.model": "claude-sonnet-5",
|
||||
"claude.env.ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-x",
|
||||
"claude.env.ANTHROPIC_SMALL_FAST_MODEL": "claude-haiku-x",
|
||||
}
|
||||
b, _ := json.Marshal(stash)
|
||||
if err := os.WriteFile(filepath.Join(filepath.Dir(Path()), "stash.json"), b, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
it := itemsOf(t, "claude-code")["settings"]
|
||||
if it.Skip != "" || it.Provider.Key != "sk-claude" {
|
||||
t.Fatalf("the relay in the stash: %+v", it)
|
||||
}
|
||||
for _, m := range []string{"claude-sonnet-5", "claude-sonnet-5-x", "claude-haiku-x"} {
|
||||
if !slices.Contains(it.Provider.Models, m) {
|
||||
t.Fatalf("models %v miss %s", it.Provider.Models, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user