claude-desktop: a model past 200K and under 1M runs at its own window in the Code tab (RQuantum198888 on X)

A GPT set to "Each model's most · 872K" still showed 200K in Claude.
Claude Desktop 5.11492 starts its Code tab's Claude Code with
CLAUDE_CODE_MAX_CONTEXT_TOKENS=200000 in its --settings file, and flag
settings come before the 872000 magpie writes to ~/.claude/settings.json.
ccae8e821 fixed this for 1M models through Desktop's 1M entry and called a
model between 200K and 1M "not fixable": Desktop offers no 1M entry for
one.

Claude Code takes a "[1m]" id for 1M over that variable (peo in aV,
2.1.326), and reads modelSettings.<id>.autoCompactWindow by the id
without "[1m]". So a model past 200K and under 1M that isn't Claude's is
now listed to Desktop by its "[1m]" id whatever DesktopLongest says
(desktopMidWindow), described by its own size ("872K context window",
not "1M"). claudePlan gives it an entry at its own window: the window
the user typed whole, else the working window, as before. A Claude
model keeps its id, since Claude Code knows its window. The gateway
already serves a "[1m]" id as the plain one. desktopPlan's work() treats
it as listed at 1M only when its window is 1M or more, so the full-1M
rule (henglu486729) doesn't apply to it.

Changed behaviour: a user's own modelSettings entry past such a model's
window ("auto") no longer holds CLAUDE_CODE_MAX_CONTEXT_TOKENS to that
window. The model's "[1m]" id doesn't read that variable, so holding it
did nothing for the model and held every other model back.

Run (on 074614077 plus this change; pushed on a9cd746da, whose
last two commits touch only README, site files and internal/bark):
- go test -timeout 45m ./... on mica: exit 0, 103 packages ok, no FAIL
  (log kept whole)
- GOOS=linux, GOOS=windows and darwin go vet ./internal/agent
  ./internal/gateway on mica: ok; gofmt -l: clean
- Broken by hand: desktopListed1M without desktopMidWindow turns
  TestClaudeDesktopLongestOnly (exo-free 872K plain), the new
  TestClaudeDesktopMidWindowRunsPast200K and TestClaudeDesktopContextWindow
  red; claudePlan without the new case turns TestClaudePlan's "[1m] under
  1M" (m:1000000) and TestClaudeDesktopMidWindowRunsPast200K red.
- Real Claude Code 2.1.326 binary against a local fake Messages server, in a
  sandbox HOME, with Desktop's flag settings
  (--settings '{"env":{"CLAUDE_CODE_MAX_CONTEXT_TOKENS":"200000"}}'):
  "/context" on anthropic/magpie-123 with 872000 in settings.json read
  "2.1k / 200k" (the report); on anthropic/magpie-123[1m] with
  modelSettings.anthropic/magpie-123.autoCompactWindow 872000 it read
  "2.2k / 872k", and "/ 272k" with the top-level 272000 alone.
  mythos-magpie-123[1m] runs at 1M the same way.

Not tried: a real Claude Desktop 5.11492 on magpie; the reporter's Desktop
build (no screenshot; the CLI path writes 872000 already, so the Code tab
is the likely surface). The GUI is unchanged. Not changed: a user's own
CLAUDE_CODE_MAX_CONTEXT_TOKENS in ~/.claude/settings.json, which magpie
keeps and the GUI doesn't name. Not broken by hand: work()'s 1M condition
(a 400K model untyped compacts at the working window, not its whole).
This commit is contained in:
yetone
2026-11-17 18:27:14 +08:00
parent a9cd746da3
commit 7c3e68908f
7 changed files with 114 additions and 19 deletions
+2 -2
View File
@@ -153,7 +153,7 @@ something else shows up as drift.
- 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, unless every model it can reach there surely gets Anthropic's results back (`claudeReviewed`, by `gateway.AutoModeAnswered`: a model `AutoModeReviewable` on the Claude subscription or on `api.anthropic.com` itself; a relay's Claude model, even on its Anthropic endpoint, may drop `safeguard_results`, and a Claude model asked on Chat or Responses never carries the review, nexnull on Discord, `TestClaudeReviewedOnlyWhereResultsComeBack`): 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, each judged on the provider (or group, or fallback) it resolves to, as the gateway judges its requests, so a Claude model on Copilot or Kiro writes `"0"` and a name magpie doesn't know is judged by the name (`TestClaudeReviewedJudgesTheSetModelWhereItGoes`). One model that doesn't answer is enough, since `/model` can take the session there; a model hidden from Claude Code doesn't count. Off, Claude Code runs its own classifier through the gateway (fitted to any model, `classifierStandIn`; the model is the Claude Code card's auto mode square, `CLAUDE_CODE_AUTO_MODE_MODEL`), which works on every model. Left on behind a route that doesn't answer, 2.1.322 doesn't fall back: with telemetry or feature flags off (`DISABLE_TELEMETRY`, `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`, …) it denies each action it would check, "Auto mode can't check actions in this session … your requests go through 127.0.0.1:3425, which doesn't pass it through" (`auto_mode_no_check_in_session`), on a Claude model too when the session could also reach another model (JoyYoung2Lucky on X). Before this, any reviewed model left it unset, which is how a relay's Claude beside DeepSeek met that denial. 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.
- Claude Code's tool search (`ENABLE_TOOL_SEARCH`, `claudeSearchEnv` in [`claude.go`](../../internal/agent/claude.go)) is written `"true"` while Claude Code is routed through magpie. On, MCP tools are named in a reminder and loaded by `ToolSearch` when the model needs them, not sent whole on every request. Claude Code before 2.1.304 keeps it off behind an `ANTHROPIC_BASE_URL` other than Anthropic's, so the MCP router's tools all went on each request (cybercaius on Discord: 245 tools, 124K tokens of a 341K context; 2.1.290 through a sandbox gateway sent 242,346 bytes of tools, 27,443 with it on); 2.1.304 and later turn it on there themselves, and `"true"` also keeps it on in a conversation begun without it. The gateway carries deferred tools to every upstream (`Tool.Deferred`, `withoutDeferredTools`). magpie's value is kept apart in the stash (`claude.tool_search`); a value the user set, an empty one too, is theirs; it goes when Claude Code is taken off magpie (`desktopOnly`, `unroute`; `TestClaudeToolSearchOn`). T3 Code's magpie instance carries `"true"` in its environment unless the user gave it a value there (`TestT3CodeToolSearchOn`).
- Claude Desktop's Code tab gets tool search only with Desktop's own `toolSearchEnabled` policy on (3p only, off by default). Off, Desktop 2.7032 (`Ztr` "off") starts Claude Code with `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`, and Claude Code (2.1.312, 2.1.316: `oae` returns "standard") then keeps tool search off whatever `ENABLE_TOOL_SEARCH` says, so every MCP tool went whole on each request (bigcat1800 on Discord: 13 MCP servers, ~162K tokens; a sandbox CLI with 60 MCP tools sent 83 tools, 205KB). On, with the gateway provider and a bundled Claude Code of 2.1.247 or later, Desktop hands the CLI `ENABLE_TOOL_SEARCH=force` as a managed setting and the same CLI sent 13 tools, MCP ones behind `ToolSearch`, 56KB, asking only `tool-search-tool-2025-10-19` of the betas. magpie's profile gets `toolSearchEnabled: true` once, on a switch on and from Sync, as `claudeAiImport` is (`desktopSeedToolSearch`, `desktopSeedOnce`, mark `claude-desktop.tool-search`): a value the user set, false too, or took away since, stays theirs (`TestClaudeDesktopTurnsOnToolSearch`). A profile the user applied for magpie's gateway (`desktopAppliedGateway`) is not written.
- Claude Desktop 5.11492 starts its Code tab's Claude Code with `CLAUDE_CODE_MAX_CONTEXT_TOKENS=200000` in its `--settings` file whenever the provider routes models itself, the gateway included (`Fcn`, `Lcn` in its app.asar; 4.16336 had none). Flag settings come before `~/.claude/settings.json`, so the window magpie writes there (`claudeContextEnv`) no longer reaches the Code tab: a 1M model picked by its plain entry ran at 200K (fwxkogaia on X, v0.1.4321). Claude Code takes a `[1m]` id for 1M whatever that variable says (2.1.322's `pT`), so magpie's profile gets Desktop's own "Use 1M wherever it's available" (`modelPrefer1mContext: true`, 3p only, Desktop 1.28929 and later) once, on a switch on and from Sync, as `toolSearchEnabled` is (`desktopSeedPrefer1M`, mark `claude-desktop.prefer-1m`; `TestClaudeDesktopPrefers1M`). Desktop then shows a model it offers a 1M entry for by that entry alone; it offers one only for a row whose `max_input_tokens` is 1M or more, so smaller models are unchanged, and one between 200K and 1M still runs at Desktop's 200K (only a managed policy setting comes before flag settings, and magpie writes none). The user's own value, false too, or their taking it away, stays theirs.
- Claude Desktop 5.11492 starts its Code tab's Claude Code with `CLAUDE_CODE_MAX_CONTEXT_TOKENS=200000` in its `--settings` file whenever the provider routes models itself, the gateway included (`Fcn`, `Lcn` in its app.asar; 4.16336 had none). Flag settings come before `~/.claude/settings.json`, so the window magpie writes there (`claudeContextEnv`) no longer reaches the Code tab: a 1M model picked by its plain entry ran at 200K (fwxkogaia on X, v0.1.4321). Claude Code takes a `[1m]` id for 1M whatever that variable says (2.1.322's `pT`), so magpie's profile gets Desktop's own "Use 1M wherever it's available" (`modelPrefer1mContext: true`, 3p only, Desktop 1.28929 and later) once, on a switch on and from Sync, as `toolSearchEnabled` is (`desktopSeedPrefer1M`, mark `claude-desktop.prefer-1m`; `TestClaudeDesktopPrefers1M`). Desktop then shows a model it offers a 1M entry for by that entry alone; it offers one only for a row whose `max_input_tokens` is 1M or more, so it does nothing for a smaller model. A model past 200K and under 1M that isn't Claude's (a 272K or 872K GPT) is listed by its `[1m]` id whatever `DesktopLongest` says (`desktopMidWindow` in [`desktop.go`](../../internal/gateway/desktop.go)), described by its own size ("872K context window"), because by its plain id it ran at 200K whatever its window was (RQuantum198888 on X: a GPT set to 872K showed 200K). Claude Code 2.1.326 then runs it in 1M (`peo` in `aV`, past the forced 200000), and it compacts within its own window through `modelSettings.<id>.autoCompactWindow` (`claudePlan`): the window the user typed whole, else the working window (`TestClaudeDesktopMidWindowRunsPast200K`). Its `/context` then reads "/ 872k" where the plain id read "/ 200k" (tried on 2.1.326 with Desktop's flag settings); a managed policy setting is the only thing that comes before flag settings, and magpie writes none. The user's own value, false too, or their taking it away, stays theirs.
- OpenMausBot (`openmausbot.go`) runs each bot on an engine from `instances` in `~/.openmausbot/config.json` (`$OMB_DATA_DIR`, `server/config.ts` in its source). magpie writes the `magpie` engine as OpenMausBot's own Claude endpoint (`newClaudeEndpoint`, `claude-endpoints.ts`): driver `claudeAgent`, access `custom`, `config.configDir` under `providers/magpie` so OpenMausBot starts Claude Code with its own `CLAUDE_CONFIG_DIR` and strips account keys the engine doesn't set (`claudeEnvironment`, `claude.ts`), `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY` at the gateway, and magpie's models as `config.endpointModels`, kept to the ids OpenMausBot's `CLAUDE_MODEL_ID` accepts (one bad id makes it refuse the whole engine). A non-empty `instances` is the whole fleet, so with none saved magpie writes OpenMausBot's `DEFAULT_FLEET` beside it (`ombFleet`, stashed as `openmausbot.fleet`) and takes it out again on off if the user hasn't changed it (`TestOpenMausBotFleetChanged`). The name, a model picked from the list, other env and a `cli` are the user's. OpenMausBot reads the file once at start and writes back the fleet it holds whenever an engine is edited in it, so the switch is refused while it runs (`errOMBRunning`; not checked on Windows) and the notice asks to quit it first. That write-back, and an edit of magpie's engine there (`updateClaudeEndpoint` keeps only the model picked and its tiers), leave `endpointModels` without models picked in magpie, and no catalog change follows to sync it again: while magpie serves, `KeepOpenMausBotListed` runs the sync every 30 seconds when the saved list differs from magpie's (`ombListStale`; maxleebeta on Discord, 11-08: Antigravity's models missing from its search). A copy started before magpie's last change to the engine (`ombPart`: the gateway, the first model and the list) offers the row's Restart (`restartApps`, `OpenMausBot.app` and `OpenMausBot.exe`). Codex bots use `~/.codex`, which magpie's Codex wiring already covers.
- Avibe (`avibe.go`, `avibe-os` on PyPI, the `vibe` CLI) keeps its model sources in `model_hub.sources` of `config/config.json` in its home (`$AVIBE_HOME`, else `~/.avibe`, else a legacy `~/.vibe_remote`: `config/paths.py`). A source can't be written there by hand: its key is sealed in the Model Hub's store and Avibe adds it to its agents' route chains as it is made. So magpie adds the `magpie` source through the same internal API Avibe's Models page uses (`POST /internal/model-hub`, `core/handlers/model_hub/rpc.py`) on the control socket `state/dispatch.sock` in its home, or on Windows the loopback port and bearer token in `runtime/control-ipc/endpoint.json` (`core/control_ipc.py`). `create_source` makes an `api_key` source of vendor `custom` at the gateway's `/v1` with `agentKey("avibe")`, protocol `openai_chat` and `save_unverified` (Avibe's probe can't tell which protocol a gateway serving all of them speaks); Avibe then lists the models from `/v1/models` itself. Chat completions, not Responses: for a Responses source its CLIProxyAPI runs Codex's executor, which sends `codex-tui` headers the gateway would take for Codex. Its id is stashed (`avibe.source:<home>`); a source of the custom vendor at the gateway's `/v1` counts as magpie's too. `delete_source` and `refresh_source` are sent with `force` and then again with the `would_remove_hops` and `would_interrupt` Avibe answers with, as its page confirms them. A gateway address change makes the source again (the key goes with the address and `patch_source` can't change it). Every change needs Avibe running (`avibeLive` probes `list_sources`; `errAvibeDown`); `Sync` refreshes the source's models while it runs.
- Kun (`kun.go`, KunAgent/Kun, an Electron app, `com.xingyuzhong.deepseekgui`; zhongxingyuyes on X) keeps its model connections in `model-connections.v2.json` in its data folder (`$KUN_DATA_DIR`, not ~-expanded, else `~/.kun/data`). A connection's key goes to Kun's credential store as it is made, so the file isn't written by hand: magpie adds the `magpie` connection the way Settings > Providers does, through the runtime's admin API at the `baseUrl` of `runtime.json` in that folder, with its `runtimeToken` as a bearer (loopback only). `POST /v1/model-connections/connect` makes an `http` connection with `api-key` auth at the gateway's `/v1`, `endpointFormat` `chat_completions`, `agentKey("kun")`, the models picked for Kun (500 at most) and the pick selected; another of magpie's models is `PATCH` of the list and `POST /v1/model-connections/select`. Every change names the registry's revision (409 `revision_conflict` otherwise). Kun's default before magpie's is stashed (`kun.prev:<dir>`) and selected again when magpie steps out, then the connection is `DELETE`d. Kun refuses to delete the connection its default names ("still has references: default.providerId"), so with no default of Kun's own to go back to, magpie's goes as Kun's Settings retires one: a provider-config transaction (`POST /v1/provider-config/transactions/preview`, then `commit`) that clears the default and removes the connection (`kunClient.remove`, `TestKunFromNothing`). Its id is stashed (`kun.id:<dir>`); an HTTP connection at the gateway's `/v1` counts as magpie's too. Every change needs Kun running (`kunLive` probes the snapshot; `errKunDown`); reads go to the registry file first. A sync brings the list up to the picked models, and makes the connection again only from the gateway's own address on an older port (`kunMoved`, as `avibeMoved`). Every test of the package but Kun's own finds a Kun running per data folder (`runningKun`).
@@ -180,7 +180,7 @@ something else shows up as drift.
no Windows build, so there is no Windows or WSL wiring.
- T3 Code runs a thread on the harness of the provider instance its model is picked under, so magpie writes two instances (karissasel_ on X: only Claude Code could be picked). `magpie` runs Claude Code, as above. `magpie-codex` ("magpie · Codex", `t3CodexJSON` in [`t3code.go`](../../internal/agent/t3code.go)) runs Codex: its `config.launchArgs`, which T3 hands to `codex app-server` and the `-c` pairs of to `codex exec`, are Codex's own overrides, making `magpie` its `model_provider` (the same table `codex.go` writes) and `magpie-codex-models.json`, written beside settings.json from `codexcat`, its `model_catalog_json`. Each value is quoted for T3's `tokenizeCliArgs` (`t3Arg`; `TestT3CodeCodexInstance` reads them back with a port of it). `~/.codex/config.toml` is not written, and a `binaryPath` or `homePath` the user gave T3's own `codex` instance is carried over. The name, on/off and unknown keys are the user's; the launch args and catalog are magpie's, and Check says when the launch args no longer reach the gateway (`t3CodexOff`). An older Claude-only wiring gets the Codex instance on its next Sync once; one the user removed stays removed (`t3code.codex` in the stash) until magpie is turned on for T3 again (`TestT3CodeCodexInstanceAddedOnce`).
- Claude Code's main model in `~/.claude/settings.json` is written as the alias of a tier that carries it (`mainWord` in [`claude.go`](../../internal/agent/claude.go): sonnet, opus, haiku, fable, `[1m]` kept), not as magpie's provider-prefixed id. Claude Desktop's Code tab on the user's own subscription runs Claude Code with its provider routing managed by the host (`CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`): it drops this file's env (the gateway's address, key, tiers; tried on 2.1.312, 2.1.314 and 2.1.316) but still takes the top-level `model`, so the prefixed id went to Anthropic and every request failed, WebFetch included (iryan_sun on X). The alias is magpie's model through the env and Anthropic's own tier anywhere else. A model on no tier, a distro's file and the `claude-magpie` launch file keep the id; Sync brings a file an older magpie wrote to the alias, and Disconnect takes the alias out with the tiers (`wroteAlias`; `TestClaudeMainModelIsAnAlias`). `modelPicker` rows still carry the ids: they only list.
- 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). Under `DesktopLongest` that 1M model also compacts at its whole 1M, not the working window (`work` in `desktopPlan`; henglu486729 on X: Desktop's 1M entry showed and compacted at 272K); a threshold typed in magpie (`CompactAt`, a model's or provider's) still holds it. 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 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`, a Desktop model past 200K and under 1M, or Claude Code's own) counts by its 1M too, or by its own window under 1M, which is its entry, 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). Under `DesktopLongest` that 1M model also compacts at its whole 1M, not the working window (`work` in `desktopPlan`; henglu486729 on X: Desktop's 1M entry showed and compacted at 272K); a threshold typed in magpie (`CompactAt`, a model's or provider's) still holds it. 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 unless the model is handed by a `[1m]` id, which the largest doesn't reach, 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.
- Claude Code's status line (`statusline`, [`claude_statusline.go`](../../internal/agent/claude_statusline.go)) is a switch on its row, beside ultracode (steven_4422 on Discord: the 5h and 7d use in Claude Code). On writes settings.json's `statusLine` to run this magpie by its full path (`update.Program()`, forward slashes and quoted for Git Bash on Windows) with `statusline` (#1997, [`statusline_cli.go`](../../internal/cli/statusline_cli.go)), which reads the gateway's kept windows with a 1s timeout and prints nothing when it can't. A status line runs magpie's when its program's base name is `magpie` (or `magpie-…`) and its first argument `statusline` (`claudeStatusOurs`), so one written by hand from the reference counts too. A status line of the user's own (claude-hud, a script) is never written over: Options is empty while one is there, so the square isn't shown, and on is refused; an unreadable settings.json is refused too. Off and Disconnect take out only magpie's. Claude Code watches settings.json and reruns a changed command in its open sessions, so it is Quiet and needs no restart. Only on this computer: a WSL distro, running or stopped (`wslKinds` asleep options), isn't offered it (`TestClaudeStatusLine*`, `TestWSLClaudeNoStatusLine`, `claude-statusline.test.cjs`). For Claude Code on another computer than magpie (Docker), the gateway serves the same line at `/v1/magpie/statusline` ([`statusline.go`](../../internal/gateway/statusline.go), the renderer shared in [`provider/statusline.go`](../../internal/provider/statusline.go)), and `magpie web` shows the curl to put in settings.json (`TestStatuslineEndpoint`, `TestStatuslineEndpointIsTheCLIsLine`, `statusline-remote.test.cjs`); nothing writes that computer's file.
- 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)).
+2 -1
View File
@@ -1393,7 +1393,8 @@ func claudeIn(at place) *Agent {
for _, e := range shown {
for _, id := range append([]string{gateway.DesktopID(e)}, again[e.ID]...) {
if claudeName(id) == "" {
models = append(models, claudeBudget{id: id, window: e.Context, long: gateway.DesktopListed1M(e), compact: work(e.ID, gateway.DesktopListed1M(e)), behaves: behaves[id] != ""})
long := gateway.DesktopListed1M(e)
models = append(models, claudeBudget{id: id, window: e.Context, long: long, compact: work(e.ID, long && e.Context >= claudeLong), behaves: behaves[id] != ""})
}
}
}
+7 -1
View File
@@ -100,8 +100,14 @@ func claudePlan(models []claudeBudget, base int, theirs map[string]string) (top
assumed = claudeLong
}
want := assumed
if m.window > 0 && !m.long {
switch {
case m.window > 0 && !m.long:
want = min(m.window, top)
case m.long && m.window > 0 && m.window < claudeLong:
// listed by its "[1m]" id though its window is smaller
// (gateway.DesktopListed1M: Claude Desktop's 200K would hold
// it otherwise), it compacts within its own window
want = m.window
}
switch {
case m.compact > 0:
+9
View File
@@ -61,6 +61,15 @@ func TestClaudePlan(t *testing.T) {
if top != 1000000 || !reflect.DeepEqual(entries, map[string]int{"g": 272000}) {
t.Fatalf("[1m] beside 272K: %d %v", top, entries)
}
// a model under 1M listed by its "[1m]" id (Claude Desktop's 200K
// held it otherwise, RQuantum198888 on X) runs in Claude Code's 1M
// and compacts within its own window: the 872K the user typed whole,
// and a 400K one at the working window. Neither holds the top-level
// window, which its "[1m]" id doesn't read
top, entries = claudePlan([]claudeBudget{{id: "m[1m]", window: 872000, long: true, compact: -1}, {id: "n[1m]", window: 400000, long: true, compact: 272000}, {id: "g", window: 128000, compact: 272000}}, 272000, nil)
if top != 872000 || !reflect.DeepEqual(entries, map[string]int{"m": 872000, "g": 128000}) {
t.Fatalf("[1m] under 1M: %d %v", top, entries)
}
// a Desktop tier's pick Claude Code runs as a Claude model
// (behavesAs, moer2831) would run at that model's window: it is told
// its own, even where it is the largest
+39 -3
View File
@@ -147,12 +147,15 @@ func TestClaudeDesktopContextWindow(t *testing.T) {
if err := a.Sync(); err != nil || budget("w/small.v2") != "" || !strings.Contains(readFile(path), ids["v/grok"]) {
t.Fatalf("after w/small.v2 went: %v %s", err, readFile(path))
}
// the user's own entry for a model, and a window of their own past the
// model's, which holds the largest to it
// the user's own entry for a model is theirs. Grok's 256K is listed by
// its "[1m]" id (Desktop's 200K held it otherwise, RQuantum198888 on
// X), which runs at 1M whatever the largest says, so "auto" past its
// window doesn't hold the largest to it (claudePlan does for a model
// listed by its plain id: TestClaudePlan)
if err := edit.SetJSON(path, edit.KV{Path: budgetPath(ids["v/grok"]), Value: "auto"}); err != nil {
t.Fatal(err)
}
if err := a.Sync(); err != nil || window() != "256000" || budget("v/grok") != "auto" {
if err := a.Sync(); err != nil || window() != "1000000" || budget("v/grok") != "auto" {
t.Fatalf("the user's grok entry: window %q grok %q %v", window(), budget("v/grok"), err)
}
if err := edit.SetJSON(path, edit.KV{Path: budgetPath(ids["v/grok"]), Value: 100000}); err != nil {
@@ -535,3 +538,36 @@ func TestClaudeDesktopLongestRunsTo1M(t *testing.T) {
t.Fatalf("typed 400K: glm %q top %q: %s", budget("v/glm"), top, readFile(path))
}
}
// RQuantum198888 on X: a GPT set to its most, 872K, still showed 200K in
// Claude. Claude Desktop 5.11492 starts its Code tab's Claude Code with
// CLAUDE_CODE_MAX_CONTEXT_TOKENS=200000 in flag settings, before the
// 872000 magpie writes, so a model listed by its plain id runs at 200K.
// Claude Code takes a "[1m]" id for 1M over that, so the model is listed
// by it (DesktopListed1M), with Only each model's largest window off too,
// and compacts at the 872K the user set through its own autoCompactWindow.
func TestClaudeDesktopMidWindowRunsPast200K(t *testing.T) {
home, path := desktopWindowSandbox(t)
if err := provider.Save(provider.Provider{ID: "w", Name: "W", Key: "k", Chat: "http://127.0.0.1:1/v1",
Models: []string{"gpt-6"}, Contexts: map[string]int{"gpt-6": 872000}}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("w", "http://127.0.0.1:1/v1", []catalog.Model{{ID: "gpt-6", Context: 272000}}); err != nil {
t.Fatal(err)
}
if err := claudeDesktop(home).Field("provider").Set("magpie"); err != nil {
t.Fatal(err)
}
var e provider.Entry
for _, x := range provider.Catalog() {
if x.ID == "w/gpt-6" {
e = x
}
}
if e.Context != 872000 || !gateway.DesktopListed1M(e) {
t.Fatalf("w/gpt-6 at %d, listed by its [1m] id: %v", e.Context, gateway.DesktopListed1M(e))
}
if v, _ := edit.GetJSON(path, budgetPath(gateway.DesktopID(e))); v != "872000" {
t.Fatalf("w/gpt-6 (%s) compacts at %q, want 872000: %s", gateway.DesktopID(e), v, readFile(path))
}
}
+35 -3
View File
@@ -241,7 +241,7 @@ func desktopModels(entries []provider.Entry, knowsMythos bool) []map[string]any
var said []string
if desktopListed1M(e, longest) {
m["id"] = m["id"].(string) + "[1m]"
said = append(said, desktop1MSaid)
said = append(said, desktopWindowSaid(e))
}
if by := desktopSaidBy(e, labels[i]); by != "" {
said = append(said, by)
@@ -277,8 +277,40 @@ func desktopModels(entries []provider.Entry, knowsMythos bool) []map[string]any
const desktop1M = 1_000_000
// desktopListed1M says e is listed to Claude Desktop by its "[1m]" id,
// longest being settings.DesktopLongest.
func desktopListed1M(e provider.Entry, longest bool) bool { return longest && e.Context >= desktop1M }
// longest being settings.DesktopLongest: a model of 1M or more under
// it, and one past 200K and under 1M that isn't Claude's always
// (desktopMidWindow).
func desktopListed1M(e provider.Entry, longest bool) bool {
return longest && e.Context >= desktop1M || desktopMidWindow(e)
}
// desktop200K is the window Claude Desktop 5.11492 starts its Code tab's
// Claude Code with (CLAUDE_CODE_MAX_CONTEXT_TOKENS=200000 in its
// --settings file, Fcn in its app.asar), which comes before the one magpie
// writes to ~/.claude/settings.json.
const desktop200K = 200_000
// desktopMidWindow says e's window is past Desktop's 200K and under 1M,
// so by its plain id it ran at 200K whatever the user set (872K on a GPT,
// RQuantum198888 on X), and Desktop offers no 1M entry for it. Claude
// Code 2.1.326 takes a "[1m]" id for 1M over that 200K (peo in aV), so it
// is listed by that id and compacts within its own window, the
// modelSettings.<id>.autoCompactWindow magpie writes for it (claudePlan),
// described by its real size (desktopWindowSaid). A Claude model has its
// own window in Claude Code and keeps its id.
func desktopMidWindow(e provider.Entry) bool {
return e.Context > desktop200K && e.Context < desktop1M && claudeModel(e) == ""
}
// desktopWindowSaid is the description of a row listed by its "[1m]" id:
// Desktop's own for its 1M entry (desktop1MSaid), or the model's real
// window, "872K context window", for one under 1M.
func desktopWindowSaid(e provider.Entry) string {
if e.Context >= desktop1M {
return desktop1MSaid
}
return strconv.Itoa((e.Context+500)/1000) + "K context window"
}
// DesktopListed1M says Claude Desktop is shown e by its "[1m]" id, which
// its Code tab hands Claude Code, so a session on it has the 1M window.
+20 -9
View File
@@ -15,9 +15,12 @@ import (
// models made 34 entries). With DesktopLongest on, such a model is listed
// by its "[1m]" id alone, so Desktop's menu has one entry per model, told
// as the 1M one by the "1M context window" Desktop gives its own (a lone
// "[1m]" row was shown as the plain model: 杰多夫 on Discord); one
// under 1M (872K) keeps its own id and window, and a request on the plain id
// a session was saved with is still served.
// "[1m]" row was shown as the plain model: 杰多夫 on Discord). One past
// 200K and under 1M (872K) is listed by its "[1m]" id whether or not
// (RQuantum198888 on X: Desktop 5.11492 runs a plain id at 200K, and
// offers no 1M entry for it), described by its own size and told its own
// window, and a request on either id, or on the plain id a session was
// saved with, is still served.
func TestClaudeDesktopLongestOnly(t *testing.T) {
f := &fake{reply: sse(
`event: message_start`+"\n"+`data: {"type":"message_start","message":{"id":"m","type":"message","role":"assistant","model":"x","content":[],"usage":{"input_tokens":1,"output_tokens":0}}}`,
@@ -75,7 +78,7 @@ func TestClaudeDesktopLongestOnly(t *testing.T) {
t.Fatalf("off: %d entries of %d rows, want two 1M extras: %v", entries(off), len(off), off)
}
for id, r := range off {
if strings.HasSuffix(r.ID, "[1m]") {
if strings.HasSuffix(r.ID, "[1m]") != (id == "vend/exo-free") {
t.Fatalf("off: %s listed as %s", id, r.ID)
}
}
@@ -101,9 +104,12 @@ func TestClaudeDesktopLongestOnly(t *testing.T) {
}
// a row Desktop names after its catalog says its provider as well
// (desktopSaidBy)
said := func(r row, oneM bool) string {
said := func(r row, long bool) string {
var s []string
if oneM {
switch {
case long && r.MaxInput < 1_000_000:
s = append(s, "872K context window")
case long:
s = append(s, "1M context window")
}
if strings.Contains(r.ID, ".anthropic.") {
@@ -117,7 +123,7 @@ func TestClaudeDesktopLongestOnly(t *testing.T) {
}
}
for id, r := range off {
if want := said(r, false); r.Said != want {
if want := said(r, strings.HasSuffix(r.ID, "[1m]")); r.Said != want {
t.Errorf("off: %s (%s) described %q, want %q", id, r.ID, r.Said, want)
}
}
@@ -126,14 +132,19 @@ func TestClaudeDesktopLongestOnly(t *testing.T) {
}
// the 1M id and the plain id an older session holds both reach the model
for _, id := range []string{on["vend/deepseek-v4-pro"].ID, off["vend/deepseek-v4-pro"].ID} {
exo := strings.TrimSuffix(on["vend/exo-free"].ID, "[1m]")
for _, id := range []string{on["vend/deepseek-v4-pro"].ID, off["vend/deepseek-v4-pro"].ID, exo + "[1m]", exo} {
f.calls = 0
req := httptest.NewRequest("POST", "/v1/messages", strings.NewReader(`{"model":"`+id+`","max_tokens":10,"stream":true,"tools":[{"name":"t","input_schema":{"type":"object"}}],"messages":[{"role":"user","content":"hi"}]}`))
req.Header.Set("x-api-key", TokenFor("claude-desktop"))
rec := httptest.NewRecorder()
New().Handler().ServeHTTP(rec, req)
var sent struct{ Model string }
if rec.Code != 200 || f.calls != 1 || json.Unmarshal(f.got, &sent) != nil || sent.Model != "deepseek-v4-pro" {
want := "deepseek-v4-pro"
if strings.HasPrefix(id, exo) {
want = "exo-free"
}
if rec.Code != 200 || f.calls != 1 || json.Unmarshal(f.got, &sent) != nil || sent.Model != want {
t.Fatalf("%s: %d %s, %d calls, sent %s", id, rec.Code, rec.Body, f.calls, f.got)
}
}