Claude Code in a terminal holds every subagent to one model through
CLAUDE_CODE_SUBAGENT_MODEL (its "subagents" field), and Codex through
magpie's own setting (settings.CodexSubagentModel). Claude Desktop runs
its Code tab's Claude Code with CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1,
and Claude Code 2.1.295 then ignores CLAUDE_CODE_SUBAGENT_MODEL,
CLAUDE_CODE_SUBAGENT_MODEL_FORCE and the tier variables in its settings
files ("Ignoring … this session's provider routing is managed by the
host"). The env Desktop 2.31226 builds for the Code tab has no key for it
either. So Desktop's subagents ran on the lead's model or on a tier's, and
only the tiers could be picked.
Claude Desktop's row now has a "subagent model" square, the same square
and strings as Codex's. It is magpie's setting
(settings.DesktopSubagentModel), which the gateway applies
(desktopSubagentPick):
- Only a claude-desktop request with x-claude-code-agent-id and tools is
moved: a subagent's turn. The lead's turns, the tool-less helper calls
Claude Code makes inside a subagent (on the haiku tier's model),
terminal Claude Code and every other agent stay as asked.
- It is applied after desktopTurn, the tiers and the groups. A turn
already on the model set isn't marked as moved. Route.Subagent,
Route.Model and the ledger's Requested keep the model asked for; Kind
stays empty.
- The model set must be served by its exact id (Resolve takes any model
name under a provider that is on), enabled, and allowed to a gateway key
held to some models (groupAllowed for a group). Otherwise the subagent
stays on the model asked for and the trace says why, in the reasons
Codex's subagent model already has.
- count_tokens counts on the same model.
- It is read on each request, so Desktop needn't restart. The field is
Live (a new Field flag): /api/set and `magpie <agent> <field> <value>`
leave Desktop's restart notice out after it, unless the pick connected
Desktop. Codex's subagent model is unchanged.
- The getter follows a provider renamed since it was set (RenamedRef).
The setter takes any provider/model or group/<id>, also one not served
now (a restored profile), refuses a bare name, and keeps a Desktop
alias by its catalog id. Options are shown while Desktop is on magpie.
- POST /api/settings keeps it; a stopped WSL distro's field copy keeps
Live.
- The Routing page says why a Desktop subagent was moved or kept
(subagentWhy, for a route with a subagent pick and no kind). "it is
disabled in magpie" gets its zh, zh-TW, ja and de, which Codex's kept
reason lacked as well.
- Unset, the pick costs one held settings read (no body decode, no
catalog build).
Not changed: a Desktop on another computer that reaches magpie with a
named gateway key is read as Claude Code (agentOf), so none of Desktop's
routing applies to it, this included. There is no fallback when the model
set has a smaller window than the lead's.
Verified at this head, on 20769439, under a temporary HOME with Go's
caches pinned:
- Each new test fails with the guarantee it names broken by hand (a real
FAIL, not a compile error), then passes restored. 48 Go breaks were
first run on 8f34bbcd: settings trim and bare-name refusal; setter
validation and clear; RenamedRef in the getter and in Unserved; the
exact served check and served groups; the serve pick, each guard
(agent id, tools, claude-desktop only, unset, same and resolved model);
the named id kept in Route.Model, Kind and the ledger's Requested; each
kept reason (unserved, disabled, held model, held group); groupAllowed;
the next request reading a change; the session pick kept; count_tokens;
the unset pick allocating; Live on the field, not on the tiers or on
Codex's, copied by WSL; options while unwired and wired; alias
conversion; the settings keep line; the GUI and CLI notice rules.
Re-run at this head:
- no tools guard: TestDesktopSubagentLeavesOtherRequests/helper,
`sent "m2", want m1`
- no agent-id guard: TestDesktopSubagentLeavesOtherRequests/lead,
`sent "m2", want m1`
- no count_tokens pick: TestDesktopSubagentCountTokens,
`count sent "m1" to "/v1/messages/count_tokens", want m2`
- Resolve instead of the exact served check: TestDesktopSubagentUnserved,
`fake/missing: "", want "magpie doesn't serve it now"`
- no Live rule in /api/set: TestDesktopSubagentModelNotice (gui),
`wired Live pick notice "Claude Desktop reads this at start-up …"`
- no keep line in POST /api/settings: TestSettingsSaveKeepsWhatItDoesNotSend,
`DesktopSubagentModel: after a save of the Settings page, was fake/m2`
GUI breaks (0 pass / 2 fail in each engine): renderSteps' new aside
removed (Desktop's moved story missing); the four "it is disabled in
magpie" translations removed (the kept story keeps the English reason);
the Default note's translation removed.
- go test -tags nogui ./...: 52 packages ok, no failure.
- go test -race -count=20 -run '^TestDesktopSubagent' ./internal/gateway: ok.
- gofmt -l on the changed files: nothing. go vet ./...,
GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...,
go build, GOOS=linux go build -tags nogui, GOOS=windows go build: exit 0.
- Playwright 1.62.1: desktop-subagent-model.test.cjs (en, zh, zh-TW, ja,
de; 1100 and 560 wide) with codex-subagent-model, codex-subagents-lead,
codex-start-model-field, desktop-tiers, desktop-model-menu,
subagent-effort and every routing-*.test.cjs: 472/472 in Chromium and
in WebKit. The whole suite: Chromium 4580/4580; WebKit 4570/4572. The
two are red on 20769439 untouched as well: group-fold.test.cjs 3 of 3
alone (195a1009b, fixed upstream since by a125d5c9), usage-fold.test.cjs
4 of 9 alone there and 4 of 9 here ("as many accounts on the first
screen as before the curves: 12 of 29").
- The built binary in a temporary HOME, `magpie serve` on a free port, a
fake Anthropic upstream, requests shaped like Desktop's Claude Code:
`magpie claude-desktop subagent_model fake/m2` printed no restart
advice; a subagent's turn and its count went to m2; the lead's turn,
a subagent's tool-less call, terminal Claude Code's and a subagent turn
after `… subagent_model default` went to m1; claude-desktop.model stayed
fake/m1; the ledger kept requested fake/m1.
- Not tried: a real Claude Desktop or Cowork (that needs the live
gateway), Linux and Windows machines (GOOS vet and build only),
WebKitGTK.
Maintainer's review on origin/main c4c3cafa2 (#2081), under a scratchpad
HOME with Go's caches pinned, machine load 120-330:
- Claude Code 2.1.299's bundled source has the "Ignoring … this
session's provider routing is managed by the host" path, with
CLAUDE_CODE_SUBAGENT_MODEL_FORCE in the set it ignores.
- Breaks re-run: no tools guard -> TestDesktopSubagentLeavesOtherRequests/
helper `sent "m2", want m1` and TestDesktopSubagentCountTokens helper
count; no count_tokens pick -> TestDesktopSubagentCountTokens `count
sent "m1" … want m2`; the Routing page's subagentWhy aside removed ->
desktop-subagent-model 0 pass / 2 fail (webkit, zh).
- go test -tags nogui ./internal/{gateway,agent,settings,gui,cli,provider}:
ok on 2fbbd1694 (agent with -timeout 40m: 1857s under the load; the
default 10m timed out mid TestClaudeNewSessionEffortLastsModelSwitch, a
test this change doesn't touch). After rebasing onto c4c3cafa2, the
Desktop/Subagent/SettingsSave/Live/Notice tests of those six packages: ok.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./..., go build, GOOS=linux go build -tags nogui,
GOOS=windows go build: ok.
- desktop-subagent-model.test.cjs now runs at 1100 and 420 (was 560):
20/20, chromium and webkit, en zh zh-TW ja de. codex-subagent-model,
desktop-tiers, routing-purpose-state, routing-request-model,
routing-sealed-task: all pass in both engines.
- usage-fold's "29 accounts" case passed 4 of 4 alone in WebKit here.
- Not repeated: the author's built-binary run; a real Claude Desktop or
Cowork; Linux and Windows machines.
Decisions on the author's questions: Live is kept as named, and Codex's
subagent model is left as it is; a subagent's tool-less helper calls stay
on the model they asked for, being Claude Code's own housekeeping rather
than the subagent's work.
Reported-by: Koohoko (#2081)
Subsystem design references
These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.
| Subsystem | Reference |
|---|---|
| Built-in subscriptions moving to plugins | Provider and plugin ownership |
| Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) | Plugin runtime |
| Plugins that run on the gateway's requests and replies | Gateway middleware |
| Claude subscription turns across Claude Code runs | Claude subscription bridge |
| How the gateway picks a provider, key or account, and falls back | Gateway routing and fallback |
| Gateway Session Aggregation | Gateway Session Aggregation |
| Connecting an agent's config to the gateway, drift, disconnect, WSL twins | Agent wiring |
| Providers, keys, subscription accounts, refresh and allowance | Providers and accounts |
| Instructions, MCP servers, skills and RTK written into agents | Library |
Tray, panel, window, magpie web and the page's JSON API |
GUI app shell |
| Encrypted backups and setup synchronization over WebDAV, S3 or GitHub | Sync and backup |
A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.
Maintain a reference
Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.
Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.
For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.
Describe a PR's semantic changes
For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.
For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.
This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.
Review a change
- Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
- Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
- Check that changed contracts appear in the owning reference and that source links still resolve.
- Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.
A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.