Skip to content

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

Open
8liang wants to merge 2 commits into
siteboon:mainfrom
8liang:main
Open

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

Conversation

@8liang

@8liang 8liang commented Jun 27, 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 optional cc-switch integration for Claude model selection, allowing model options to be loaded dynamically when enabled.
    • Added support for customizing the cc-switch database location via configuration.
  • Bug Fixes
    • Improved fallback behavior so Claude model options continue to work normally when the integration is disabled, unavailable, or misconfigured.
  • Tests
    • Added coverage for cc-switch-enabled model mapping, custom database paths, and fallback scenarios.

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 Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an optional cc-switch proxy integration to ClaudeProviderModels. When CLAUDE_CC_SWITCH_MODELS_ENABLED is set, getSupportedModels() queries a better-sqlite3 SQLite database for the claude provider row, extracts model alias mappings, and returns tier-aliased model options; any error falls back to the existing static CLAUDE_FALLBACK_MODELS. Config docs are added to .env.example and a full test suite covers all paths.

Changes

cc-switch model alias integration

Layer / File(s) Summary
cc-switch DB resolver and getSupportedModels wiring
server/modules/providers/list/claude/claude-models.provider.ts, .env.example
Adds OS/path imports, environment-toggling helpers, DB path resolution, dynamic better-sqlite3 querying of the cc-switch claude provider row, transformation of real model names into CLI tier aliases, and a null-on-error fallback. getSupportedModels() now calls the resolver before reverting to CLAUDE_FALLBACK_MODELS. .env.example documents the two new optional env vars.
Test suite
server/modules/providers/tests/claude-models.test.ts
Adds createCcSwitchDbUnderHome, withHomedir, and withCcSwitchEnabled helpers; five test cases assert correct alias mapping when enabled, CLAUDE_CC_SWITCH_DB_PATH override, disabled-by-default fallback, empty-config fallback, and missing-DB fallback.

Possibly related PRs

  • siteboon/claudecodeui#806: Also modifies ClaudeProviderModels.getSupportedModels() in the same file, disabling runtime discovery to always return CLAUDE_FALLBACK_MODELS—the direct predecessor to the conditional logic this PR introduces.
  • siteboon/claudecodeui#834: Updates CLAUDE_FALLBACK_MODELS definitions in the same provider file that this PR's cc-switch integration falls back to when disabled or misconfigured.

Poem

🐇 Hoppity-hop through the SQLite rows,
A cc-switch alias wherever code goes!
When the DB is missing, I don't shed a tear—
I nibble the fallback list kept always near.
CLAUDE_CC_SWITCH_MODELS_ENABLED=true… what fun!
This bunny maps tiers 'til the query is done. 🌟

🚥 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 model options 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
server/modules/providers/tests/claude-models.test.ts (1)

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

Assert on fallback contents, not object identity.

getSupportedModels() only promises a ProviderModelsDefinition; returning the shared CLAUDE_FALLBACK_MODELS object is just the current implementation. These assert.equal(...) checks will fail on a behavior-preserving clone.

Proposed fix
-    assert.equal(result, CLAUDE_FALLBACK_MODELS);
+    assert.deepEqual(result, CLAUDE_FALLBACK_MODELS);

Also applies to: 147-147, 157-157

🤖 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/tests/claude-models.test.ts` at line 136, The tests
for `getSupportedModels()` are asserting object identity against
`CLAUDE_FALLBACK_MODELS`, which is an implementation detail and will fail if the
function returns an equivalent clone. Update the assertions in
`claude-models.test.ts` to compare the fallback model contents/shape instead of
using `assert.equal` on the shared constant, so the checks validate the returned
`ProviderModelsDefinition` behavior rather than the exact object instance.
🤖 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.

Inline comments:
In `@server/modules/providers/tests/claude-models.test.ts`:
- Around line 112-122: The test in ClaudeProviderModels is not restoring the
previous CLAUDE_CC_SWITCH_DB_PATH value and instead always deletes it, which can
leak or clobber parent process state. In the test around withCcSwitchEnabled()
and new ClaudeProviderModels().getSupportedModels(), snapshot the existing
environment value before setting customDbPath, then in the finally block restore
that original value (or delete it only if it was unset) just like
withCcSwitchEnabled() does.

---

Nitpick comments:
In `@server/modules/providers/tests/claude-models.test.ts`:
- Line 136: The tests for `getSupportedModels()` are asserting object identity
against `CLAUDE_FALLBACK_MODELS`, which is an implementation detail and will
fail if the function returns an equivalent clone. Update the assertions in
`claude-models.test.ts` to compare the fallback model contents/shape instead of
using `assert.equal` on the shared constant, so the checks validate the returned
`ProviderModelsDefinition` behavior rather than the exact object instance.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a2c964a3-c383-4159-a9b7-14a4333b11ae

📥 Commits

Reviewing files that changed from the base of the PR and between ed4ae31 and 58aa56a.

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

Comment thread 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