diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 8fad1ba90..3f0ad2bef 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -64,7 +64,7 @@ something else shows up as drift. - A field that follows another while empty (`Follows`: Claude Code's tiers and subagents on its main model) is read by `Drift` as on that field's model. The main model moved, in Claude Code's own `/model`, onto the model magpie had set a tier to is not drift (#1050). The tier keeps that model as its own through the move and the next one (`tier_own` in the stash), whatever it would follow on the new main model: fable, which follows no model that is no Fable, and haiku, which follows a Claude model on its Haiku, read as following and lost their model on the next move (#2257). - A Claude Code tier or its subagents given a model of their own keep it when the main model moves onto that model and on again (`ownKey` in `claudeIn`), whether the main model is picked in magpie or in Claude Code's `/model`. Same as model, picked for them, has them follow again. - While this machine's Claude Desktop is on magpie, Claude Code's shared settings get `CLAUDE_CODE_DISABLE_EXPLORE_INHERIT_CAP="1"` (`writeExplore` in `claudeIn`, [`claude.go`](../../internal/agent/claude.go)). Claude Code 2.1.295's Explore inherit cap can otherwise replace Desktop's `mythos-magpie` compatibility alias with Opus. This disables that cap, not the model choices of all subagents. It applies with Desktop alone or beside a connected Claude Code, including model picks and Sync; WSL twins do not get it. A user's existing value, including an empty string, stays. The stash (`claude.explore_inherit_cap`) marks only magpie's value: taking Claude Code off magpie leaves it while Desktop is on, and taking Desktop off removes it only if the user has not changed it. Since the settings file is shared, other Claude Code sessions reading it see the flag while Desktop is connected too. -- Claude Code's tier and subagent models the user had set for their own endpoint (`claudeOwnEnv`) are stashed with that endpoint and token when magpie is wired in, and come back with them when magpie steps out, by Disconnect or by Claude Code's own model (#1050). +- Claude Code's tier and subagent models the user had set for their own endpoint (`claudeOwnEnv`) are stashed with that endpoint and token when magpie is wired in, and come back with them when magpie steps out, by Disconnect or by Claude Code's own model (#1050). So does their main model in the env (`ANTHROPIC_MODEL`, a Bedrock model id beside `CLAUDE_CODE_USE_BEDROCK` for one), which magpie takes out while wired in because it outranks a pick in `/model`. - Claude Code's provider switches (`agentenv.ClaudeProviders`: `CLAUDE_CODE_USE_BEDROCK`, `_VERTEX`, `_FOUNDRY`, `_ANTHROPIC_AWS`, `_ANTHROPIC_GOOGLE_CLOUD`, `_MANTLE`, Claude Code 2.1.300) send it to that cloud's own endpoint and pass `ANTHROPIC_BASE_URL` over, so with one on it never reaches magpie (jw1dev on X: Bedrock refused magpie's model, and magpie showed nothing). Claude Code reads 1, true, yes and on as on (`claudeSwitchOn`). One that is on in the settings magpie writes is taken out on every route that writes the wiring (`dropClouds` in `writeTiers` and `Sync`), its raw value stashed (`claude.cloud.`, under the distro's id for a WSL twin), and put back as written when magpie steps out (`putClouds` in `unroute`), unless the user set it again since. The cloud's own variables (`AWS_*`, `ANTHROPIC_VERTEX_PROJECT_ID`, …) and a switch that is off stay. Where magpie doesn't write it, Check says so, naming the variable, the cloud and where (`claudeCloud`): the managed settings, which win over the user's; `~/.claude.json`'s env, under the user's settings; and, for this machine's Claude Code, the login shell's environment (`proc.LoginEnv`, read but never set in magpie's), under every settings file. A project's `.claude/settings.json` isn't read: magpie doesn't know which folders Claude Code runs in. T3 Code's Check says the same of the user's `~/.claude` settings, which are put over its magpie instance's environment, and a switch put on that instance goes at its next write; that Check first says when the instance's `ANTHROPIC_BASE_URL` no longer reaches the gateway (`t3EnvOf`), as every agent's Check does, so a port move rewrites it too. The drift's detail is shown in the row's line and its pill through `tNotice` (`claude-cloud-drift.test.cjs`). Claude Desktop's Code tab runs with `CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`, under which Claude Code ignores a switch in settings files, so Desktop needs neither. - Claude Code's sign-in (`login`) is magpie's key (`""`, the default) or claude.ai (`claudeai`). claude.ai writes `ANTHROPIC_AUTH_TOKEN` empty, which Claude Code reads as no key: it keeps its claude.ai login and sends that to magpie, which never passes it on (`claudeSignIn` in the gateway). Every later write keeps the token empty (`wiredKey`), and a key put there by hand is reported by Check, not taken for magpie's. It's offered only where the gateway takes any key (`gwKey() == gateway.Token`: loopback, a WSL distro mirrored), not from a distro under NAT while magpie is shared on the network, where only the sharing key gets in. The choice is stashed, so it survives Disconnect and a port move. An empty token counts as magpie's only beside the address magpie last wrote (`claude.wired_at` in the stash, which Rewire carries to the new port, `keyOurs`): an endpoint of the user's own with an empty token stays theirs when the model goes back to Claude Code's own. - Claude Code's auto mode review (`CLAUDE_CODE_AUTO_MODE_SERVER`, `claudeReviewEnv` in [`claude.go`](../../internal/agent/claude.go)) is written `"0"` while Claude Code is routed through magpie and none of the models it can reach there is one Anthropic reviews (`claudeReviewed`, by `gateway.AutoModeReviewed`): those it is shown (and Claude Desktop's while Desktop is on magpie), a shown group's members, those providers' fallbacks, and the models it is set to. Off, it classifies locally from the start, as it does anyway behind a gateway that doesn't answer, without the "isn't eligible because your requests go through 127.0.0.1:3425" notice (1EFLOPS on X). Any reviewed model leaves it unset, since `/model` can take the session there; a model hidden from Claude Code doesn't count. It is rewritten on every model set and `Sync`, so adding a Claude provider turns the review back on. magpie's value is kept apart in the stash (`claude.auto_mode_server`), a user's own is left alone, and it goes when Claude Code is taken off magpie (`desktopOnly`, `unroute`). T3 Code's magpie instance, which runs Claude Code on the gateway through its own environment, carries the same `"0"` there by the models it lists (`t3InstanceJSON` in [`t3code.go`](../../internal/agent/t3code.go)); a value in the user's `~/.claude` settings comes after it. diff --git a/internal/agent/claude.go b/internal/agent/claude.go index 18dee3c45..3538b39fd 100644 --- a/internal/agent/claude.go +++ b/internal/agent/claude.go @@ -60,8 +60,10 @@ var claudeAboutEnv = func() []string { // claudeOwnEnv are the models of claudeEnv a user may have set for their // own endpoint, which magpie's take the place of while it is wired in and // gives back when it steps out, with what the user's env says about each -// tier's model +// tier's model. ANTHROPIC_MODEL, their main model, too: magpie takes it +// out while wired in (writeTiers), and it was lost for good. var claudeOwnEnv = append([]string{ + "ANTHROPIC_MODEL", "ANTHROPIC_DEFAULT_OPUS_MODEL", "ANTHROPIC_DEFAULT_SONNET_MODEL", "ANTHROPIC_DEFAULT_HAIKU_MODEL", "ANTHROPIC_DEFAULT_FABLE_MODEL", "ANTHROPIC_SMALL_FAST_MODEL", "CLAUDE_CODE_SUBAGENT_MODEL", diff --git a/internal/agent/claude_cloud_test.go b/internal/agent/claude_cloud_test.go index 659670de7..ea97b25a5 100644 --- a/internal/agent/claude_cloud_test.go +++ b/internal/agent/claude_cloud_test.go @@ -28,13 +28,13 @@ func claudeCloudHome(t *testing.T, settings string) (home, path string, parse fu // claudeClouded is each settings.json of a Claude Code on a cloud, as jw1dev // on X had Bedrock: the switch on beside the cloud's own variables, and an -// endpoint of the user's own for magpie to give back. +// endpoint and Bedrock main model of the user's own for magpie to give back. var claudeClouded = []struct { name, settings, key, raw string cloud []string }{ {"bedrock", `{"model":"opus","env":{"ANTHROPIC_BASE_URL":"https://relay.example","ANTHROPIC_AUTH_TOKEN":"sk-relay", - "CLAUDE_CODE_USE_BEDROCK":"1","AWS_REGION":"us-west-2","AWS_PROFILE":"work","AWS_BEARER_TOKEN_BEDROCK":"bedrock-key"}}`, + "CLAUDE_CODE_USE_BEDROCK":"1","AWS_REGION":"us-west-2","AWS_PROFILE":"work","AWS_BEARER_TOKEN_BEDROCK":"bedrock-key","ANTHROPIC_MODEL":"us.anthropic.claude-sonnet-4-5-20250929-v1:0"}}`, "CLAUDE_CODE_USE_BEDROCK", `"1"`, []string{"AWS_REGION", "AWS_PROFILE", "AWS_BEARER_TOKEN_BEDROCK"}}, // a JSON true, which Claude Code takes as on too, comes back a true {"bedrock-bool", `{"env":{"CLAUDE_CODE_USE_BEDROCK":true,"AWS_REGION":"eu-central-1"}}`, diff --git a/internal/agent/disconnect_test.go b/internal/agent/disconnect_test.go index 72449e703..d9efb494c 100644 --- a/internal/agent/disconnect_test.go +++ b/internal/agent/disconnect_test.go @@ -89,12 +89,18 @@ func TestCodexDisconnect(t *testing.T) { // come back, and every env key, tier and capability magpie wrote goes. // The tier and subagent models the user set for their relay come back with // it (#1050), whether magpie steps out by Disconnect or by Claude Code's -// own model. +// own model. So does the main model set for the relay in the env +// (ANTHROPIC_MODEL), which magpie takes out while wired in. func TestClaudeDisconnect(t *testing.T) { for name, before := range map[string]string{ "own relay": `{"theme":"dark","model":"opus","env":{"ANTHROPIC_BASE_URL":"https://relay.example","ANTHROPIC_AUTH_TOKEN":"sk-relay","DISABLE_TELEMETRY":"1"}}`, "own tiers": `{"model":"sonnet","env":{"ANTHROPIC_BASE_URL":"https://relay.example","ANTHROPIC_AUTH_TOKEN":"sk-relay","ANTHROPIC_DEFAULT_OPUS_MODEL":"relay-opus","ANTHROPIC_DEFAULT_SONNET_MODEL":"relay-sonnet","ANTHROPIC_DEFAULT_HAIKU_MODEL":"relay-haiku","ANTHROPIC_SMALL_FAST_MODEL":"relay-haiku","CLAUDE_CODE_SUBAGENT_MODEL":"relay-sonnet"}}`, "nothing set": `{"theme":"dark"}`, + // the main model set for the relay in the env (with no settings + // model, and beside one), which magpie takes out while wired in: + // it outranks a pick in /model + "own env model": `{"env":{"ANTHROPIC_BASE_URL":"https://relay.example","ANTHROPIC_AUTH_TOKEN":"sk-relay","ANTHROPIC_MODEL":"relay-main"}}`, + "own env model, both": `{"model":"opus","env":{"ANTHROPIC_BASE_URL":"https://relay.example","ANTHROPIC_AUTH_TOKEN":"sk-relay","ANTHROPIC_MODEL":"relay-main[1m]"}}`, } { for _, out := range []string{"disconnect", "default"} { t.Run(name+", "+out, func(t *testing.T) {