-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add model override in cli #476
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
base: main
Are you sure you want to change the base?
feat: add model override in cli #476
Conversation
|
Specifically, if you understand how CCR works, you'll know why /model doesn't work. CCR spawns the Claude code, and the parameters are passed to it based on the settings in CCR's config.json. Therefore, if a parameter is not defined in CCR's configuration, it cannot be used by the Claude code. To solve this, I've created a feature to override the default model information in config.json and improved it so that it can be used within the Claude code. |
https://github.com/musistudio/claude-code-router?tab=readme-ov-file#-features
Does the You've vibe coded a convoluted and overly complex feature, that is already built in... ❯ ccr code --model 'abcd,not/real'
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /Users/user/Repos/github.com/herp-derp │
│ │
│ ─────────────────────────────────────────────── │
│ │
│ Overrides (via env): │
│ │
│ • API timeout: 600000ms │
│ • API Base URL: http://127.0.0.1:3456 │
╰───────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────╮
│ │
│ Select Model │
│ Switch between Claude models. Applies to this session and future │
│ Claude Code sessions. For custom model names, specify with │
│ --model. │
│ │
│ 1. Default (recommended) Use the default model (currently │
│ Sonnet 4) · $3/$15 per Mtok │
│ 2. Opus Opus 4.1 for complex tasks · $15/$75 │
│ per Mtok │
│ 3. Opus Plan Mode Use Opus 4.1 in plan mode, Sonnet 4 │
│ otherwise │
│ ❯ 4. abcd,not/real Custom model✔ │
│ │
╰──────────────────────────────────────────────────────────────────────╯
Enter to confirm · Esc to exit
> /model
⎿ Kept model as abcd,not/real
> test
⎿ API Error: 404 {"error":{"message":"Provider 'abcd' not
foundError: Provider 'abcd' not found\n at bt
(/opt/homebrew/lib/node_modules/@musistudio/claude-code-router/
dist/cli.js:74721:11)\n at o0 (/opt/homebrew/lib/node_module
s/@musistudio/claude-code-router/dist/cli.js:74745:17)\n at
Object.<anonymous> (/opt/homebrew/lib/node_modules/@musistudio/
claude-code-router/dist/cli.js:74795:86)\n at
preHandlerCallbackInner (/opt/homebrew/lib/node_modules/@musist
udio/claude-code-router/dist/cli.js:4522:28)\n at
preHandlerCallback (/opt/homebrew/lib/node_modules/@musistudio/
claude-code-router/dist/cli.js:4494:9)\n at next
(/opt/homebrew/lib/node_modules/@musistudio/claude-code-router/
dist/cli.js:3661:13)\n at handleResolve
(/opt/homebrew/lib/node_modules/@musistudio/claude-code-router/
dist/cli.js:3676:11)\n at process.processTicksAndRejections
(node:internal/process/task_queues:105:5)","type":"api_error","
code":"provider_not_found"}}
> /model humans,hallucinate/too
⎿ Set model to humans,hallucinate/too
> hi
⎿ API Error: 404 {"error":{"message":"Provider 'humans' not
foundError: Provider 'humans' not found\n at bt
(/opt/homebrew/lib/node_modules/@musistudio/claude-code-router/
dist/cli.js:74721:11)\n at o0 (/opt/homebrew/lib/node_module
s/@musistudio/claude-code-router/dist/cli.js:74745:17)\n at
Object.<anonymous> (/opt/homebrew/lib/node_modules/@musistudio/
claude-code-router/dist/cli.js:74795:86)\n at
preHandlerCallbackInner (/opt/homebrew/lib/node_modules/@musist
udio/claude-code-router/dist/cli.js:4522:28)\n at
preHandlerCallback (/opt/homebrew/lib/node_modules/@musistudio/
claude-code-router/dist/cli.js:4494:9)\n at next
(/opt/homebrew/lib/node_modules/@musistudio/claude-code-router/
dist/cli.js:3661:13)\n at handleResolve
(/opt/homebrew/lib/node_modules/@musistudio/claude-code-router/
dist/cli.js:3676:11)\n at process.processTicksAndRejections
(node:internal/process/task_queues:105:5)","type":"api_error","
code":"provider_not_found"}}
╭──────────────────────────────────────────────────────────────────────╮
│ > │
╰──────────────────────────────────────────────────────────────────────╯
|
I'm a big fan of this project! I've implemented some features that I needed during my usage. I'd love to get your feedback and review.
Overview
Add --model CLI option to override the default model configuration at runtime
Objective
Currently, Claude Code Router uses the model configuration from config.json for all requests. Users need to manually edit the configuration file to use a different model temporarily. This PR adds a --model command-line option that allows users to override the default model for a specific ccr code execution without modifying the configuration file.
Solution
Implemented a model override mechanism by leveraging the existing auth token communication channel between the CLI client and server:
- Added parsing for --model option in the code command
- Format: ccr code --model provider,model "prompt"
- Updated help text with usage examples
- Since CLI and server run in separate processes, embedded model override in auth token
- Format: test:MODEL:{encoded_model} where commas are encoded as ___
- This approach works reliably because Claude CLI forwards ANTHROPIC_AUTH_TOKEN
- Added preHandler hook to extract model override from auth token
- Decodes the model string and overrides the router configuration
- Only affects the specific request, not global configuration
Usage Example