Skip to content

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

fix(advisor): stop sending Claude Code selectors as Anthropic model ids

Jack Rudenko6899f3e2dbe9
diff --git a/packages/cli/src/handlers/advisor-claude-route.ts b/packages/cli/src/handlers/advisor-claude-route.ts
index f1b56c84..e36a80d7 100644
--- a/packages/cli/src/handlers/advisor-claude-route.ts
+++ b/packages/cli/src/handlers/advisor-claude-route.ts
@@ -16,6 +16,11 @@
import { latestAnthropicTierModelId } from "../providers/catalog-client.js";
import { findEntryByAlias } from "../providers/catalog-query.js";
+import {
+ CLAUDE_CODE_MODEL_ALIASES,
+ ONE_MILLION_CONTEXT_SUFFIX,
+ claudeCodeTierAlias,
+} from "../providers/claude-code-aliases.js";
/** The Anthropic API origin. `NativeHandler` forwards to it; the advisor calls it. */
export const ANTHROPIC_API_ORIGIN = "https://api.anthropic.com";
@@ -26,27 +31,38 @@ export const ANTHROPIC_MESSAGES_URL = `${ANTHROPIC_API_ORIGIN}/v1/messages`;
/** The host of {@link ANTHROPIC_API_ORIGIN}, for notices and records. */
export const ANTHROPIC_API_HOST = new URL(ANTHROPIC_API_ORIGIN).host;
-/** Why a Claude name cannot be sent to the API as a model id. */
-export type ClaudeAdvisorModelRefusal = "unresolved-alias";
+/**
+ * Why a Claude name cannot be sent to the API as a model id.
+ *
+ * - `claude-selector`: a Claude Code selector that names no single model the
+ * API accepts (`opusplan`, `best`, any `[1m]` form).
+ * - `unresolved-alias`: a tier alias the catalog holds no id for (it is cold
+ * or has never been fetched).
+ */
+export type ClaudeAdvisorModelRefusal = "claude-selector" | "unresolved-alias";
/** The Anthropic model id a Claude name stands for, or why there is none. */
export type ClaudeAdvisorModel =
| { refused: false; id: string }
- | { refused: true; cause: ClaudeAdvisorModelRefusal; alias: string };
+ | { refused: true; cause: ClaudeAdvisorModelRefusal; alias: string; reason: string };
-/**
- * The Claude Code TIER an advisor spec names as a bare alias (`haiku`), or null
- * for anything already spelled as a model id (`claude-haiku-4-5`). Only an
- * alias needs resolving; an id is passed through as the user wrote it.
- */
-function anthropicTierAlias(model: string): "opus" | "sonnet" | "haiku" | null {
- const m = model.toLowerCase();
- return m === "opus" || m === "sonnet" || m === "haiku" ? m : null;
+function selectorRefusal(alias: string, reason: string): ClaudeAdvisorModel {
+ return { refused: true, cause: "claude-selector", alias, reason };
}
/**
* The Anthropic model id for a Claude name (the model part of the spec, with
- * any `anthropic@` already removed).
+ * any `anthropic@` already removed), over every name native recognition
+ * admits (`isClaudeCodeModelName`):
+ *
+ * | Name (trimmed, case-insensitive) | Outcome |
+ * |-----------------------------------------|--------------------------------------------|
+ * | ends with `[1m]` | refused: the API takes no `[1m]` in an id |
+ * | a tier alias (`opus`, `sonnet`, `haiku`, and `internal`/`default` → `opus`) | the tier's id from the catalog, else refused `unresolved-alias` |
+ * | `opusplan` | refused: it switches tier with the mode |
+ * | `best` | refused: Claude Code's own rating |
+ * | any other Claude Code alias | refused (a guard: an alias added later) |
+ * | anything else (a `claude-*` id) | passed through as written |
*
* The alias itself is never the answer. It used to fall through as `?? model`,
* so the default collector POSTed the literal `haiku` to api.anthropic.com,
@@ -54,10 +70,54 @@ function anthropicTierAlias(model: string): "opus" | "sonnet" | "haiku" | null {
* `haiku -> api.anthropic.com (ANTHROPIC_API_KEY, billed per token)`.
*/
export function claudeAdvisorModelFor(model: string): ClaudeAdvisorModel {
- const tier = anthropicTierAlias(model);
- if (!tier) return { refused: false, id: model };
- const resolved = findEntryByAlias(model)?.modelId ?? latestAnthropicTierModelId(tier);
- return resolved
- ? { refused: false, id: resolved }
- : { refused: true, cause: "unresolved-alias", alias: model };
+ const normalized = model.trim().toLowerCase();
+
+ if (normalized.endsWith(ONE_MILLION_CONTEXT_SUFFIX)) {
+ return selectorRefusal(
+ model,
+ `"${model}" uses Claude Code's 1M-context selector, which Claude Code applies and the ` +
+ `Anthropic API does not accept in a model id; name the model without "${ONE_MILLION_CONTEXT_SUFFIX}".`
+ );
+ }
+
+ const tier = claudeCodeTierAlias(normalized);
+ if (tier) {
+ // The TIER's alias, not the name: `internal` and `default` select the opus
+ // tier, and the catalog's alias table knows the tier.
+ const resolved = findEntryByAlias(tier)?.modelId ?? latestAnthropicTierModelId(tier);
+ if (resolved) return { refused: false, id: resolved };
+ return {
+ refused: true,
+ cause: "unresolved-alias",
+ alias: model,
+ reason:
+ `"${model}" is a claudish alias, not a model id ${ANTHROPIC_API_HOST} accepts, and the ` +
+ "model catalog holds no id for it, so claudish refused to send it. Name the model by its " +
+ "full model id, or refresh the catalog (`claudish --models-refresh`).",
+ };
+ }
+
+ if (normalized === "opusplan") {
+ return selectorRefusal(
+ model,
+ `"${model}" switches tier with Claude Code's mode, so it names no single model; name a ` +
+ "tier (opus, sonnet, haiku) or a model id."
+ );
+ }
+ if (normalized === "best") {
+ return selectorRefusal(
+ model,
+ `"${model}" is Claude Code's own choice of model and claudish has no source for it; name ` +
+ "a tier or a model id."
+ );
+ }
+ if ((CLAUDE_CODE_MODEL_ALIASES as readonly string[]).includes(normalized)) {
+ return selectorRefusal(
+ model,
+ `"${model}" is a Claude Code selector, not a model id the Anthropic API accepts; name a ` +
+ "tier (opus, sonnet, haiku) or a model id."
+ );
+ }
+
+ return { refused: false, id: model };
}
diff --git a/packages/cli/src/handlers/native-handler-advisor.ts b/packages/cli/src/handlers/native-handler-advisor.ts
index 164e1425..434962fc 100644
--- a/packages/cli/src/handlers/native-handler-advisor.ts
+++ b/packages/cli/src/handlers/native-handler-advisor.ts
@@ -42,6 +42,7 @@ import { getCatalogEntries } from "../providers/catalog-client.js";
import { resolveConnection, resolveRouteProfile } from "../providers/connection-resolver.js";
import { type KnownWire, type WireApi, wireRequestUrl } from "../providers/connection-wire.js";
import { parseModelSpec } from "../providers/model-parser.js";
+import { nativeRouteFor } from "../providers/native-route.js";
import { mergeWireHeaders, shapeRequestFromWire } from "../providers/wire-request.js";
import { claudeAdvisorModelFor } from "./advisor-claude-route.js";
import { extractProviderMessage, extractUpstreamStatus } from "./shared/anthropic-error.js";
@@ -1590,22 +1591,27 @@ function routeOf(kind: AdvisorRouteKind, wireModel: string): AdvisorRoute {
* - `google@`/`gemini@` (and bare `gemini-*`) → the direct Gemini API.
* - `openai@`/`oai@` (and bare `gpt-*`) → api.openai.com with the metered
* OPENAI_API_KEY, never the Codex login.
- * - a Claude model (`claude-*`, `haiku`, `sonnet`, `opus`, `anthropic@`) →
- * the Anthropic Messages API, but ONLY as the collector. A Claude panel
- * member goes to OpenRouter, as it always did.
+ * - a Claude model (`claude-*`, any name Claude Code owns such as `haiku` or
+ * `internal`, `anthropic@`) → the Anthropic Messages API, but ONLY as the
+ * collector. A Claude panel member goes to OpenRouter, as it always did.
* - everything else (e.g. `grok-4.6` → `x-ai`) → OpenRouter, the id resolved
* through the catalog.
*
+ * Throws for a Claude Code selector that names no model id the API accepts
+ * (`opusplan`, `best`, any `[1m]` form): startup refuses the launch with the
+ * message, and the runtime collector reports it as its failure.
+ *
* Not subscription routing: the advisor never goes through `route()`.
*/
export function advisorRouteFor(modelSpec: string, role: "panel" | "collector"): AdvisorRoute {
const parsed = parseModelSpec(modelSpec);
- if (role === "collector" && isAnthropicModel(parsed)) {
+ if (role === "collector" && (isAnthropicModel(parsed) || nativeRouteFor(modelSpec))) {
// The Anthropic id comes from `claudeAdvisorModelFor` (the leaf shared with
- // the startup planner); an alias the catalog cannot resolve is marked, never
- // POSTed.
+ // the startup planner). A selector is refused outright; an alias the
+ // catalog cannot resolve is marked, never POSTed.
const claude = claudeAdvisorModelFor(parsed.model);
+ if (claude.refused && claude.cause === "claude-selector") throw new Error(claude.reason);
if (claude.refused)
return { ...routeOf("anthropic", claude.alias), unresolvedAlias: claude.alias };
return routeOf("anthropic", claude.id);
diff --git a/packages/cli/src/providers/claude-code-aliases.ts b/packages/cli/src/providers/claude-code-aliases.ts
index a6bd1c08..c47475ae 100644
--- a/packages/cli/src/providers/claude-code-aliases.ts
+++ b/packages/cli/src/providers/claude-code-aliases.ts
@@ -81,7 +81,7 @@ export const CLAUDE_CODE_MODEL_ALIASES = [
] as const;
/** Claude Code's 1M-context selector, appended to an alias or a `claude-` id: `sonnet[1m]`. */
-const ONE_MILLION_CONTEXT_SUFFIX = "[1m]";
+export const ONE_MILLION_CONTEXT_SUFFIX = "[1m]";
/**
* Whether Claude Code owns this bare name: one of its aliases, optionally with the