Skip to content

feat: skip setModel() when model is provided via query Options#447

Open
hatawong wants to merge 1 commit intoagentclientprotocol:mainfrom
hatawong:feat/skip-setmodel-when-options-model
Open

feat: skip setModel() when model is provided via query Options#447
hatawong wants to merge 1 commit intoagentclientprotocol:mainfrom
hatawong:feat/skip-setmodel-when-options-model

Conversation

@hatawong
Copy link
Copy Markdown

Summary

When a client passes model through _meta.claudeCode.options in session/new, the model is already set at CLI startup time via the query() Options parameter. The subsequent setModel() call in getAvailableModels() is unnecessary and causes two issues:

  1. /model command leaks into the ACP event streamsetModel() triggers a /model CLI command whose output appears as user_message_chunk events, polluting the client's UI
  2. Extra round-trip — adds a synchronous setModel() call to every session creation

Changes

  • Add optionsModel parameter to getAvailableModels()
  • When optionsModel is present, resolve it against available models for currentModelId reporting but skip the setModel() call
  • Pass options.model (which comes from _meta.claudeCode.options spread) at the call site

Effort support

The same _meta.claudeCode.options path also supports effort — it gets spread into SDK Options and takes effect at CLI startup via query({ options: { effort } }). No adapter changes needed for effort support; this PR unblocks it by establishing the pattern of passing config through _meta instead of post-hoc commands.

This addresses #441 — effort can now be passed through _meta.claudeCode.options.effort without waiting for a runtime setEffort() API.

Backward compatibility

Clients that don't pass _meta.claudeCode.options.model get the existing behavior — setModel() is called as before. Only clients that explicitly provide a model via _meta benefit from the optimization.

Test plan

  • Existing tests pass
  • Client sends session/new with _meta: { claudeCode: { options: { model: "claude-opus-4-6" } } } → no /model command in event stream
  • Client sends session/new without _meta → existing setModel() behavior unchanged
  • Client sends _meta.claudeCode.options.effort → effort takes effect at CLI startup

🤖 Generated with Claude Code

When a client passes `model` through `_meta.claudeCode.options` in
`session/new`, the model is already set at CLI startup time via the
`query()` Options parameter. Calling `setModel()` afterwards triggers
an unnecessary `/model` command that:

1. Leaks into the ACP event stream as `user_message_chunk`
2. Adds an extra round-trip to every session creation
3. May override the client's intended model with the default

This change adds an `optionsModel` parameter to `getAvailableModels()`.
When present, it resolves the model for `currentModelId` reporting but
skips the `setModel()` call, eliminating the `/model` command leak.

The same `_meta.claudeCode.options` path also supports `effort`, which
is spread into SDK Options and takes effect at CLI startup without any
post-hoc command — no adapter changes needed for effort support.

Backward compatible: clients that don't pass `_meta` get the existing
behavior (setModel is called as before).

Closes zed-industries#441
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 22, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @hatawong on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@hatawong
Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 22, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @hatawong on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 22, 2026

The cla-bot has been summoned, and re-checked this pull request!

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