Skip to content

fix: /model command now switches active model#635

Open
CoderLuii wants to merge 1 commit intositeboon:mainfrom
CoderLuii:fix/model-command-switching
Open

fix: /model command now switches active model#635
CoderLuii wants to merge 1 commit intositeboon:mainfrom
CoderLuii:fix/model-command-switching

Conversation

@CoderLuii
Copy link
Copy Markdown

@CoderLuii CoderLuii commented Apr 10, 2026

what

/model <name> in the Chat tab shows a response message but never switches the active model.

why

three layers were broken:

  1. server/routes/commands.js didn't include the requested model name in the response
  2. the frontend case "model" handler only rendered a display message
  3. setClaudeModel never reached the composer hook that handles built-in commands

fix

  • server returns newModel when args are provided
  • the composer hook applies setClaudeModel(newModel) and persists claude-model
  • setClaudeModel is threaded into useChatComposerState
  • the provider picker shows the current custom model in the dropdown when it isn't in the built-in options list

behavior

  • /model <name> now switches the active model in Chat
  • the model persists across page reload
  • /model with no args still shows current model info without switching

Summary by CodeRabbit

  • New Features

    • Added /model command to switch between Claude models
    • Model selection is now persisted across sessions
  • Improvements

    • Model dropdown now displays all available models, including the currently selected one, ensuring accurate selection display

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

The changes implement model selection through a /model command. The server returns the requested model in the response, the client hook processes this response to update the Claude model state and persist it to local storage, and the UI properly wires the setter through the component tree.

Changes

Cohort / File(s) Summary
Server Model Command
server/routes/commands.js
Added newModel field to the /model command response payload, extracting the requested model from command arguments.
Client Hook Integration
src/components/chat/hooks/useChatComposerState.ts
Added setClaudeModel callback parameter; updated model command handler to call the setter and persist to local storage when data.newModel is present.
Component Prop Wiring
src/components/chat/view/ChatInterface.tsx
Passed setClaudeModel function to useChatComposerState hook alongside existing model props.
UI Model Display
src/components/chat/view/subcomponents/ProviderSelectionEmptyState.tsx
Ensured current model is always available in select options by appending it if missing from predefined provider options.

Sequence Diagram

sequenceDiagram
    actor User
    participant Server
    participant Hook as useChatComposerState
    participant Storage as Local Storage
    participant UI as ProviderSelectionEmptyState

    User->>Server: Send /model command with target model
    Server->>User: Return response with newModel field
    User->>Hook: Trigger model command handler
    Hook->>Hook: Extract newModel from response.data
    Hook->>Storage: Persist model under 'claude-model' key
    Hook->>UI: Update claudeModel state
    UI->>UI: Render model option with current value available
Loading

Possibly related PRs

Suggested reviewers

  • viper151

Poem

🐇 A model command hops through the air,
From server to client, with utmost care,
The hook persists what the CLI brings,
Local storage keeps the model's rings,
And select menus show all the things!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: /model command now switches active model' directly and clearly describes the main change: the /model command now switches the active model, which is the core issue being fixed across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/chat/hooks/useChatComposerState.ts`:
- Around line 174-177: The /model command handler in useChatComposerState always
calls setClaudeModel and writes 'claude-model' to storage even when the active
provider is cursor/codex/gemini; update useChatComposerState to accept
setCursorModel, setCodexModel, and setGeminiModel (in addition to
setClaudeModel), read the current provider value, and route updates: call the
corresponding setter
(setCursorModel/setCodexModel/setGeminiModel/setClaudeModel) and write the
matching key ('cursor-model'/'codex-model'/'gemini-model'/'claude-model') to
safeLocalStorage when data.newModel is present so the /model command updates the
correct provider's active model.
🪄 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: 15b1b26a-b7bf-4aca-bc66-ddd3ef52e817

📥 Commits

Reviewing files that changed from the base of the PR and between 388134c and a747cd4.

📒 Files selected for processing (4)
  • server/routes/commands.js
  • src/components/chat/hooks/useChatComposerState.ts
  • src/components/chat/view/ChatInterface.tsx
  • src/components/chat/view/subcomponents/ProviderSelectionEmptyState.tsx

Comment on lines +174 to +177
if (data.newModel) {
setClaudeModel(data.newModel);
safeLocalStorage.setItem('claude-model', data.newModel);
}
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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify how /model is handled and whether provider-specific setters are wired.
rg -n -C3 "case 'model'|newModel|setClaudeModel|setCursorModel|setCodexModel|setGeminiModel|claude-model|cursor-model|codex-model|gemini-model" \
  server/routes/commands.js \
  src/components/chat/hooks/useChatComposerState.ts \
  src/components/chat/view/ChatInterface.tsx

Repository: siteboon/claudecodeui

Length of output: 5536


🏁 Script executed:

#!/bin/bash
# Check if provider state is accessible and how other models are initialized/stored
rg -n "handleBuiltInCommand|setProvider|setCodexModel|setCursorModel|setGeminiModel" \
  src/components/chat/hooks/useChatComposerState.ts -A 5 -B 2 | head -100

Repository: siteboon/claudecodeui

Length of output: 886


🏁 Script executed:

#!/bin/bash
# Search for localStorage patterns to see if other providers use different keys
rg -n "localStorage|setItem|getItem" src/components/chat/hooks/useChatComposerState.ts

Repository: siteboon/claudecodeui

Length of output: 763


🏁 Script executed:

#!/bin/bash
# Check how the command gets dispatched and what context it has
rg -n "case 'model':" -A 10 -B 5 server/routes/commands.js

Repository: siteboon/claudecodeui

Length of output: 47


🏁 Script executed:

#!/bin/bash
# Find model command handling with broader search
rg -n "model" server/routes/commands.js | grep -E "(case|'model'|\bmodel\b)" | head -20

Repository: siteboon/claudecodeui

Length of output: 545


🏁 Script executed:

#!/bin/bash
# Look for how other models are initialized from storage
rg -n "cursorModel|codexModel|geminiModel" src/components/chat/hooks/useChatComposerState.ts -B 3 -A 3 | head -80

Repository: siteboon/claudecodeui

Length of output: 2421


🏁 Script executed:

#!/bin/bash
# Search for provider state handling in chat interface
rg -n "provider.*setClaudeModel|provider.*setCursorModel|if.*provider.*model" src/components/chat/

Repository: siteboon/claudecodeui

Length of output: 47


🏁 Script executed:

#!/bin/bash
# Find where models are initialized from localStorage
rg -n "useState.*Model|getItem.*model|CLAUDE_MODELS|CURSOR_MODELS|CODEX_MODELS|GEMINI_MODELS" \
  src/components/chat/hooks/useChatComposerState.ts -B 2 -A 2 | head -100

Repository: siteboon/claudecodeui

Length of output: 47


🏁 Script executed:

#!/bin/bash
# Check parent component to see how model state is created
rg -n "useChatComposerState|claudeModel|cursorModel" src/components/chat/view/ChatInterface.tsx \
  | grep -E "(useState|const.*Model|useChatComposerState)" | head -20

Repository: siteboon/claudecodeui

Length of output: 170


🏁 Script executed:

#!/bin/bash
# Read the hook file to find where models are initialized
head -150 src/components/chat/hooks/useChatComposerState.ts | tail -100

Repository: siteboon/claudecodeui

Length of output: 3234


🏁 Script executed:

#!/bin/bash
# Look for useState calls and model initialization
rg -n "useState|setClaudeModel|setCursorModel|setCodexModel|setGeminiModel" \
  src/components/chat/hooks/useChatComposerState.ts | head -30

Repository: siteboon/claudecodeui

Length of output: 851


🏁 Script executed:

#!/bin/bash
# Check ChatInterface.tsx to see where all model state is defined
rg -n "claudeModel|cursorModel|codexModel|geminiModel|useState" \
  src/components/chat/view/ChatInterface.tsx | head -40

Repository: siteboon/claudecodeui

Length of output: 384


🏁 Script executed:

#!/bin/bash
# Look for setCursor, setCodex, setGemini setters in ChatInterface
rg -n "setCursor|setCodex|setGemini|setClaudeModel" \
  src/components/chat/view/ChatInterface.tsx

Repository: siteboon/claudecodeui

Length of output: 361


🏁 Script executed:

#!/bin/bash
# Check what ChatComposer component does with the other model setters
rg -n "setCursorModel|setCodexModel|setGeminiModel" \
  src/components/chat/ -A 3 -B 3 | grep -E "\.tsx:|\.ts:" | head -40

Repository: siteboon/claudecodeui

Length of output: 3001


🏁 Script executed:

#!/bin/bash
# Check if there's documentation or comments about /model being Claude-only
rg -n "model.*command|/model|claude.*only" \
  server/routes/commands.js docs/ README.md 2>/dev/null | head -20

Repository: siteboon/claudecodeui

Length of output: 719


/model command handler should support all providers, not just Claude.

The handler at lines 174-177 always calls setClaudeModel() and updates claude-model storage, regardless of the active provider. When a non-Claude provider (cursor, codex, or gemini) is active, running /model fails to update that provider's active model.

To fix: Pass setCursorModel, setCodexModel, and setGeminiModel into useChatComposerState and route the update based on the current provider state:

case 'model':
  if (data.newModel) {
    if (provider === 'cursor') {
      setCursorModel(data.newModel);
      safeLocalStorage.setItem('cursor-model', data.newModel);
    } else if (provider === 'codex') {
      setCodexModel(data.newModel);
      safeLocalStorage.setItem('codex-model', data.newModel);
    } else if (provider === 'gemini') {
      setGeminiModel(data.newModel);
      safeLocalStorage.setItem('gemini-model', data.newModel);
    } else {
      setClaudeModel(data.newModel);
      safeLocalStorage.setItem('claude-model', data.newModel);
    }
  }

The README documents support for "Claude, GPT, and Gemini model families," confirming /model should work across all providers.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/chat/hooks/useChatComposerState.ts` around lines 174 - 177,
The /model command handler in useChatComposerState always calls setClaudeModel
and writes 'claude-model' to storage even when the active provider is
cursor/codex/gemini; update useChatComposerState to accept setCursorModel,
setCodexModel, and setGeminiModel (in addition to setClaudeModel), read the
current provider value, and route updates: call the corresponding setter
(setCursorModel/setCodexModel/setGeminiModel/setClaudeModel) and write the
matching key ('cursor-model'/'codex-model'/'gemini-model'/'claude-model') to
safeLocalStorage when data.newModel is present so the /model command updates the
correct provider's active model.

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