-
Notifications
You must be signed in to change notification settings - Fork 24
feat(gateway): admit non-Anthropic models to Claude Code CLI picker #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yyyr-p
wants to merge
5
commits into
Menci:main
Choose a base branch
from
yyyr-p:worktree-discovery-cc-picker-prefix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1558b0a
feat(gateway): admit non-Anthropic models into Claude Code CLI picker
yyyr-p d9fb6a5
test(gateway): cover the claude-code: prefix rewrite and strip-retry
yyyr-p 4f45363
chore(lint): fix import order and trailing blank line
yyyr-p 909485f
fix(gateway): drop non-chat models from Claude Code CLI picker
yyyr-p d62f943
docs(gateway): cite the model-discovery protocol page
yyyr-p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
packages/gateway/src/data-plane/models/claude-code-prefix.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // The Claude Code CLI's gateway-discovery model picker (enabled by the | ||
| // `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1` env var) applies two | ||
| // filters to the `/v1/models` payload before populating its `/model` | ||
| // menu. Anthropic documents both filters at | ||
| // https://code.claude.com/docs/en/llm-gateway-protocol#model-discovery: | ||
| // | ||
| // > Claude Code reads `id` and the optional `display_name` from each | ||
| // > entry in the response's `data` array, and ignores entries whose | ||
| // > `id` doesn't begin with `claude` or `anthropic`. | ||
| // | ||
| // > A discovered ID is skipped when it exactly matches a row already | ||
| // > in the picker, or when both the discovered and existing IDs | ||
| // > resolve to Fable. | ||
| // | ||
| // The compiled implementation matches the docs verbatim; the shape is | ||
| // | ||
| // models.filter(m => /^(claude|anthropic)/i.test(m.id)) | ||
| // .filter(m => { const fam = knownFamily(m.id); return fam === null || fam === fable5Family; }) | ||
| // | ||
| // where `knownFamily` walks the CLI's built-in id→family map. Extracted | ||
| // from `@anthropic-ai/[email protected]`'s compiled `Bootstrap Gateway | ||
| // /v1/models` handler, captured 2026-07-16 by grepping the Bun-compiled | ||
| // darwin-arm64 binary around the `[Bootstrap] Gateway /v1/models` | ||
| // telemetry strings; the docs are the primary source-of-truth and the | ||
| // binary extraction pins the exact carve-out (`fable5`) and evaluation | ||
| // order the prose leaves implicit. | ||
| // | ||
| // Consequences for gateway callers: | ||
| // | ||
| // - `label: display_name ?? id` — the picker renders `display_name` to | ||
| // the user; the id itself is only shown on the wire. Rewriting the | ||
| // id is invisible in the UI. | ||
| // - The synthetic prefix used here (`claude-code:`) starts with | ||
| // `claude`, so any non-Anthropic id we advertise passes the first | ||
| // filter. It never exact-matches a built-in family string, so the | ||
| // second filter also passes (`knownFamily('claude-code:gpt-5')` | ||
| // returns null). This mirrors the same de-collision trick that | ||
| // lets `<id>[1m]` variants surface — the bracket suffix guarantees | ||
| // the synthesized id can never coincide with a built-in family | ||
| // string. | ||
| // | ||
| // The prefix is a Floway-owned convention: `claude-code:` was chosen | ||
| // over `claude-` because a bare `claude-` prefix would masquerade a | ||
| // non-Anthropic model as a Claude family member in any log / trace / | ||
| // error the user sees; the `code:` segment plus the colon separator | ||
| // make it visually obvious to anyone reading the wire that the id is | ||
| // a gateway alias, not an upstream-native Anthropic name. | ||
| export const CLAUDE_CODE_SYNTHETIC_PREFIX = 'claude-code:'; | ||
|
|
||
| // Ids the CLI's `/^(claude|anthropic)/i` picker filter accepts without | ||
| // prefixing. Kept as a single shared regex so `toClaudeCodeShape` (which | ||
| // decides whether to prepend) and any future consumer stay in lockstep. | ||
| export const CLAUDE_CODE_PICKER_ID_ACCEPT = /^(claude|anthropic)/i; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on hold since this PR manipulated the model resolution