Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(routing): split lookup-only names out of CATALOG_ROUTE_BINDINGS
Jack Rudenko21496c141193
diff --git a/CLAUDE.md b/CLAUDE.mdindex 48eb355a..a68ce125 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -119,7 +119,7 @@ negative case: if you are about to type one of those words, stop and use the lef- A new `StatsEvent` field MUST also be pushed in `eventToLogRecord` — `stats-otlp.ts` is a HAND-WRITTEN attribute allowlist, so a field wired only into the interface and `stats.ts` is typed, buffered to `~/.claudish/stats-buffer.json`, and never sent. Nothing errors; the number is just missing from every dashboard, a quarter later. `stats-otlp.test.ts`'s table is `satisfies Record<OptionalStatsKey, …>`, so adding the field breaks compilation until it is listed there too — keep that.- A connection failure can arrive wearing an AUTH status code, at FIVE sites in `composed-handler.ts` (`refreshAuth`, `forceRefreshAuth`, the parameter-recovery re-fetch, `getHeaders`, the primary fetch). 401 is retryable to `FallbackHandler`, so answering it for a network fault walks a subscription user onto metered billing mid-outage; an unclassified THROW is the same bug one layer out (`{status: 0}` + an unconditional advance, with no cost warning). Classify first or rethrow unchanged — never invent a status. `getHeaders()` is the non-obvious one: for `gk@` it is the request's first network touch, and refresh-conditional, so it is rare rather than safe. A TRANSPORT's own `refreshAuth` catch that returns normally is the same bug one layer earlier: `openai-codex.ts` swallowed an unreachable token host and fell through to the metered api-key path.- Anything that renders a TUI to **stderr** must `setStderrQuiet(true)` for as long as it owns the screen, and release it in a `finally`. `logStderr` writes there too, so the two interleave inside one frame: the TUI repaints its own cells over part of the line and the surviving fragments read as a layout bug. `--probe` hit this — the tell was a stray `[c`, the head of `[claudish] `, left in a failed row. The message is not lost; `logStderr` always writes the debug log as well.-- A `route binding` names one endpoint AND one credential silo. A provider that owns neither does not belong in `CATALOG_ROUTE_BINDINGS`, even when its name matches the `routeId`: since `providersForCatalogRoute` returns every provider bound to a route, a placeholder listed there becomes a route candidate and `--probe` prints a hop no key can ever satisfy. Do NOT fix that by filtering `reason: "virtual"` out of the gatherer — `native-anthropic` is virtual and genuinely routable through the native passthrough, so that filter takes `claude-*` away from anyone holding an `ANTHROPIC_API_KEY`.+- A `route binding` names one endpoint AND one credential silo. A provider that owns neither does not belong in `CATALOG_ROUTE_BINDINGS`, even when its name matches the `routeId`: since `routingProvidersForRoute` returns every provider bound to a route, a placeholder listed there becomes a route candidate and `--probe` prints a hop no key can ever satisfy. A name that only READS catalog data through a route (a vendor slug such as `anthropic` for the savings-panel price, `moonshotai` for the Kimi picker list) goes in `LOOKUP_ONLY_ROUTE_BINDINGS`, which the lookups consult and routing never does; a test pins that table's members. Do NOT fix that by filtering `reason: "virtual"` out of the gatherer — `native-anthropic` is virtual and genuinely routable through the native passthrough, so that filter takes `claude-*` away from anyone holding an `ANTHROPIC_API_KEY`.## Commandsdiff --git a/packages/cli/src/providers/catalog-route-bindings.test.ts b/packages/cli/src/providers/catalog-route-bindings.test.tsindex c45bb58e..b14e0855 100644--- a/packages/cli/src/providers/catalog-route-bindings.test.ts+++ b/packages/cli/src/providers/catalog-route-bindings.test.ts@@ -4,7 +4,16 @@ import { tmpdir } from "node:os";import { join } from "node:path";import { type DiskCacheV3, writeAllModelsCache } from "./all-models-cache.js";import { resolveExternalId } from "./catalog-client.js";-import { catalogRouteForProvider, providerForCatalogRoute } from "./catalog-route-bindings.js";+import {+ CATALOG_ROUTE_BINDINGS,+ LOOKUP_ONLY_ROUTE_BINDINGS,+ catalogRouteForProvider,+ catalogRouteMatchesProvider,+ providerForCatalogRoute,+ routingProvidersForRoute,+} from "./catalog-route-bindings.js";+import { PREDEFINED_ENDPOINTS } from "./predefined-catalog.js";+import { BUILTIN_PROVIDERS } from "./provider-definitions.js";const subscriptionBindings = [["native-anthropic", "anthropic", "claude-code-subscription"],@@ -48,6 +57,56 @@ describe("v3 route bindings", () => {providerForCatalogRoute({ routeId: "qwen", routeProfileId: "unrecognised" })).toBeUndefined();});++ test("lookup-only names are exact, non-routable names", () => {+ const lookupNames = Object.keys(LOOKUP_ONLY_ROUTE_BINDINGS);+ const providerNames = new Set([+ ...BUILTIN_PROVIDERS.map((provider) => provider.name),+ ...PREDEFINED_ENDPOINTS.map((endpoint) => endpoint.name),+ ]);++ expect(lookupNames).toEqual(["anthropic", "moonshotai", "zen"]);+ expect(lookupNames.filter((name) => providerNames.has(name))).toEqual([]);+ expect(lookupNames.filter((name) => name in CATALOG_ROUTE_BINDINGS)).toEqual([]);+ });++ test("catalog reads retain literal lookup routes without creating route candidates", () => {+ expect(catalogRouteForProvider("anthropic")).toEqual({+ routeId: "anthropic",+ routeProfileId: "direct-api",+ });+ expect(catalogRouteForProvider("moonshotai")).toEqual({+ routeId: "moonshotai",+ routeProfileId: "direct-api",+ });+ expect(catalogRouteForProvider("zen")).toEqual({+ routeId: "opencode",+ routeProfileId: "zen",+ });++ expect(+ catalogRouteMatchesProvider(+ { routeId: "anthropic", routeProfileId: "direct-api" },+ "anthropic"+ )+ ).toBe(true);+ expect(+ catalogRouteMatchesProvider(+ { routeId: "anthropic", routeProfileId: "claude-code-subscription" },+ "anthropic"+ )+ ).toBe(false);++ expect(+ routingProvidersForRoute({ routeId: "anthropic", routeProfileId: "direct-api" })+ ).toEqual([]);+ expect(+ routingProvidersForRoute({ routeId: "moonshotai", routeProfileId: "direct-api" })+ ).toEqual(["kimi"]);+ expect(routingProvidersForRoute({ routeId: "opencode", routeProfileId: "zen" })).toEqual([+ "opencode-zen",+ ]);+ });});const translations = [diff --git a/packages/cli/src/providers/catalog-route-bindings.ts b/packages/cli/src/providers/catalog-route-bindings.tsindex 851c256a..0474aa13 100644--- a/packages/cli/src/providers/catalog-route-bindings.ts+++ b/packages/cli/src/providers/catalog-route-bindings.ts@@ -4,18 +4,32 @@ export interface CatalogRouteBinding {}/**- * Transport bindings between Claudish providers and catalog v3 routes.- * Model membership and wire IDs remain catalog data; this table only identifies- * the transport adapter that can execute each canonical route.+ * Route bindings between claudish's names and catalog v3 routes, split by job.+ *+ * Model membership and wire ids remain catalog data. These tables only say which+ * name stands for which `(routeId, routeProfileId)` pair, and there are two jobs:+ *+ * - {@link CATALOG_ROUTE_BINDINGS}, the ROUTING table. Every key is a claudish+ * provider, built-in or a bundled catalog row (`together`, `fireworks`), that+ * owns one endpoint and one credential silo. The candidate gatherer reads it+ * through {@link routingProvidersForRoute}, so every key here can become a+ * route candidate.+ * - {@link LOOKUP_ONLY_ROUTE_BINDINGS}, names that catalog READS ask about and+ * that no claudish provider answers to. They are never route candidates.+ *+ * The split exists because the gatherer returns every name bound to a route. A+ * read-only name in the routing table was a candidate by accident of spelling:+ * a custom endpoint a user named `anthropic` would have been gathered for every+ * model Anthropic's native API serves. The reads still see both tables+ * ({@link catalogRouteForProvider}, {@link catalogReadProvidersForRoute}), so each+ * of them answers exactly as before the split.*/export const CATALOG_ROUTE_BINDINGS: Readonly<Record<string, CatalogRouteBinding>> = {"native-anthropic": { routeId: "anthropic", routeProfileId: "claude-code-subscription" },- anthropic: { routeId: "anthropic", routeProfileId: "direct-api" },"openai-codex": { routeId: "openai", routeProfileId: "codex-subscription" },openai: { routeId: "openai", routeProfileId: "direct-api" },"kimi-coding": { routeId: "moonshotai", routeProfileId: "kimi-code-subscription" },kimi: { routeId: "moonshotai", routeProfileId: "direct-api" },- moonshotai: { routeId: "moonshotai", routeProfileId: "direct-api" },"glm-coding": { routeId: "z-ai", routeProfileId: "glm-coding-subscription" },"z-ai": { routeId: "z-ai", routeProfileId: "direct-api" },// The SAME endpoint as `z-ai` (both are https://api.z.ai) under a second@@ -42,11 +56,11 @@ export const CATALOG_ROUTE_BINDINGS: Readonly<Record<string, CatalogRouteBinding// that owns neither — no baseUrl, no apiPath, no apiKeyEnvVar — and// `qwen-payg` is what actually calls dashscope. It was listed here while// `providerForCatalogRoute` returned only the FIRST provider per route, which- // hid it behind `qwen-payg`. v10.0.0's `providersForCatalogRoute` returns all- // of them (the z-ai/glm key-silo fix) and the placeholder surfaced: a- // `Qwen ✗ key missing` hop in `--probe qwen3.8-max`, sending the reader after- // a key no environment variable can hold. `route()` never yielded it, so the- // damage was confined to the display.+ // hid it behind `qwen-payg`. v10.0.0 made the gatherer take all of them (the+ // z-ai/glm key-silo fix, now `routingProvidersForRoute`) and the placeholder+ // surfaced: a `Qwen ✗ key missing` hop in `--probe qwen3.8-max`, sending the+ // reader after a key no environment variable can hold. `route()` never yielded+ // it, so the damage was confined to the display.//// Not fixed by filtering placeholders out of the gatherer: `native-anthropic`// is a placeholder too, by the same `reason: "virtual"` marker, and it IS@@ -56,7 +70,6 @@ export const CATALOG_ROUTE_BINDINGS: Readonly<Record<string, CatalogRouteBinding// claim lived, so it is where the correction belongs."opencode-zen-go": { routeId: "opencode", routeProfileId: "go-subscription" },"opencode-zen": { routeId: "opencode", routeProfileId: "zen" },- zen: { routeId: "opencode", routeProfileId: "zen" },ollamacloud: { routeId: "ollama", routeProfileId: "cloud" },openrouter: { routeId: "openrouter", routeProfileId: "gateway" },together: { routeId: "together-ai", routeProfileId: "gateway" },@@ -67,39 +80,103 @@ export const CATALOG_ROUTE_BINDINGS: Readonly<Record<string, CatalogRouteBindingmistralai: { routeId: "mistralai", routeProfileId: "direct-api" },};+/**+ * Names that catalog READS ask about and that no claudish provider answers to.+ *+ * {@link routingProvidersForRoute} never sees this table, so none of these names+ * can become a route candidate. Each entry names its reader; a name whose reader+ * goes away should go with it.+ */+export const LOOKUP_ONLY_ROUTE_BINDINGS: Readonly<Record<string, CatalogRouteBinding>> = {+ // Anthropic's native API. Its reader is the session summary's savings panel,+ // which takes the first-party price from this route (`FIRST_PARTY` in+ // `session/baseline-pricing.ts`). The probe map also keys this route's probe+ // pick under this name (`probe-catalog.ts`). claudish calls Claude through+ // `native-anthropic` or a gateway, never through this route.+ anthropic: { routeId: "anthropic", routeProfileId: "direct-api" },+ // The catalog's vendor slug for Kimi. Its reader is the Kimi picker list: the+ // picker maps `kimi` to `moonshotai` (`pickerProviderToFirebaseSlug` in+ // `model-selector.ts`) and asks `modelsByVendor("moonshotai")` and+ // `servedByVendor("moonshotai")`. The provider that calls this route is `kimi`.+ moonshotai: { routeId: "moonshotai", routeProfileId: "direct-api" },+ // The shortcut spelling of `opencode-zen`, kept as a legacy picker value+ // (`PROVIDER_MODEL_PREFIX_OVERRIDE` in `model-selector.ts`). Its reader is the+ // picker's wire-id and price lookup (`resolveProviderAggregatorEntry`) when a+ // caller still passes that value. `zen@<id>` itself parses to `opencode-zen`.+ zen: { routeId: "opencode", routeProfileId: "zen" },+};++/**+ * The route a name is bound to, in either table.+ *+ * Every catalog read asks through this (`catalogRouteMatchesProvider`,+ * `externalIdFor`, the availability filter, the picker), so a lookup-only name+ * answers exactly as it did when it sat in the routing table.+ */export function catalogRouteForProvider(provider: string): CatalogRouteBinding | undefined {- return CATALOG_ROUTE_BINDINGS[provider];+ return CATALOG_ROUTE_BINDINGS[provider] ?? LOOKUP_ONLY_ROUTE_BINDINGS[provider];}-export function providerForCatalogRoute(+function namesBoundTo(+ table: Readonly<Record<string, CatalogRouteBinding>>,route: CatalogRouteBinding | undefined-): string | undefined {- return providersForCatalogRoute(route)[0];+): string[] {+ if (!route) return [];+ return Object.entries(table)+ .filter(+ ([, binding]) =>+ binding.routeId === route.routeId && binding.routeProfileId === route.routeProfileId+ )+ .map(([name]) => name);}/**- * EVERY claudish provider bound to one catalog route, in declaration order.+ * EVERY claudish provider bound to one catalog route, in declaration order. The+ * candidate gatherer's question (`route-candidates.ts`), answered from the routing+ * table only.*- * The binding table is many-to-one on purpose: one endpoint can wear several- * claudish names because each name owns a different key silo (`glm` and `z-ai`- * are both https://api.z.ai, under ZHIPU_API_KEY and ZAI_API_KEY), and some- * names are legacy spellings kept so an old `provider@model` spec still parses.+ * The routing table is many-to-one on purpose: one endpoint can wear several+ * claudish names because each name owns a different key silo. Today that is one+ * pair, `z-ai` and `glm`, both https://api.z.ai, under ZAI_API_KEY and+ * ZHIPU_API_KEY.*- * Routing must consider all of them, and {@link providerForCatalogRoute} — which- * answers with the first — silently hid the rest: a user whose key sat in the+ * Routing must consider all of them. {@link providerForCatalogRoute}, which+ * answers with the first, silently hid the rest: a user whose key sat in the* second silo lost the model by bare name, with no error, because the candidate* carrying their credential was never gathered. Deciding WHICH of them serves is- * the credential filter's job; a name with no provider definition drops out on- * its own, one layer down, since it has no tier.+ * the credential filter's job. A bundled catalog row (`together`, `fireworks`)+ * that has not registered in this process has no definition and so no tier, and+ * the gatherer drops it one layer down.*/-export function providersForCatalogRoute(route: CatalogRouteBinding | undefined): string[] {- if (!route) return [];- return Object.entries(CATALOG_ROUTE_BINDINGS)- .filter(- ([, binding]) =>- binding.routeId === route.routeId && binding.routeProfileId === route.routeProfileId- )- .map(([provider]) => provider);+export function routingProvidersForRoute(route: CatalogRouteBinding | undefined): string[] {+ return namesBoundTo(CATALOG_ROUTE_BINDINGS, route);+}++/**+ * Every name bound to one catalog route, for a catalog READ: the routing names in+ * declaration order, then the lookup-only names. Never a routing input.+ *+ * Routing names come first, so the first answer is a provider whenever one is+ * bound: `kimi` before `moonshotai`, `opencode-zen` before `zen`. `anthropic` is+ * the only name on `anthropic/direct-api`.+ */+export function catalogReadProvidersForRoute(route: CatalogRouteBinding | undefined): string[] {+ return [+ ...namesBoundTo(CATALOG_ROUTE_BINDINGS, route),+ ...namesBoundTo(LOOKUP_ONLY_ROUTE_BINDINGS, route),+ ];+}++/**+ * One name per route, for a read that wants exactly one: the first name+ * {@link catalogReadProvidersForRoute} returns. Readers: the probe map+ * (`probe-catalog.ts`), the aggregator slug set (`model-catalog.ts`) and the+ * recommended-models list (`model-loader.ts`).+ */+export function providerForCatalogRoute(+ route: CatalogRouteBinding | undefined+): string | undefined {+ return catalogReadProvidersForRoute(route)[0];}export function catalogRouteMatchesProvider(diff --git a/packages/cli/src/providers/custom-endpoints-loader.test.ts b/packages/cli/src/providers/custom-endpoints-loader.test.tsindex d550942f..c11b489a 100644--- a/packages/cli/src/providers/custom-endpoints-loader.test.ts+++ b/packages/cli/src/providers/custom-endpoints-loader.test.ts@@ -3,9 +3,13 @@*/import { afterEach, beforeEach, describe, expect, test } from "bun:test";+import { mkdtempSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";import { credentials } from "../auth/credentials/authority.js";import { __resetSniffForTests } from "../auth/credentials/op-source.js";import type { ClaudishProfileConfig } from "../profile-config.js";+import { type DiskCacheV3, writeAllModelsCache } from "./all-models-cache.js";import {loadCustomEndpoints,resolveCustomEndpointApiKey,@@ -108,6 +112,90 @@ describe("custom-endpoints-loader", () => {expect(getRuntimeProfiles().get("my-vllm")).toBeDefined();});+ test("custom endpoint named anthropic is not a route candidate for a Claude model", () => {+ const dir = mkdtempSync(join(tmpdir(), "claudish-anthropic-endpoint-"));+ const cachePath = join(dir, "cloud-models-catalog-v3.json");++ try {+ const cache: DiskCacheV3 = {+ version: 3,+ catalogGenerationId: "stage8-custom-endpoint-fixture",+ lastUpdated: "2026-09-24T00:00:00.000Z",+ entries: [+ {+ modelId: "claude-stage8",+ aliases: [],+ provider: "anthropic",+ aggregators: [+ {+ sourceProviderId: "anthropic",+ sourceCollectorId: "stage8-fixture",+ confidence: "api_official",+ routeStatus: "mapped",+ route: { routeId: "anthropic", routeProfileId: "direct-api" },+ externalModelId: "claude-stage8",+ },+ ],+ },+ ],+ models: [],+ plans: [],+ };+ writeAllModelsCache(cache, cachePath);++ const loaderModuleUrl = new URL("./custom-endpoints-loader.ts", import.meta.url).href;+ const candidatesModuleUrl = new URL("./route-candidates.ts", import.meta.url).href;+ const runtimeModuleUrl = new URL("./runtime-providers.ts", import.meta.url).href;+ const script = `+ const { loadCustomEndpoints } = await import(${JSON.stringify(loaderModuleUrl)});+ const { gatherRouteCandidates } = await import(${JSON.stringify(candidatesModuleUrl)});+ const { clearRuntimeRegistry } = await import(${JSON.stringify(runtimeModuleUrl)});+ try {+ const loaded = loadCustomEndpoints({+ version: "1.0.0",+ defaultProfile: "default",+ profiles: {},+ customEndpoints: {+ anthropic: {+ kind: "simple",+ url: "https://custom-anthropic.invalid/v1",+ format: "openai",+ apiKey: "none",+ },+ },+ });+ const providers = gatherRouteCandidates("claude-stage8", ${JSON.stringify(cachePath)})+ .candidates.map((candidate) => candidate.provider);+ process.stdout.write(JSON.stringify({ loaded, providers }));+ } finally {+ clearRuntimeRegistry();+ }+ `;+ const child = Bun.spawnSync([process.execPath, "-e", script], {+ cwd: join(import.meta.dir, "../../../.."),+ env: {+ ...process.env,+ HOME: dir,+ CLAUDISH_DISABLE_CATALOG_WARM: "1",+ CLAUDISH_DISABLE_KEYCHAIN: "1",+ CLAUDISH_DISABLE_OP: "1",+ },+ stdout: "pipe",+ stderr: "pipe",+ });+ const stdout = child.stdout.toString();+ const stderr = child.stderr.toString();++ expect(child.exitCode, stderr || stdout).toBe(0);+ expect(JSON.parse(stdout)).toEqual({+ loaded: { registered: 1, errors: [], refused: [] },+ providers: [],+ });+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+test("valid complex endpoint with litellm transport: registers", () => {const result = loadCustomEndpoints(makeConfig({diff --git a/packages/cli/src/providers/custom-endpoints-loader.ts b/packages/cli/src/providers/custom-endpoints-loader.tsindex b352667a..df47108b 100644--- a/packages/cli/src/providers/custom-endpoints-loader.ts+++ b/packages/cli/src/providers/custom-endpoints-loader.ts@@ -245,8 +245,11 @@ export function loadCustomEndpoints(config: ClaudishProfileConfig): LoadResult {** Not `fallback`: that tier is a POSITION held by whichever provider* `defaultProvider` names, and no definition may claim it.+ *+ * Exported for the route-binding guard: a bundled row gets a definition only when+ * it registers, which needs its key, so a hermetic test reads the tier here.*/-const CUSTOM_ENDPOINT_TIER: RouteTier = "gateway";+export const CUSTOM_ENDPOINT_TIER: RouteTier = "gateway";/*** Build a ProviderDefinition for a custom endpoint so it appears in lookupsdiff --git a/packages/cli/src/providers/model-catalog.ts b/packages/cli/src/providers/model-catalog.tsindex 09af32f2..8274345f 100644--- a/packages/cli/src/providers/model-catalog.ts+++ b/packages/cli/src/providers/model-catalog.ts@@ -116,9 +116,11 @@ export interface CatalogClient {* slug is in this set we prefer `getModelsByProvider()` which returns the* full ModelDoc shape.*- * Note: a slug can be BOTH an owner and an aggregator (e.g. "anthropic" owns- * Claude models AND appears in some `aggregators[]` lists). The owner path- * wins because it returns more complete data.+ * Note: a slug can be BOTH an owner and a name bound to a route. "anthropic"+ * owns Claude models AND names Anthropic's native API route+ * (`anthropic/direct-api`, a lookup-only binding in `catalog-route-bindings.ts`:+ * no claudish provider calls it). The owner path wins because it returns more+ * complete data.*/const OWNER_PROVIDER_SLUGS = new Set<string>(["anthropic",diff --git a/packages/cli/src/providers/provider-definitions.test.ts b/packages/cli/src/providers/provider-definitions.test.tsindex 2222757b..690917d9 100644--- a/packages/cli/src/providers/provider-definitions.test.ts+++ b/packages/cli/src/providers/provider-definitions.test.ts@@ -18,6 +18,8 @@ import {import { setConfigFileOverride } from "../profile-config.js";import { API_KEY_MAP } from "./api-key-map.js";import { CATALOG_ROUTE_BINDINGS } from "./catalog-route-bindings.js";+import { CUSTOM_ENDPOINT_TIER } from "./custom-endpoints-loader.js";+import { PREDEFINED_ENDPOINTS } from "./predefined-catalog.js";import {BUILTIN_PROVIDERS,getApiKeyEnvVars,@@ -206,19 +208,19 @@ describe("BUILTIN_PROVIDERS structural integrity", () => {});test("catalog bindings exclude the qwen steering placeholder but retain native passthrough", () => {- let resolvedBuiltinBindings = 0;-- for (const providerName of Object.keys(CATALOG_ROUTE_BINDINGS)) {- const provider = getProviderByName(providerName);- if (!provider) continue;-- resolvedBuiltinBindings += 1;- expect(provider.tier).toBeDefined();- }+ const builtinsByName = new Map(+ BUILTIN_PROVIDERS.map((provider) => [provider.name, provider] as const)+ );+ const bundledTiers = new Map(+ PREDEFINED_ENDPOINTS.map((endpoint) => [endpoint.name, CUSTOM_ENDPOINT_TIER] as const)+ );+ const offenders = Object.keys(CATALOG_ROUTE_BINDINGS).filter((providerName) => {+ const builtin = builtinsByName.get(providerName);+ if (builtin) return builtin.tier === undefined;+ return bundledTiers.get(providerName) === undefined;+ });- // The loop must exercise real bindings, not pass vacuously on an empty or- // wholly unresolved table.- expect(resolvedBuiltinBindings).toBeGreaterThan(0);+ expect(offenders).toEqual([]);// qwen only steers bare names; qwen-payg owns dashscope and its credentials.expect(CATALOG_ROUTE_BINDINGS.qwen).toBeUndefined();@@ -621,6 +623,19 @@ describe("billing classification", () => {]);});+ test("name-decided subscription billing matches the subscription tiers", () => {+ const derived = BUILTIN_PROVIDERS.filter(+ (provider) =>+ (provider.tier === "subscription" || provider.tier === "dynamic-subscription") &&+ provider.name !== "native-anthropic" &&+ !CREDENTIAL_DECIDED_PROVIDERS.has(provider.name)+ )+ .map((provider) => provider.name)+ .sort();++ expect([...SUBSCRIPTION_PROVIDERS].sort()).toEqual(derived);+ });+test("every billing-set member names a real provider", () => {// The sets hold canonical uids only, deliberately — enumerating shortcut// spellings would be a second hand-written spelling table free to drift fromdiff --git a/packages/cli/src/providers/provider-definitions.ts b/packages/cli/src/providers/provider-definitions.tsindex 6c06d4ed..47ccd92b 100644--- a/packages/cli/src/providers/provider-definitions.ts+++ b/packages/cli/src/providers/provider-definitions.ts@@ -1482,8 +1482,8 @@ export const BUILTIN_PROVIDERS: TieredProviderDefinition[] = [// It used to carry `openaiHandler` and a comment arguing it was unreachable// anyway, because `providerForCatalogRoute` returned only the FIRST provider// bound to `qwen/dashscope-direct` and `qwen-payg` is the earlier key. v10.0.0- // replaced that with `providersForCatalogRoute`, which returns ALL of them —- // the z-ai/glm key-silo fix — and deleted the premise. This became a gathered+ // made the gatherer take ALL of them (now `routingProvidersForRoute`) — the+ // z-ai/glm key-silo fix — and deleted the premise. This became a gathered// candidate, so `--probe qwen3.8-max` printed a `Qwen ✗ key missing` hop and// sent the reader looking for a key that no environment variable can hold.// `route()` never yielded it (the credential filter drops it), so the damagediff --git a/packages/cli/src/providers/route-candidates.test.ts b/packages/cli/src/providers/route-candidates.test.tsindex 9715ba5c..a2c278b5 100644--- a/packages/cli/src/providers/route-candidates.test.ts+++ b/packages/cli/src/providers/route-candidates.test.ts@@ -5,7 +5,7 @@ import { join } from "node:path";import { credentials } from "../auth/credentials/authority.js";import { type DiskCacheV3, type SlimModelEntry, writeAllModelsCache } from "./all-models-cache.js";import { _resetCatalogClient, _setCatalogEntriesForTest } from "./catalog-client.js";-import { providersForCatalogRoute } from "./catalog-route-bindings.js";+import { routingProvidersForRoute } from "./catalog-route-bindings.js";import {getModelDiscoveryFetcher,invalidateModelDiscovery,@@ -245,7 +245,7 @@ describe("catalog route candidate gathering and order", () => {test("gathers every provider bound to z-ai/direct-api", () => {const binding = { routeId: "z-ai", routeProfileId: "direct-api" };- expect(providersForCatalogRoute(binding)).toEqual(["z-ai", "glm"]);+ expect(routingProvidersForRoute(binding)).toEqual(["z-ai", "glm"]);const direct = gatherRouteCandidates("glm-4.7", cachePath).candidates.filter(({ wireId }) => wireId === "glm-4.7"diff --git a/packages/cli/src/providers/route-candidates.ts b/packages/cli/src/providers/route-candidates.tsindex d628fe08..6dd4a7a5 100644--- a/packages/cli/src/providers/route-candidates.ts+++ b/packages/cli/src/providers/route-candidates.ts@@ -70,7 +70,7 @@ import {type CatalogRouteBinding,catalogRouteForProvider,catalogRouteMatchesProvider,- providersForCatalogRoute,+ routingProvidersForRoute,} from "./catalog-route-bindings.js";import {type ConnectionPrice,@@ -194,8 +194,9 @@ function gatherFromConnections(// EVERY provider bound to this route, not just the first. One endpoint can// wear several claudish names, each owning a different key silo, and the- // user's credential may be in any of them — see `providersForCatalogRoute`.- const bound = providersForCatalogRoute(connection.route);+ // user's credential may be in any of them — see `routingProvidersForRoute`.+ // The routing table only: a lookup-only name is never a candidate.+ const bound = routingProvidersForRoute(connection.route);const routable = bound.filter((name) => getProviderByName(name)?.tier !== undefined);if (routable.length === 0) {unmappedRoutes.add(routeLabel(connection.route));@@ -436,12 +437,13 @@ export function catalogDeniesProvider(if (!entry) return false;// `catalogRouteMatchesProvider`, NOT `providerForCatalogRoute(...) === provider`.- // The reverse lookup returns the FIRST provider bound to a route pair, and- // four pairs have two claudish names each (`kimi`/`moonshotai`,- // `opencode-zen`/`zen`, `qwen-payg`/`qwen`). Comparing its answer would have- // declared `moonshotai` denied on every model `kimi` serves — a real denial- // built out of an alias. Comparing BINDINGS is what `externalIdFor` and- // `model-availability.ts` already do, for this reason.+ // The reverse lookup returns ONE name per route pair, and a pair can carry+ // several. In the routing table only `z-ai`/`glm` share one (two key silos on+ // one endpoint); the reads add `kimi`/`moonshotai` and `opencode-zen`/`zen`+ // through the lookup-only names. Comparing its answer would declare `glm`+ // denied on every model `z-ai` serves, a denial built out of a second key+ // silo. Comparing BINDINGS is what `externalIdFor` and `model-availability.ts`+ // already do, for this reason.return !(entry.aggregators ?? []).some((connection) =>connection.routeStatus === "mapped" && catalogRouteMatchesProvider(connection.route, provider)diff --git a/packages/cli/src/session/baseline-pricing.test.ts b/packages/cli/src/session/baseline-pricing.test.tsnew file mode 100644index 00000000..c72da08b--- /dev/null+++ b/packages/cli/src/session/baseline-pricing.test.ts@@ -0,0 +1,107 @@+import { afterAll, describe, expect, test } from "bun:test";+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";++const home = mkdtempSync(join(tmpdir(), "claudish-stage8-baselines-"));+const cacheDir = join(home, ".claudish");+const cachePath = join(cacheDir, "cloud-models-catalog-v3.json");++mkdirSync(cacheDir, { recursive: true });+writeFileSync(+ cachePath,+ JSON.stringify({+ version: 3,+ catalogGenerationId: "stage8-baseline-fixture",+ lastUpdated: "2026-09-24T00:00:00.000Z",+ entries: [+ {+ modelId: "claude-opus-stage8",+ aliases: ["~anthropic/claude-opus-latest"],+ aggregators: [+ {+ sourceProviderId: "native-anthropic",+ sourceCollectorId: "stage8-fixture",+ confidence: "scrape_verified",+ routeStatus: "mapped",+ route: { routeId: "anthropic", routeProfileId: "claude-code-subscription" },+ externalModelId: "claude-opus-stage8",+ pricing: { type: "flat", input: 1, output: 2 },+ },+ {+ sourceProviderId: "openrouter",+ sourceCollectorId: "stage8-fixture",+ confidence: "aggregator_reported",+ routeStatus: "mapped",+ route: { routeId: "openrouter", routeProfileId: "gateway" },+ externalModelId: "anthropic/claude-opus-stage8",+ pricing: { type: "flat", input: 10, output: 50 },+ },+ {+ sourceProviderId: "anthropic",+ sourceCollectorId: "stage8-fixture",+ confidence: "api_official",+ routeStatus: "mapped",+ route: { routeId: "anthropic", routeProfileId: "direct-api" },+ externalModelId: "claude-opus-stage8",+ pricing: { type: "flat", input: 5, output: 25 },+ },+ ],+ },+ {+ modelId: "claude-sonnet-stage8",+ aliases: ["~anthropic/claude-sonnet-latest"],+ aggregators: [+ {+ sourceProviderId: "anthropic",+ sourceCollectorId: "stage8-fixture",+ confidence: "api_official",+ routeStatus: "mapped",+ route: { routeId: "anthropic", routeProfileId: "direct-api" },+ externalModelId: "claude-sonnet-stage8",+ pricing: { type: "unavailable" },+ },+ ],+ },+ ],+ models: [],+ plans: [],+ }),+ "utf8"+);++afterAll(() => {+ rmSync(home, { recursive: true, force: true });+});++describe("baseline pricing catalog reads", () => {+ test("uses Anthropic direct-api pricing and omits unavailable tiers", () => {+ const moduleUrl = new URL("./baseline-pricing.ts", import.meta.url).href;+ const script = `+ const { getBaselines } = await import(${JSON.stringify(moduleUrl)});+ process.stdout.write(JSON.stringify(getBaselines()));+ `;+ const result = Bun.spawnSync([process.execPath, "-e", script], {+ cwd: join(import.meta.dir, "../../../.."),+ env: {+ ...process.env,+ HOME: home,+ CLAUDISH_DISABLE_CATALOG_WARM: "1",+ },+ stdout: "pipe",+ stderr: "pipe",+ });+ const stdout = result.stdout.toString();+ const stderr = result.stderr.toString();++ expect(result.exitCode, stderr || stdout).toBe(0);+ expect(JSON.parse(stdout)).toEqual([+ {+ modelId: "claude-opus-stage8",+ label: "Opus",+ inputPerM: 5,+ outputPerM: 25,+ },+ ]);+ });+});diff --git a/packages/cli/src/session/baseline-pricing.ts b/packages/cli/src/session/baseline-pricing.tsindex 3ca0ca45..e124d784 100644--- a/packages/cli/src/session/baseline-pricing.ts+++ b/packages/cli/src/session/baseline-pricing.ts@@ -51,7 +51,12 @@ const BASELINE_ALIASES: ReadonlyArray<{ alias: string; label: string }> = [{ alias: "~anthropic/claude-opus-latest", label: "Opus" },];-/** The catalog provider whose price counts as the reference. See file header. */+/**+ * The name bound to Anthropic's native API route (`anthropic/direct-api`), whose+ * price counts as the reference. See file header. It is a lookup-only binding+ * (`LOOKUP_ONLY_ROUTE_BINDINGS`), kept for reads like this one: no claudish+ * provider calls that route.+ */const FIRST_PARTY = "anthropic";/**