feat(claude): source model list from cc-switch, gated by env#975
feat(claude): source model list from cc-switch, gated by env#9758liang wants to merge 3 commits into
Conversation
Read the claude provider model list from cc-switch's current claude provider (alias→real-model mapping in settings_config.env) instead of the static fallback. The OPTIONS value stays a CLI alias (opus/sonnet/haiku/fable) that cc-switch's proxy rewrites; the label surfaces the real model name. Gated behind CLAUDE_CC_SWITCH_MODELS_ENABLED (default false) with CLAUDE_CC_SWITCH_DB_PATH overriding the default ~/.cc-switch/cc-switch.db. Falls back to the static list when disabled, the DB is missing, or no aliases are configured. Documented in .env.example.
📝 WalkthroughWalkthroughAdds an opt-in cc-switch integration for the Claude models provider: environment variables document and control reading model aliases from a cc-switch SQLite database, ChangesCC-Switch Model Sourcing
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ClaudeProviderModels
participant CcSwitchResolver as resolveClaudeModelsFromCcSwitch
participant CcSwitchDB as cc-switch SQLite DB
Caller->>ClaudeProviderModels: getSupportedModels()
ClaudeProviderModels->>CcSwitchResolver: check enabled, resolve aliases
CcSwitchResolver->>CcSwitchDB: read settings_config for "claude" provider
CcSwitchDB-->>CcSwitchResolver: JSON env map
alt env map valid
CcSwitchResolver-->>ClaudeProviderModels: ProviderModelsDefinition with aliases
else disabled, missing DB, or invalid data
CcSwitchResolver-->>ClaudeProviderModels: null
end
ClaudeProviderModels-->>Caller: resolved aliases or CLAUDE_FALLBACK_MODELS
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/modules/providers/list/claude/claude-models.provider.ts (1)
104-116: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider logging when cc-switch fallback is triggered.
The catch-all at line 112 silently swallows all errors. While expected failures (DB missing, locked, malformed JSON) correctly trigger the static fallback, programming errors (SQL typos, unexpected data shapes) would also be hidden. A debug-level log would help users distinguish "cc-switch not configured" from "something broke."
♻️ Optional: add a debug log on fallback
const resolveClaudeModelsFromCcSwitch = async (): Promise<ProviderModelsDefinition | null> => { if (!isCcSwitchModelsEnabled()) { return null; } try { const env = await readClaudeAliasMapFromCcSwitch(); return env ? buildClaudeModelsFromCcSwitch(env) : null; - } catch { - // DB missing, locked, malformed, or better-sqlite3 unavailable — fall back. + } catch (error) { + // DB missing, locked, malformed, or better-sqlite3 unavailable — fall back. + logger?.debug?.('cc-switch model resolution failed, using static fallback', error); return null; } };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/modules/providers/list/claude/claude-models.provider.ts` around lines 104 - 116, In resolveClaudeModelsFromCcSwitch, the catch-all currently hides every failure when cc-switch fallback is used. Add a debug-level log inside the catch block that records the fallback trigger and includes the caught error, while still returning null so static fallback continues. Keep the behavior in buildClaudeModelsFromCcSwitch and readClaudeAliasMapFromCcSwitch unchanged, and make sure the log clearly distinguishes expected cc-switch unavailability from unexpected failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@server/modules/providers/list/claude/claude-models.provider.ts`:
- Around line 104-116: In resolveClaudeModelsFromCcSwitch, the catch-all
currently hides every failure when cc-switch fallback is used. Add a debug-level
log inside the catch block that records the fallback trigger and includes the
caught error, while still returning null so static fallback continues. Keep the
behavior in buildClaudeModelsFromCcSwitch and readClaudeAliasMapFromCcSwitch
unchanged, and make sure the log clearly distinguishes expected cc-switch
unavailability from unexpected failures.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2b822cca-8847-40a1-b4d9-3ad9793e7802
📒 Files selected for processing (3)
.env.exampleserver/modules/providers/list/claude/claude-models.provider.tsserver/modules/providers/tests/claude-models.test.ts
Read the claude provider model list from cc-switch's current claude provider (alias→real-model mapping in settings_config.env) instead of the static fallback. The OPTIONS value stays a CLI alias (opus/sonnet/haiku/fable) that cc-switch's proxy rewrites; the label surfaces the real model name.
Gated behind CLAUDE_CC_SWITCH_MODELS_ENABLED (default false) with CLAUDE_CC_SWITCH_DB_PATH overriding the default ~/.cc-switch/cc-switch.db. Falls back to the static list when disabled, the DB is missing, or no aliases are configured. Documented in .env.example.
Summary by CodeRabbit
New Features
Bug Fixes
Tests