Skip to content

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

refactor(routing): add isClaudeCodeModelName to claude-code-aliases

Jack Rudenkod91d355d5b5e
diff --git a/packages/cli/src/providers/claude-code-aliases.test.ts b/packages/cli/src/providers/claude-code-aliases.test.ts
index 358c4c62..4118d3df 100644
--- a/packages/cli/src/providers/claude-code-aliases.test.ts
+++ b/packages/cli/src/providers/claude-code-aliases.test.ts
@@ -1,5 +1,49 @@
import { describe, expect, test } from "bun:test";
-import { claudeCodeTierAlias, normalizeNativeModelSpec } from "./claude-code-aliases.js";
+import {
+ CLAUDE_CODE_MODEL_ALIASES,
+ claudeCodeTierAlias,
+ isClaudeCodeModelName,
+ normalizeNativeModelSpec,
+} from "./claude-code-aliases.js";
+
+describe("isClaudeCodeModelName", () => {
+ test("pins Claude Code's model alias list", () => {
+ expect(CLAUDE_CODE_MODEL_ALIASES).toEqual([
+ "opus",
+ "sonnet",
+ "haiku",
+ "internal",
+ "default",
+ "opusplan",
+ "best",
+ ]);
+ });
+
+ test("accepts every alias with and without the 1M-context suffix", () => {
+ for (const alias of CLAUDE_CODE_MODEL_ALIASES) {
+ expect(isClaudeCodeModelName(alias), alias).toBe(true);
+ expect(isClaudeCodeModelName(`${alias}[1m]`), `${alias}[1m]`).toBe(true);
+ }
+ });
+
+ test("accepts concrete claude ids, including dated and 1M-context ids", () => {
+ for (const model of ["claude-opus-5", "claude-haiku-4-5-20251001", "claude-opus-4-6[1m]"]) {
+ expect(isClaudeCodeModelName(model), model).toBe(true);
+ }
+ });
+
+ test("ignores case and surrounding whitespace", () => {
+ for (const model of [" OPUS ", " Sonnet[1M] ", " CLAUDE-OPUS-5 "]) {
+ expect(isClaudeCodeModelName(model), model).toBe(true);
+ }
+ });
+
+ test("rejects foreign, incomplete, empty, and provider-like names", () => {
+ for (const model of ["o4-mini", "swe-1.7", "gpt-5", "claude", "", "@model"]) {
+ expect(isClaudeCodeModelName(model), model).toBe(false);
+ }
+ });
+});
describe("claudeCodeTierAlias", () => {
test("maps every Claude Code alias to its tier", () => {
diff --git a/packages/cli/src/providers/claude-code-aliases.ts b/packages/cli/src/providers/claude-code-aliases.ts
index bf0325c2..931639e4 100644
--- a/packages/cli/src/providers/claude-code-aliases.ts
+++ b/packages/cli/src/providers/claude-code-aliases.ts
@@ -61,6 +61,44 @@ export function claudeCodeTierAlias(model: string): ClaudeTier | null {
return TIER_ALIASES[model.trim().toLowerCase()] ?? null;
}
+/**
+ * Every alias Claude Code itself accepts as a `--model` value. A superset of the
+ * {@link TIER_ALIASES} keys, so keep every tier alias listed here too. `opusplan`
+ * (which switches tier with the mode) and `best` (whatever Claude Code rates most
+ * capable) are not in the tier table, but Claude Code owns them all the same.
+ */
+export const CLAUDE_CODE_MODEL_ALIASES = [
+ "opus",
+ "sonnet",
+ "haiku",
+ "internal",
+ "default",
+ "opusplan",
+ "best",
+] as const;
+
+/** Claude Code's 1M-context selector, appended to an alias or a `claude-` id: `sonnet[1m]`. */
+const ONE_MILLION_CONTEXT_SUFFIX = "[1m]";
+
+/**
+ * Whether Claude Code owns this bare name: one of its aliases, optionally with the
+ * `[1m]` suffix, or any `claude-` id (the suffix included). Trimmed and
+ * case-insensitive.
+ *
+ * A different question from {@link claudeCodeTierAlias}, which asks which tier to
+ * substitute: `opus[1m]`, `sonnet[1m]`, `opusplan` and `best` are Claude Code's
+ * names, and the tier table answers null for each. Not a model name at all (`""`,
+ * `@model`), `claude` with no dash, and every other vendor's id are false.
+ */
+export function isClaudeCodeModelName(name: string): boolean {
+ const normalized = name.trim().toLowerCase();
+ if (normalized.startsWith("claude-")) return true;
+ const alias = normalized.endsWith(ONE_MILLION_CONTEXT_SUFFIX)
+ ? normalized.slice(0, -ONE_MILLION_CONTEXT_SUFFIX.length)
+ : normalized;
+ return (CLAUDE_CODE_MODEL_ALIASES as readonly string[]).includes(alias);
+}
+
/**
* Normalize a `--model` value so a native-Anthropic SELECTOR becomes a name
* Claude Code actually recognises.