Skip to content

feat(claude-code): add model selection for the claude-code engine#434

Open
r-sayar wants to merge 2 commits into
browser-use:mainfrom
r-sayar:feat/claude-code-model-selection
Open

feat(claude-code): add model selection for the claude-code engine#434
r-sayar wants to merge 2 commits into
browser-use:mainfrom
r-sayar:feat/claude-code-model-selection

Conversation

@r-sayar
Copy link
Copy Markdown

@r-sayar r-sayar commented May 16, 2026

Summary

The claude-code engine currently passes no --model flag to the claude CLI, meaning every session uses whatever the CLI defaults to. This PR lets users pick a specific Claude model from the Settings panel.

  • Settings → Anthropic card: a "Model" dropdown appears once you're connected (OAuth or API key). Selecting a model persists immediately.
  • Default option omits the --model flag entirely, preserving the CLI's current default (claude-sonnet-4-6).
  • Available options: Haiku 4.5, Sonnet 4.5, Sonnet 4.6, Opus 4.5, Opus 4.7.

Changes

File What changed
authStore.ts Added claudeCodeModel field to credentials blob + loadClaudeCodeModel / saveClaudeCodeModel
apiKeyIpc.ts Registered settings:claude-code:model:get and settings:claude-code:model:set IPC handlers
preload/shell.ts Exposed getModel / setModel on the claudeCode API bridge
globals.d.ts Added TypeScript types for the two new IPC methods
runEngine.ts Loads saved model for the claude-code engine path and populates SpawnContext.model
adapter.ts Passes --model <id> to the claude CLI when a model is set; omits it when null
ConnectionsPane.tsx Added <select> under the Anthropic card, visible when connected; persists on change

Test plan

  • With no model selected, sessions use the CLI default (claude-sonnet-4-6)
  • Selecting Haiku / Opus in Settings → Connections → Anthropic card takes effect on the next session
  • Model preference survives an app restart
  • Switching back to "Default" removes the --model flag

🤖 Generated with Claude Code


Summary by cubic

Adds model selection to the claude-code engine so you can choose a Claude model in Settings; the engine passes --model to the claude CLI when set and falls back to the CLI default otherwise. Also fixes yarn.lock to resolve install failures from stale git SHAs.

  • New Features

    • Adds a "Model" dropdown in Settings → Connections → Anthropic when connected; selection saves immediately and persists across restarts.
    • Engine loads the saved model and calls claude with --model <id>; "Default" omits the flag (CLI default is claude-sonnet-4-6).
    • Options include Haiku 4.5, Sonnet 4.5/4.6, and Opus 4.5/4.7.
  • Dependencies

    • Replaces stale commit pins in yarn.lock for @electron/node-gyp and libsignal with branch heads to allow clean yarn install.

Written for commit 1e1c2bf. Summary will update on new commits. Review in cubic

r-sayar and others added 2 commits May 16, 2026 17:00
libsignal and @electron/node-gyp were pinned to commit hashes that no
longer exist on any branch, causing `yarn install` to fail for anyone
without those exact SHAs in their local git cache.

Replaced the resolved SHA pins with branch-head references so the
lockfile resolves cleanly on a fresh clone.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Allows users to choose which Claude model the claude-code engine uses
instead of always relying on the CLI default (claude-sonnet-4-6).

Changes:
- authStore: add `claudeCodeModel` field to the credentials blob with
  `loadClaudeCodeModel` / `saveClaudeCodeModel` helpers
- apiKeyIpc: register `settings:claude-code:model:get/set` IPC handlers
- preload/shell: expose `getModel` / `setModel` on the claudeCode API
- globals.d.ts: add TypeScript types for the new IPC methods
- runEngine: load the saved model for the claude-code engine path and
  populate SpawnContext.model
- adapter: pass `--model <id>` to the claude CLI when a model is set
  (omitted when null so the CLI default is preserved)
- ConnectionsPane: add a model <select> under the Anthropic card,
  visible when connected; persists immediately on change

Available options: Haiku 4.5, Sonnet 4.5, Sonnet 4.6, Opus 4.5,
Opus 4.7, and a "Default" option that omits the flag entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 8 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="app/src/main/settings/apiKeyIpc.ts">

<violation number="1" location="app/src/main/settings/apiKeyIpc.ts:582">
P2: `handleClaudeCodeModelSet` accepts renderer-provided `model` without runtime validation (no `assertString` or allowlist check), unlike every other IPC handler in this file that validates user input before persisting. This risks invalid persisted state and downstream CLI invocation with malformed `--model` values.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Fix all with cubic | Re-trigger cubic

Comment on lines +582 to +586
async function handleClaudeCodeModelSet(
_e: Electron.IpcMainInvokeEvent,
model: string | null,
): Promise<void> {
mainLogger.info('apiKeyIpc.claudeCode.model.set', { model });
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot May 16, 2026

Choose a reason for hiding this comment

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

P2: handleClaudeCodeModelSet accepts renderer-provided model without runtime validation (no assertString or allowlist check), unlike every other IPC handler in this file that validates user input before persisting. This risks invalid persisted state and downstream CLI invocation with malformed --model values.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/src/main/settings/apiKeyIpc.ts, line 582:

<comment>`handleClaudeCodeModelSet` accepts renderer-provided `model` without runtime validation (no `assertString` or allowlist check), unlike every other IPC handler in this file that validates user input before persisting. This risks invalid persisted state and downstream CLI invocation with malformed `--model` values.</comment>

<file context>
@@ -570,6 +574,19 @@ async function handleClaudeCodeLogout(): Promise<{ opened: boolean; error?: stri
+  return { model };
+}
+
+async function handleClaudeCodeModelSet(
+  _e: Electron.IpcMainInvokeEvent,
+  model: string | null,
</file context>
Suggested change
async function handleClaudeCodeModelSet(
_e: Electron.IpcMainInvokeEvent,
model: string | null,
): Promise<void> {
mainLogger.info('apiKeyIpc.claudeCode.model.set', { model });
async function handleClaudeCodeModelSet(
_e: Electron.IpcMainInvokeEvent,
model: string | null,
): Promise<void> {
const validated = model === null ? null : assertString(model, 'model', 160);
mainLogger.info('apiKeyIpc.claudeCode.model.set', { model: validated });
await saveClaudeCodeModel(validated);
}
Fix with Cubic

@Cheggin
Copy link
Copy Markdown
Collaborator

Cheggin commented May 17, 2026

thanks! will take a look at this

didnt add this yet bc I didn't get requests for it but clearly I should haha

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.

2 participants