Skip to content

feat(claude): source model list from cc-switch, gated by env#975

Open
8liang wants to merge 3 commits into
siteboon:mainfrom
8liang:feat/source-model-list-from-cc-switch
Open

feat(claude): source model list from cc-switch, gated by env#975
8liang wants to merge 3 commits into
siteboon:mainfrom
8liang:feat/source-model-list-from-cc-switch

Conversation

@8liang

@8liang 8liang commented Jul 8, 2026

Copy link
Copy Markdown

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

    • Added an optional CC-switch integration for Claude model selection, allowing model aliases to resolve dynamically when enabled.
    • Documented new environment settings for turning the feature on and overriding the database path.
  • Bug Fixes

    • Added safe fallback behavior so Claude model selection continues to work if the optional integration is disabled or unavailable.
  • Tests

    • Added coverage for CC-switch-enabled model resolution, custom database paths, and fallback behavior.

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.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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, getSupportedModels() uses resolved aliases when available and falls back to static CLAUDE_FALLBACK_MODELS otherwise, with accompanying tests.

Changes

CC-Switch Model Sourcing

Layer / File(s) Summary
Environment variable documentation
.env.example
Documents CLAUDE_CC_SWITCH_MODELS_ENABLED and CLAUDE_CC_SWITCH_DB_PATH for optional cc-switch integration behavior.
cc-switch resolver and provider integration
server/modules/providers/list/claude/claude-models.provider.ts
Adds os/path imports, cc-switch DB read/parse helpers, tier-to-alias mapping, and updates getSupportedModels() to use resolved cc-switch aliases or fall back to CLAUDE_FALLBACK_MODELS.
cc-switch integration tests
server/modules/providers/tests/claude-models.test.ts
Adds test helpers for a temporary cc-switch SQLite DB and env toggling, plus tests for alias resolution, DB path override, and multiple fallback scenarios.

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
Loading

Possibly related PRs

  • siteboon/claudecodeui#806: Both PRs directly modify ClaudeProviderModels.getSupportedModels() and change how the supported-model list is produced.
  • siteboon/claudecodeui#834: Updates the CLAUDE_FALLBACK_MODELS entries that this PR's cc-switch integration falls back to in the same file.

Suggested reviewers: viper151

Poem

A rabbit peeked inside a switch,
and found aliases without a hitch,
opus, sonnet, haiku too,
fable joins the model crew,
if the DB's gone, no need to fear —
fallback models still appear! 🐇🔀

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: sourcing Claude models from cc-switch behind an environment flag.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
server/modules/providers/list/claude/claude-models.provider.ts (1)

104-116: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4fff0ff and 95cf237.

📒 Files selected for processing (3)
  • .env.example
  • server/modules/providers/list/claude/claude-models.provider.ts
  • server/modules/providers/tests/claude-models.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant