agent: Claude Code's /model hides its own lineup while magpie's list is narrowed
yyhhyyyyyy on Discord picked only a routing group's models for Claude Code
on the Agents page, and Claude Code's /model still listed a model they had
not picked. Real Claude Code 2.1.316 in a sandbox HOME, with the settings
magpie writes, lists: Default, the group (as Custom Opus), Claude Code's
built-in "Fable 5.1" row, then the group as Sonnet and Haiku, then
magpie's modelPicker rows. The Fable row is Claude Code's own lineup.
magpie leaves ANTHROPIC_DEFAULT_FABLE_MODEL unset for a main model that
isn't a Fable (#2090), so Claude Code shows its own Fable there. The
gateway's /v1/models already follows the picks (CatalogFor), and Claude
Code's gateway discovery is off unless
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY is set. Neither of those is
where the row comes from.
Claude Code's documented modelPicker.replaceBuiltInOptions hides the
lineup and leaves Default and magpie's rows. In the same sandbox, the
same settings with the flag set list exactly those rows. magpie already
set the flag while "Show Claude Code's own models" is off (#4548). It now
also sets it while Claude Code's list leaves out some of magpie's
catalog: only the picked models, some taken out one by one, or a
visibility of families (claudeNarrowed, CatalogFor's hidden list). A
change to the picks already rewrites settings.json through
catalog.Touched and Sync.
The user's own values:
- A user's ANTHROPIC_CUSTOM_MODEL_OPTION, in the settings env or the
shell, keeps the lineup. The flag would hide that row too.
- availableModels was not used. It also hid the Fable row in the
sandbox, but it is the user's key, it blocks --model, and it is meant
for enforcement.
Run at this head (rebased on origin/main 2503520f8), on mote:
- gofmt -l: clean.
- go vet ./..., GOOS=linux go vet -tags nogui ./... and
GOOS=windows go vet ./...: ok.
- go test -tags nogui -timeout 45m ./...: internal/agent ok, along with
84 packages. Three packages are red, all on main and filed:
- internal/settingsapi TestKeysAreWhatTheSaveWrites and
internal/cli TestSettingsCLISetsWhatTheWindowSaves (trayNoNumber,
#4793);
- internal/cli TestEveryRouteHasACommandOrIsNamed (/api/quit, #4794);
- internal/gui TestRestartHandsTheGatewayOver (#4167, #4107).
Broken by hand:
- On the old claude.go, TestClaudePickerNarrowedListReplacesLineup fails:
"glm-5 taken out: ... replaceBuiltInOptions=false".
- With the custom-option guard forced off, it fails on the user's
ANTHROPIC_CUSTOM_MODEL_OPTION step.
Not tried:
- A real magpie writing settings.json for the real Claude Code. The
sandbox used hand-written settings of the same shape, with the base URL
on an unused port and no sign-in.
- Claude Code in WSL. claude@wsl takes the same writePicker path.
No GUI file is touched, so no GUI run.
This commit is contained in:
@@ -113,7 +113,7 @@ something else shows up as drift.
|
||||
- Claude Code takes one window (`CLAUDE_CODE_MAX_CONTEXT_TOKENS`, `claudeContextEnv` in [`claude.go`](../../internal/agent/claude.go)) for every model it doesn't know. Claude Code alone on magpie is told its main model's (`claudeWindow`), and a model picked in its `/model` (magpie's `modelPicker`) runs at that one value. Beside a main that is one of Claude's own models (or a group of them), with no tier that isn't, nothing is told, so a model picked there ran at Claude Code's own 200K: a routing group of a 500K GPT and a 1M Claude did (young02036 on Discord). Then (`pickerApart`) the `/model` rows (`pickerRefs`) count as tiers do in the layout below. While Claude Desktop is on magpie too, its Code tab runs Claude Code on the same `~/.claude/settings.json` with every model Desktop lists, so magpie tells it the largest window of those and of Claude Code's own models (its main, tiers and `/model` rows), and holds each model below it to its own with `modelSettings.<id>.autoCompactWindow` (`claudePlan` in [`claude_budget.go`](../../internal/agent/claude_budget.go), #2025: the least held a 1M model to 131K). A model handed by a `[1m]` id (Desktop's under `DesktopLongest`, or Claude Code's own) counts by its 1M too, so it still runs at 1M when Claude Code stops taking the id for 1M (the 1M beta turned away once, `CLAUDE_CODE_DISABLE_1M_CONTEXT`); left out, a 1M model beside a 272K GPT was told 272K (dumplings on Discord). Claude Code 2.1.296 matches that key by the id it was handed, lowercased and without `[1m]`; it comes before the top-level `autoCompactWindow`, which serves a model without one. `CLAUDE_CODE_AUTO_COMPACT_WINDOW` would take precedence over both, so in this mode magpie's working window goes in the top-level `autoCompactWindow` instead, and an entry is written only where a model's window or its own threshold differs from what it would run at without one. magpie's entries and top-level value are stashed (`claude.model_budgets`, `claude.compact_default`) and go when Desktop leaves magpie; the user's own entries, top-level value and variables stay, a user's entry past its model's window (or `auto`) holds the largest to that window, and with a `CLAUDE_CODE_AUTO_COMPACT_WINDOW` of the user's the least window is told as before. A Code tab session whose environment host is WSL runs on the distro's Claude Code, which reads `${CLAUDE_CONFIG_DIR:-$HOME/.claude}` there (Desktop 4.29.0's remote probe) and not Windows' file, so each `claude@wsl:<distro>` is told the same while Windows' Desktop is on magpie (`desktopOn`), on magpie itself or not; it read 200K for a 500K group before (young02036 on Discord).
|
||||
- Claude Code is told what each of magpie's models can do in `CLAUDE_CODE_MODEL_CAPABILITIES` (`claudeCapsEnv`, `claudeCapabilities` in [`claude.go`](../../internal/agent/claude.go)): `<model>=effort[,xhigh_effort][,max_effort]` for those it is shown, and, while Claude Desktop is on magpie, for Desktop's `mythos-magpie-<number>` ids its Code tab hands it. A Claude model Claude Code knows gets no more than Claude Code gives it (Opus and Sonnet 4.6: no xhigh), and one with no known levels isn't named. A model that reaches max without xhigh (GLM-5.3 at low/high/max, DeepSeek V4 at high/max) is said to have xhigh too: the gateway runs xhigh at max for it (`fitEffort`), and Claude Code 2.1.299 turns Ultracode down without `xhigh_effort` ("Ultracode isn't available on …"), which in Desktop is the Ultracode level and dynamic workflows (leesunrise2364 on Discord; `TestClaudeModelCapabilities`). A value of the user's is left alone.
|
||||
- MiniMax Code takes a model ref with one slash in the whole (a SubAgent's `model` must match `^[^/\s]+\/[^/\s]+$`, #1387), and magpie's refs there are `custom_provider:magpie/<model>`. So a model under `custom_provider.magpie` is written with `~` for each slash of its catalog id (`bb-codex~gpt-6.1-sol`, `provider.FlatID`), only when that spelling stands for one served id (`provider.Flattened`); the gateway takes it back. A config an older magpie wrote moves over on the next sync: the user's keys on a model go to its new key, `defaultModel`, `defaultLightModel` and `memory.captureModel`/`consolidationModel` follow (`mcodeRefs`), and the slashed key stays, switched off (`enabled: false`), so a session begun on it still resumes. magpie never edits the user's own `agents/<name>/agent.md`. No other agent was found with this limit ([`minimax.go`](../../internal/agent/minimax.go)).
|
||||
- Claude Code's `/model` list (`modelPicker` in its settings.json) is magpie's while it is marked in the stash (`claude.model_picker`, `claude@wsl:<distro>.model_picker` for a WSL distro) or while every row's description ends "via magpie", as every row magpie writes does (`magpiesPicker` in [`claude.go`](../../internal/agent/claude.go)). magpie keeps its own list up to date on every model set and `Sync`, and removes it when Claude Code is taken off magpie; a list the user wrote is left alone. The fingerprint covers a list whose mark an older magpie's stash lost, which otherwise stayed without every model added since (#2046).
|
||||
- Claude Code's `/model` list (`modelPicker` in its settings.json) is magpie's while it is marked in the stash (`claude.model_picker`, `claude@wsl:<distro>.model_picker` for a WSL distro) or while every row's description ends "via magpie", as every row magpie writes does (`magpiesPicker` in [`claude.go`](../../internal/agent/claude.go)). magpie keeps its own list up to date on every model set and `Sync`, and removes it when Claude Code is taken off magpie; a list the user wrote is left alone. The fingerprint covers a list whose mark an older magpie's stash lost, which otherwise stayed without every model added since (#2046). The list sets `replaceBuiltInOptions` (only Default and magpie's rows, Claude Code's own lineup hidden) while Show Claude Code's own models is off (`provider.OwnModelsHidden`) and also while Claude Code's list leaves out some of magpie's catalog (`claudeNarrowed`: only the picked models, some taken out, or a visibility of families). Without it Claude Code 2.1.316 still listed its built-in Fable row beside a list narrowed to one routing group, since magpie leaves that tier unset (yyhhyyyyyy on Discord). A user's own `ANTHROPIC_CUSTOM_MODEL_OPTION` (settings env or shell) keeps the lineup, as the flag would hide that row too (`TestClaudePickerNarrowedListReplacesLineup`).
|
||||
- Claude Code 2.1.296 reads a Claude model whose version has a dot (`relay/claude-opus-4.6-us`) as Claude Opus 4: a retired warning, budget thinking, 32000 output tokens, no effort. With dashes (`relay/claude-opus-4-6-us`) it knows the model (misteer_ti. on Discord). So every model magpie writes into its settings (`model`, the tier envs, `ANTHROPIC_SMALL_FAST_MODEL`, `CLAUDE_CODE_SUBAGENT_MODEL`, `CLAUDE_CODE_AUTO_MODE_MODEL`, `modelPicker`), T3 Code's Claude slugs and Claude Desktop's Code-tab ids (`claudeLooking`) spell a dotted Claude version with dashes (`provider.ClaudeSpelled`), only when that spelling stands for one served id. A Claude model listed to Desktop with reasoning levels is given as `magpie-<n>.anthropic.<model>`, its dotted version dashed as well (`claudeModel`: Copilot's `claude-opus-5.5` is `…anthropic.claude-opus-5-5`, which Claude Code knows; it was `mythos-magpie-<n>`, an unknown model, and Haiku 4.5 got an effort Copilot refuses, #1819); a request for it is served by `<n>` alone (`aliased`), so that spelling needn't be unique. Mythos counts as Claude here too: Claude Code matches `claude-mythos-5-1` by substring, so `claude-mythos-5.1` would read as Mythos 5. Every read of those keys takes it back (`provider.ClaudeRead`: `claudeIn`'s `env`, `claudeMain`, `claudeStandInAt`), so magpie's fields, applied state and Drift keep the dotted id. The user's own values are stashed and given back as written. Values an older magpie wrote dotted are rewritten on the next Sync. Other vendors' ids are never respelled ([`claudedash.go`](../../internal/provider/claudedash.go)).
|
||||
- Codex's "subagents" field is `[agents] default_subagent_model`: only the model a subagent starts on when its lead names none in `spawn_agent` (codex-rs `core/src/agent/child_config.rs`). Unset, it isn't "same as model": the lead may still name another, so the GUI calls it the lead's pick, else the model (`leadPicks` in app.js), and its title points at the "subagent model" field.
|
||||
- Claude Code's "subagents" field is `env.CLAUDE_CODE_SUBAGENT_MODEL`. Unset, magpie writes nothing there (`writeTiers`, `setSubagent`), and Claude Code picks: the Agent tool call's model, then the subagent's own frontmatter model, then the variable, then the lead's model (Claude Code 2.1.306; the built-in Explore inherits, capped at opus). So the GUI calls unset "Claude Code's own pick" (`claudePicks` in app.js), not "same as model" (KorenKrita on Discord). Its effort is written only with a model: unset, a saved subagent effort is kept (`claude.subagent_effort` in the stash) and not applied, since writing the main model at that effort into the variable would pin every subagent to the main model (KorenKrita on Discord). A model picked later takes it. A value an older magpie wrote that way (the main model at an effort, not own) is moved into the stash and taken out of the env by `writeTiers` and Sync (`subagentFollowing`, `TestClaudeSubagentEffortNeedsAModel`). The window draws that effort at the right of the Subagents row like a tier's, disabled at Default while the model is unset (`effortBtn` in `connectPanel`, `claude-subagent-effort-row.test.cjs`); the tray panel keeps its own square.
|
||||
|
||||
@@ -985,7 +985,22 @@ func claudeIn(at place) *Agent {
|
||||
// tier rows out of /model with the built-in lineup (Claude Code
|
||||
// keeps only the Default row and the picker's own), so a tier's
|
||||
// model keeps its row then, or it would be in /model nowhere.
|
||||
replace := provider.OwnModelsHidden("claude")
|
||||
//
|
||||
// A list narrowed in magpie (only the picked models, or some taken
|
||||
// out) asks the same: the built-in lineup's rows go to magpie too
|
||||
// while Claude Code runs on it, and the one no tier names (Fable,
|
||||
// left unset for a main of no Fable) listed a model the user had
|
||||
// not picked beside the routing groups they had (yyhhyyyyyy on
|
||||
// Discord). A custom option of the user's own
|
||||
// (ANTHROPIC_CUSTOM_MODEL_OPTION), which the flag hides too, keeps
|
||||
// the lineup.
|
||||
// ownOption: the user's custom row, in settings.json's env or, for
|
||||
// this computer's Claude Code, the login shell's (a distro's
|
||||
// environment magpie can't read)
|
||||
ownOption := func() bool {
|
||||
return env(claudeCustomOptionEnv) != "" || at.spell == nil && claudeShellEnv(claudeCustomOptionEnv) != ""
|
||||
}
|
||||
replace := provider.OwnModelsHidden("claude") || claudeNarrowed() && !ownOption()
|
||||
var onTier []string
|
||||
for _, t := range claudeTiers {
|
||||
if replace {
|
||||
@@ -2966,3 +2981,16 @@ func magpiesPicker(path string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// claudeCustomOptionEnv is the one row a user adds to Claude Code's /model
|
||||
// themselves, beside its built-in lineup; replaceBuiltInOptions hides it
|
||||
// with the lineup.
|
||||
const claudeCustomOptionEnv = "ANTHROPIC_CUSTOM_MODEL_OPTION"
|
||||
|
||||
// claudeNarrowed says whether Claude Code's list leaves out some of
|
||||
// magpie's catalog: only the models picked for it, some taken out one by
|
||||
// one, or a visibility of families (provider.CatalogFor's kept list).
|
||||
func claudeNarrowed() bool {
|
||||
_, hidden := provider.CatalogFor("claude")
|
||||
return len(hidden) > 0
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// yyhhyyyyyy on Discord: Claude Code's list in magpie narrowed to a routing
|
||||
// group's models, and /model still listed others. Claude Code puts its
|
||||
// built-in lineup above a modelPicker's rows unless the picker says
|
||||
// replaceBuiltInOptions, and the lineup's Fable row (no tier names it while
|
||||
// the main model is no Fable) named a model the user hadn't picked. A list
|
||||
// narrowed in magpie, by picks or by models taken out, now says the flag as
|
||||
// the own-models switch does; one that leaves nothing out doesn't, and a
|
||||
// custom row of the user's own (ANTHROPIC_CUSTOM_MODEL_OPTION), which the
|
||||
// flag hides too, keeps the lineup.
|
||||
func TestClaudePickerNarrowedListReplacesLineup(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
shell := claudeShellEnv
|
||||
claudeShellEnv = func(string) string { return "" }
|
||||
t.Cleanup(func() { claudeShellEnv = shell })
|
||||
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-4.6", "glm-5"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(home, ".claude", "settings.json")
|
||||
writeFile(t, path, `{"theme":"dark"}`)
|
||||
|
||||
picker := func() (models []string, replace bool) {
|
||||
t.Helper()
|
||||
raw, has := edit.GetJSON(path, "modelPicker")
|
||||
if !has {
|
||||
t.Fatalf("no modelPicker\n%s", readFile(path))
|
||||
}
|
||||
var p struct {
|
||||
Options []struct {
|
||||
Model string `json:"model"`
|
||||
} `json:"options"`
|
||||
Replace *bool `json:"replaceBuiltInOptions"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(raw), &p); err != nil {
|
||||
t.Fatalf("modelPicker: %v\n%s", err, readFile(path))
|
||||
}
|
||||
for _, o := range p.Options {
|
||||
models = append(models, o.Model)
|
||||
}
|
||||
return models, p.Replace != nil && *p.Replace
|
||||
}
|
||||
sync := func() {
|
||||
t.Helper()
|
||||
if err := claude(home).Apply("model", "relay/glm-4.6"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// every model listed: Claude Code's lineup stays
|
||||
sync()
|
||||
if ms, replace := picker(); replace || len(ms) != 2 {
|
||||
t.Fatalf("nothing left out: rows %v, replaceBuiltInOptions=%v, want both rows and no flag", ms, replace)
|
||||
}
|
||||
|
||||
// one taken out: the lineup goes, the row too
|
||||
if err := provider.SetHiddenModels("claude", []string{"relay/glm-5"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sync()
|
||||
if ms, replace := picker(); !replace || len(ms) != 1 || ms[0] != "relay/glm-4.6" {
|
||||
t.Fatalf("glm-5 taken out: rows %v, replaceBuiltInOptions=%v, want [relay/glm-4.6] and the flag", ms, replace)
|
||||
}
|
||||
|
||||
// only the picked ones, glm-5 not among them: the same
|
||||
if err := provider.SetOnlyPicked("claude", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sync()
|
||||
if ms, replace := picker(); !replace || len(ms) != 1 {
|
||||
t.Fatalf("only picks: rows %v, replaceBuiltInOptions=%v, want one row and the flag", ms, replace)
|
||||
}
|
||||
|
||||
// a custom row of the user's own keeps the lineup it is shown in
|
||||
if err := edit.SetJSON(path, edit.KV{Path: "env." + claudeCustomOptionEnv, Value: "my-model"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sync()
|
||||
if _, replace := picker(); replace {
|
||||
t.Fatalf("with the user's %s: replaceBuiltInOptions set, which hides their row\n%s", claudeCustomOptionEnv, readFile(path))
|
||||
}
|
||||
if v, _ := edit.GetJSON(path, "env."+claudeCustomOptionEnv); v != "my-model" {
|
||||
t.Fatalf("the user's %s is %q now", claudeCustomOptionEnv, v)
|
||||
}
|
||||
// set in the login shell, the same
|
||||
if err := edit.DelJSON(path, "env."+claudeCustomOptionEnv); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
claudeShellEnv = func(k string) string { return map[string]string{claudeCustomOptionEnv: "my-model"}[k] }
|
||||
sync()
|
||||
if _, replace := picker(); replace {
|
||||
t.Fatalf("with the user's %s in the shell: replaceBuiltInOptions set", claudeCustomOptionEnv)
|
||||
}
|
||||
claudeShellEnv = func(string) string { return "" }
|
||||
|
||||
// every model picked again: the lineup is back
|
||||
if err := provider.SetPickedModels("claude", []string{"relay/glm-4.6", "relay/glm-5"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sync()
|
||||
if ms, replace := picker(); replace || len(ms) != 2 {
|
||||
t.Fatalf("every model picked: rows %v, replaceBuiltInOptions=%v, want both rows and no flag", ms, replace)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user