Skip to content

feat(server): Claude on a Magpie gateway lists Magpie's whole catalog - #93

Merged
nullStack65 merged 2 commits into
release/native-0.1.10from
fix/native-0.1.10-claude-magpie-catalog
Nov 19, 2026
Merged

nullStack65 merged 2 commits into
release/native-0.1.10from
fix/native-0.1.10-claude-magpie-catalog

Conversation

@nullStack65

Copy link
Copy Markdown
Owner

A Claude instance whose ANTHROPIC_BASE_URL points at a Magpie gateway listed only T3's built-in Claude models. Kameron saw "Claude shows only Claude models." Magpie routes Anthropic Messages requests to Codex, Magpie Go and routing groups too. But Claude Code's gateway discovery fetches /v1/models and keeps only ids that match /(claude|anthropic)/i (checked in the 2.1.322 binary), so those models never reached the picker.

Fix

  • New apps/server/src/provider/MagpieGatewayModels.ts. After each Claude status check, the driver reads <base>/v1/models from the effective ANTHROPIC_BASE_URL (settings env, then process env). It only does this for non-Anthropic hosts, with a 3-second timeout. A catalog counts as Magpie when its entries carry magpie_label, which catches the real gateway rather than guessing from the hostname.
  • The list it builds:
    1. The built-in Claude models Magpie serves, with their full options (effort, Ultracode, Fast Mode, context window).
    2. Magpie-only Claude ids, such as claude/claude-sonnet-4-5.
    3. Codex, Magpie Go and routing-group models, in that order.
    4. Custom models, last.
  • Dated duplicates (-20251001) fold into one entry. A custom model with the same slug wins.
  • Each added model gets a Reasoning select from the catalog's supported_reasoning_levels, keeping only levels Claude Code can send (none is dropped), plus Default. These models get no Ultracode, Fast Mode or thinking toggles.
  • Non-Claude routes carry the sub-label <Route> · 200K context.
  • Any other endpoint, an error, or no answer keeps the built-in list unchanged. claude-direct, which points at Anthropic, is untouched.

What Claude Code does with a non-Claude model name

Captured with a local stub gateway at no model cost, Claude Code 2.1.322:

  • It logs unrecognized_model, then runs with a 200K context window and a 32K max_tokens (a Claude model gets 1M and 128K). Its cost reads as unknown.
  • It still sends thinking: adaptive, output_config.effort (it defaults to high when none is set), context_management and three cache_control markers. It drops the per-turn-control beta. Magpie has to translate or ignore these.
  • CLAUDE_CODE_MAX_CONTEXT_TOKENS lifts the window. It's left as a follow-up, because it is process-wide.

Verification

  • vp test run src/provider/MagpieGatewayModels.test.ts: 3 tests pass.
  • check:changed against origin/release/native-0.1.10: format, lint, typecheck and graphql pass. knip and AgentContextBudget.test.ts (mcpToolListJsonBytes 52637 vs 52839) fail identically on the unmodified base, so both are pre-existing.
  • In an isolated dev server on ASUS (worktree .t3), the Claude picker shows the 4 current Claude models, Claude Sonnet 4.5 (latest) labelled "Claude Code", 7 Codex models, 4 Magpie Go models and 1 routing group. Legacy Claude models sit under Show more.
  • I captured a screenshot, but it can't be uploaded from the CLI.
  • End to end through t3 thread start --wait:
    • claude-stub instance on magpie-go/glm-5.3-flash against a stub gateway serving Magpie's real catalog: the reply was ok, and the stub received model: magpie-go/glm-5.3-flash with 16 tools. No paid call was made.
    • Real Magpie claudeAgent instance on claude/claude-sonnet-4-5, a Magpie-only id, with the prompt "Reply with exactly: ok": completed with ok on the included Claude Max route.
    • I made no real magpie-go request, because those keys show no Go subscription and could cost money.

The Codex half of the report is a config fix in the t3_node template: nullStack65/Closura#1955.

Model and harness: Claude Opus 5.5 in Claude Code, running in T3 Code.

🤖 Generated with Claude Code

A Claude instance whose ANTHROPIC_BASE_URL points at Magpie showed only
T3's built-in Claude list. Claude Code's own gateway discovery keeps only
ids containing "claude" or "anthropic", so Codex, Magpie Go and routing-group
models never reached the picker, though Magpie routes them.

The Claude driver now reads the gateway's /v1/models after each status
check. A catalog whose entries carry `magpie_label` is Magpie's. The picker
then keeps the built-in Claude models Magpie serves, with their full
options, and adds every other Magpie model grouped by route. Each added
model gets the reasoning levels its catalog entry states that Claude Code
can send. Non-Claude routes are labelled "200K context", because Claude
Code runs unrecognised model names with a 200K window and a 32K output cap.
Any other endpoint, or no answer, keeps the built-in list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nullStack65

Copy link
Copy Markdown
Owner Author

Bot review round 1 (Claude Sonnet 5.5, independent) @ 392e419

Scope: git diff origin/release/native-0.1.10...392e419a7b (3 files). Static review against AGENTS.md. I could not run the tests, because this worktree has no installed dependencies and no vp. The PR's reported results (3 tests, check:changed) are unverified by me.

No blocking findings.

The merge and dedupe logic holds up, and I could not construct an input that breaks it. Details:

  • Merge and dedupe (MagpieGatewayModels.ts withMagpieGatewayModels). Keys strip the claude/ route, [1m] and a trailing date. They are checked against each built-in's slug and aliases, so claude-haiku-4-5 with a dated alias matches claude/claude-haiku-4-5-20251001. Dated and undated gateway ids fold into one entry. The Claude Code-reported ids that claudeReportedModels adds also match by key and are kept. Custom models are never filtered, and an exact-slug custom model wins over the gateway entry. The default model claude-opus-5-5 (packages/contracts/src/model.ts:146) is served by Magpie, so the default stays in the list.
  • Turns and text generation with the added slugs. compileClaudeModelSelection and ClaudeTextGeneration resolve a slug the catalog doesn't know through resolveClaudeModelSlug, which returns it unchanged. resolveClaudeCatalogEffort (ClaudeModelCatalog.ts:496) maps default to undefined, so no effort is sent, and it passes only low to max. Added models are not custom, so they get no Ultracode toggle, and fastMode stays undefined because the capabilities are empty. The snapshot probe in snapshotForCwd keeps machineSnapshot.models, so the added models survive workspace rescans.
  • Failure paths. Non-200, malformed JSON, a catalog without magpie_label, and transport errors all end in orElseSucceed(() => undefined), which leaves the built-in list. The 3 s timeout wraps the request, status check and body read together. api.anthropic.com is skipped by customClaudeApiEndpointHost, so Anthropic-pointed instances make no extra request and send no credentials.

Non-blocking

  1. Settings-file credentials aren't sent. MagpieGatewayModels.ts:43-44 reads ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY only from processEnv, but ClaudeDriver.ts:283 takes ANTHROPIC_BASE_URL from settings.json env first. readClaudeSettingsEnv doesn't decode token keys (ClaudeSkills.ts:650). Failure: a user who sets the gateway URL and token together in ~/.claude/settings.json gets an unauthenticated /v1/models call. A 401 falls back silently to the built-in list, so the feature looks broken with no signal. The reverse mismatch also exists. If settings.json points the base URL at gateway X while an Anthropic ANTHROPIC_API_KEY is in the process env, that key goes to X in the x-api-key header. Claude Code's own turns would send it there too, so this adds no new exposure. Suggest either reading the token keys from settings env too, or logging at debug when the fetch is rejected.
  2. Redirects. fetchMagpieGatewayCatalog doesn't disable redirect following. Fetch implementations drop Authorization on a cross-origin redirect but keep x-api-key. A gateway that 30x's to another host would receive the key. This is low risk, since the user configured the gateway, but redirect: "manual" or a same-origin check is cheap. I didn't check which HttpClient layer the driver uses, so this is unconfirmed.
  3. Fetch cost on every status check. ClaudeDriver.ts:278-293 re-reads settings and makes an uncached HTTP call, up to 3 s, on every checkProvider run. The call also runs when the CLI is missing, the version probe failed, or auth is error. In those cases the picker is replaced with the gateway list for a provider that can't start a turn. Suggest skipping it unless provider.installed and the status isn't error. Caching by baseUrl for a short TTL would also avoid repeating the call. It's bounded and only affects Magpie or custom-endpoint instances, so it isn't blocking.
  4. Effort caps don't apply to the added models. withGatewayModels runs after capClaudeCatalogEffort (ClaudeProvider.ts:790). A user with maxEffortLevel: "medium" sees an uncapped Max label on gateway models, while the built-ins show "(capped to …)". Claude Code still clamps, so only the label is wrong.
  5. No tests for the fetch path or the custom-key collision. fetchMagpieGatewayCatalog has no test for non-200, bad JSON or the request headers. A tiny HttpClient stub would cover them. It's also untested that a custom model claude-sonnet-4-5 plus gateway claude/claude-sonnet-4-5 yield two entries, because takenSlugs compares exact slugs while the built-ins dedupe by claudeModelKey. The existing merge tests follow the repo rules (pure functions, no timers).
  6. Naming and duplication. The Effect.fn("fetchMagpieGatewayCatalog") span doesn't follow the Service.operation convention, for example MagpieGatewayModels.fetchCatalog. The settings env read in withGatewayModels duplicates the one inside checkClaudeProviderStatus (ClaudeProvider.ts:830).

Simplicity check. The change is a smaller sufficient fix. It adds one pure module, one flatMap in the driver, and no new service or setting. The route ordering and the 200K context label are the only extras, and both come from the PR's captured Claude Code behavior. The hard-coded 200K label will go stale if Claude Code starts recognising these names. That is acceptable for a sub-label.

A redirect from the gateway would carry the x-api-key header to another
host. Refuse redirects as Claude Code's own gateway discovery does.
From bot review round 1 on 392e419.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nullStack65

Copy link
Copy Markdown
Owner Author

Repair round 1 @ 24ed84b

Responds to bot review round 1 on 392e419. There were no blocking findings.

  1. Fixed: redirects. The catalog fetch now sets redirect: "error", the same as CloudSpeech and textGeneratorDrivers, so the key can't follow a redirect to another host. The span is renamed MagpieGatewayModels.fetchCatalog, which was nit 6.
  2. Follow-up, not fixed here:
    • Settings-file credentials: the fetch doesn't read a token set in settings.json. That only matters for a gateway that requires auth on /v1/models, and the fleet's Magpie doesn't, so the result is a silent fallback, not a wrong list.
    • Fetch cost: the uncached fetch, about 3 s at worst, on each status check.
    • Effort-cap labels: added models skip the effort-cap labels. Claude Code still clamps the level.
    • Test gaps: the missing fetch-path tests and the custom-vs-gateway duplicate case.

Verified on the repair: MagpieGatewayModels.test.ts (3 tests pass), and format, lint and the server typecheck pass.

@nullStack65
nullStack65 merged commit 367ca9b into release/native-0.1.10 Nov 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant