Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(catalog): give the v3 cache its own file, and the OpenRouter list another

Jack Rudenkoaf02ca359203
diff --git a/packages/cli/src/adapters/model-catalog.ts b/packages/cli/src/adapters/model-catalog.ts
index c8dc96b9..e3572b46 100644
--- a/packages/cli/src/adapters/model-catalog.ts
+++ b/packages/cli/src/adapters/model-catalog.ts
@@ -2,7 +2,7 @@
* Model metadata catalog — Firebase slim cache is the sole source of truth.
*
* All model facts (contextWindow, supportsVision) come from the slim catalog
- * at ~/.claudish/all-models.json, populated at proxy startup by the OpenRouter
+ * at ~/.claudish/cloud-models-catalog-v3.json, populated at proxy startup by the OpenRouter
* catalog resolver.
*
* Adapter-specific behavior (temperature ranges, tool name limits, max tool
@@ -61,7 +61,7 @@ export interface ModelEntry {
* - modelId isn't in the cache
* - The entry exists but has no `contextWindow`
*
- * @param cachePath Override cache path. Defaults to `~/.claudish/all-models.json`.
+ * @param cachePath Override cache path. Defaults to `~/.claudish/cloud-models-catalog-v3.json`.
* Only tests should pass this.
*/
export function lookupModel(modelId: string, cachePath?: string): ModelEntry | undefined {
diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts
index 275d05e1..6ab059e6 100644
--- a/packages/cli/src/cli.ts
+++ b/packages/cli/src/cli.ts
@@ -98,9 +98,10 @@ export function getVersion(): string {
* Clear writable claudish caches (pricing, LiteLLM, recommended models).
* Called when --models-refresh flag is used.
*
- * NOTE: We intentionally do NOT delete `all-models.json` — that file is the
- * OpenRouter catalog resolver's slim-catalog cache, sourced from Firebase.
- * Deleting it would force a cold re-warm on every --models-refresh call.
+ * NOTE: We intentionally do NOT delete `cloud-models-catalog-v3.json`, the cloud
+ * models catalog cache. Deleting it would force a cold re-warm on every
+ * --models-refresh call. `all-models.json` is not ours to delete either: older
+ * claudish builds still read it.
*/
function clearAllModelCaches(): void {
const cacheDir = join(homedir(), ".claudish");
diff --git a/packages/cli/src/handlers/composed-handler.ts b/packages/cli/src/handlers/composed-handler.ts
index 7e078564..471e9527 100644
--- a/packages/cli/src/handlers/composed-handler.ts
+++ b/packages/cli/src/handlers/composed-handler.ts
@@ -141,7 +141,7 @@ export interface ComposedHandlerOptions {
sessionEventRegistry?: SessionEventRegistry;
/**
* Test seam for the model-catalog cache path used by preset resolution.
- * Defaults to ~/.claudish/all-models.json. Only tests should pass this.
+ * Defaults to ~/.claudish/cloud-models-catalog-v3.json. Only tests should pass this.
*/
catalogCachePath?: string;
}
diff --git a/packages/cli/src/launcher/catalog-warm.ts b/packages/cli/src/launcher/catalog-warm.ts
index 9535451a..f092e32b 100644
--- a/packages/cli/src/launcher/catalog-warm.ts
+++ b/packages/cli/src/launcher/catalog-warm.ts
@@ -326,7 +326,7 @@ function reportUnusableCatalog(
// It reaches here through `CLAUDISH_DISABLE_CATALOG_WARM=1`, which
// `scripts/guard-real-config.ts` sets on the whole test run — and the e2e
// suites spawn `src/index.ts` as a child, which inherits it. So on a machine
- // with no `~/.claudish/all-models.json`, the untreated path fails those tests
+ // with no `~/.claudish/cloud-models-catalog-v3.json`, the untreated path fails those tests
// with a network diagnosis.
//
// "skipped" is the accurate answer, and it is the same one
diff --git a/packages/cli/src/mcp-server.ts b/packages/cli/src/mcp-server.ts
index 345c0156..f62e727c 100644
--- a/packages/cli/src/mcp-server.ts
+++ b/packages/cli/src/mcp-server.ts
@@ -87,7 +87,10 @@ const __dirname = dirname(__filename);
// ─── Constants ───────────────────────────────────────────────────────────────
const CLAUDISH_CACHE_DIR = join(homedir(), ".claudish");
-const ALL_MODELS_CACHE_PATH = join(CLAUDISH_CACHE_DIR, "all-models.json");
+// OpenRouter's own model list, for `search_models`. Its OWN file: this once shared
+// `all-models.json` with the cloud models catalog cache, and each writer erased the
+// other's data, because the two hold different shapes.
+const OPENROUTER_MODELS_CACHE_PATH = join(CLAUDISH_CACHE_DIR, "openrouter-models.json");
const CACHE_MAX_AGE_DAYS = 2;
/** Instructions added to Claude's system prompt when channel mode is active. */
@@ -183,9 +186,9 @@ interface ToolDefinition {
// ─── Helper Functions ────────────────────────────────────────────────────────
async function loadAllModels(forceRefresh = false): Promise<any[]> {
- if (!forceRefresh && existsSync(ALL_MODELS_CACHE_PATH)) {
+ if (!forceRefresh && existsSync(OPENROUTER_MODELS_CACHE_PATH)) {
try {
- const cacheData = JSON.parse(readFileSync(ALL_MODELS_CACHE_PATH, "utf-8"));
+ const cacheData = JSON.parse(readFileSync(OPENROUTER_MODELS_CACHE_PATH, "utf-8"));
const lastUpdated = new Date(cacheData.lastUpdated);
const ageInDays = (Date.now() - lastUpdated.getTime()) / (1000 * 60 * 60 * 24);
if (ageInDays <= CACHE_MAX_AGE_DAYS) {
@@ -203,14 +206,14 @@ async function loadAllModels(forceRefresh = false): Promise<any[]> {
const models = data.data || [];
mkdirSync(CLAUDISH_CACHE_DIR, { recursive: true });
writeFileSync(
- ALL_MODELS_CACHE_PATH,
+ OPENROUTER_MODELS_CACHE_PATH,
JSON.stringify({ lastUpdated: new Date().toISOString(), models }),
"utf-8"
);
return models;
} catch {
- if (existsSync(ALL_MODELS_CACHE_PATH)) {
- const cacheData = JSON.parse(readFileSync(ALL_MODELS_CACHE_PATH, "utf-8"));
+ if (existsSync(OPENROUTER_MODELS_CACHE_PATH)) {
+ const cacheData = JSON.parse(readFileSync(OPENROUTER_MODELS_CACHE_PATH, "utf-8"));
return cacheData.models || [];
}
return [];
diff --git a/packages/cli/src/model-selector.ts b/packages/cli/src/model-selector.ts
index 291d5f13..38cc5e08 100644
--- a/packages/cli/src/model-selector.ts
+++ b/packages/cli/src/model-selector.ts
@@ -297,7 +297,7 @@ const SUBSCRIPTION_PRICING: ModelInfo["pricing"] = {
* THIS subscription, so it beats any catalog (Kimi Coding reports it; Qwen
* Plan does not). On a miss, fall back to the Firebase slim catalog, which
* already knows most of these models — that is a read of the local
- * `~/.claudish/all-models.json`, never a network call, so the picker never
+ * `~/.claudish/cloud-models-catalog-v3.json`, never a network call, so the picker never
* blocks on it. Still-unknown stays 0 and renders as "N/A": there is no
* per-model cloud lookup, because a window the slim catalog lacks is a
* models-index gap, not something N extra round-trips can discover.
diff --git a/packages/cli/src/providers/all-models-cache.ts b/packages/cli/src/providers/all-models-cache.ts
index 09e37d00..5eb8c14c 100644
--- a/packages/cli/src/providers/all-models-cache.ts
+++ b/packages/cli/src/providers/all-models-cache.ts
@@ -89,7 +89,17 @@ export interface DiskCacheV3 {
catalogGenerationId: string;
}
-export const ALL_MODELS_CACHE_PATH = join(homedir(), ".claudish", "all-models.json");
+/**
+ * The cloud models catalog cache: contract-3 data, in a file of its own.
+ *
+ * NOT `all-models.json`. That name belongs to older claudish builds, which read
+ * it as a v2 catalog; a v3 cache written there crashed them on every bare-name
+ * route (`TypeError … entry.sources["openrouter-api"]`, measured 2026-09-19),
+ * and it was ALSO the file the MCP server overwrote with an OpenRouter model dump.
+ * A contract change gets a new file, so no build ever reads a shape it cannot
+ * parse. `all-models.json` is left untouched for the builds that still read it.
+ */
+export const ALL_MODELS_CACHE_PATH = join(homedir(), ".claudish", "cloud-models-catalog-v3.json");
function hasRoute(value: unknown): value is { routeId: string; routeProfileId: string } {
if (!value || typeof value !== "object") return false;
diff --git a/packages/cli/src/providers/catalog-query.ts b/packages/cli/src/providers/catalog-query.ts
index d06380a8..6c62034b 100644
--- a/packages/cli/src/providers/catalog-query.ts
+++ b/packages/cli/src/providers/catalog-query.ts
@@ -1,6 +1,6 @@
/**
* Read-only accessor module over the slim model catalog cache
- * (`~/.claudish/all-models.json`).
+ * (`~/.claudish/cloud-models-catalog-v3.json`).
*
* Used by feature code that needs to look up catalog entries without going
* through the full `OpenRouterCatalogResolver` resolution chain. The resolver
@@ -77,7 +77,7 @@ function project(entry: SlimModelEntry): CatalogEntryQueryResult {
// ---------------------------------------------------------------------------
//
// The pricing-cache lookup runs on every proxied request. Re-reading and
-// JSON-parsing `~/.claudish/all-models.json` each call adds non-trivial
+// JSON-parsing `~/.claudish/cloud-models-catalog-v3.json` each call adds non-trivial
// overhead (the slim catalog can hold hundreds of entries). We cache the
// parsed entries in module scope and invalidate whenever the file's `mtimeMs`
// changes — that catches both writes from `OpenRouterCatalogResolver`'s
diff --git a/packages/cli/src/providers/model-catalog.ts b/packages/cli/src/providers/model-catalog.ts
index b7ffe96d..8da0532e 100644
--- a/packages/cli/src/providers/model-catalog.ts
+++ b/packages/cli/src/providers/model-catalog.ts
@@ -65,7 +65,7 @@ export interface CatalogClient {
*
* For aggregator/gateway providers (e.g. "opencode-zen", "openrouter"):
* returns models whose `aggregators[]` lists this vendor. Reads from the
- * slim catalog cache at ~/.claudish/all-models.json (24h TTL).
+ * slim catalog cache at ~/.claudish/cloud-models-catalog-v3.json (24h TTL).
*
* For LiteLLM, Ollama, LM Studio: returns []. These have no Firebase
* catalog by design — callers handle this with a free-text input prompt.
@@ -274,7 +274,7 @@ export interface CatalogClientDeps {
getModelsByProvider?: typeof getModelsByProvider;
getModelByIdFromFirebase?: typeof getModelByIdFromFirebase;
searchModels?: typeof searchModelsFromFirebase;
- /** Returns the parsed slim cache or null. Default reads ~/.claudish/all-models.json. */
+ /** Returns the parsed slim cache or null. Default reads ~/.claudish/cloud-models-catalog-v3.json. */
readSlimCache?: () => ReturnType<typeof readAllModelsCache>;
}
diff --git a/packages/cli/src/providers/provider-profiles.ts b/packages/cli/src/providers/provider-profiles.ts
index eb364f0f..0112335c 100644
--- a/packages/cli/src/providers/provider-profiles.ts
+++ b/packages/cli/src/providers/provider-profiles.ts
@@ -76,7 +76,7 @@ export interface ProfileContext {
*
* `requiresResponsesApi` reads the model catalog, which made the composition
* table in `provider-profiles.test.ts` depend on whichever
- * `~/.claudish/all-models.json` the machine happened to have. That is the
+ * `~/.claudish/cloud-models-catalog-v3.json` the machine happened to have. That is the
* v7.43.0 trap: green on every dev box, and a different answer on a cold CI
* runner. Passing a fixture path here keeps that table hermetic.
*/
@@ -245,7 +245,7 @@ export const devinProfile: ProviderProfile = {
* opinion to read.
*
* @param cachePath Test seam. Points the catalog lookup at a fixture, so a test
- * never depends on a warm `~/.claudish/all-models.json`.
+ * never depends on a warm `~/.claudish/cloud-models-catalog-v3.json`.
*/
export function requiresResponsesApi(modelName: string, cachePath?: string): boolean {
const endpoint = lookupModelEndpoint(modelName, "openai", cachePath);
diff --git a/packages/cli/src/session-events/pro-injection.ts b/packages/cli/src/session-events/pro-injection.ts
index ab4a9271..d66a2f71 100644
--- a/packages/cli/src/session-events/pro-injection.ts
+++ b/packages/cli/src/session-events/pro-injection.ts
@@ -91,7 +91,7 @@ export interface ProInjectionOptions {
outputConfig?: { effort?: unknown; format?: unknown } | null;
/** Test seam — defaults to the process-wide registry. */
registry?: SessionEventRegistry;
- /** Test seam — catalog cache path. Defaults to ~/.claudish/all-models.json. */
+ /** Test seam — catalog cache path. Defaults to ~/.claudish/cloud-models-catalog-v3.json. */
cachePath?: string;
}
diff --git a/scripts/guard-real-config.ts b/scripts/guard-real-config.ts
index ffeb7110..fdeeda1b 100644
--- a/scripts/guard-real-config.ts
+++ b/scripts/guard-real-config.ts
@@ -24,8 +24,9 @@
* the bytes back is the part that actually saves them.
*
* GUARDED is a list rather than one path because the convention decayed again,
- * in exactly the shape the paragraph above describes. `all-models.json` is the
- * hosted model catalog's disk cache, and `effort-mapping.test.ts` seeds a
+ * in exactly the shape the paragraph above describes. `all-models.json` was the
+ * hosted model catalog's disk cache (since contract 3 it is
+ * `cloud-models-catalog-v3.json`), and `effort-mapping.test.ts` seeded a
* fixture into it and restores in a `finally`. That is the same save/restore
* pattern the config files used, with the same hole: a killed or timed-out run
* skips the restore and the two-entry fixture becomes the machine's permanent
@@ -57,7 +58,7 @@ import { join } from "node:path";
/**
* Every real file a test run must give back unchanged. `label` names it in the
* failure, and `remedy` states the isolation the author should have used — the
- * two files have different answers, so the message cannot be generic.
+ * files have different answers, so the message cannot be generic.
*/
const GUARDED = [
{
@@ -66,12 +67,24 @@ const GUARDED = [
remedy: "isolate with setConfigFileOverride(<temp path>) instead of writing the real file",
},
{
- path: join(homedir(), ".claudish", "all-models.json"),
- label: "REAL MODEL CATALOG CACHE",
+ path: join(homedir(), ".claudish", "cloud-models-catalog-v3.json"),
+ label: "REAL CLOUD MODELS CATALOG CACHE",
remedy:
"pass a temp path to readAllModelsCache/writeAllModelsCache, or seed in memory the way " +
"catalog-client.ts's _setCatalogEntriesForTest does, instead of writing the real cache",
},
+ {
+ // The pre-v3 cache file. This build no longer writes it, but older builds on the
+ // same machine still read it, so a test that touches it breaks them.
+ path: join(homedir(), ".claudish", "all-models.json"),
+ label: "REAL PRE-V3 MODEL CATALOG CACHE",
+ remedy: "nothing in this build writes all-models.json; find the test that still names it",
+ },
+ {
+ path: join(homedir(), ".claudish", "openrouter-models.json"),
+ label: "REAL OPENROUTER MODEL LIST",
+ remedy: "run the MCP search_models path against a temp HOME instead of the real cache dir",
+ },
{
path: join(homedir(), ".claudish", "catalog-incompatible.json"),
label: "REAL CATALOG CONTRACT SENTINEL",