Skip to content

[FEATURE]:Support runtime model switching via plugin API #24006

@zhangym1995

Description

@zhangym1995

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Description:

Problem
Currently, switching the active LLM model in OpenCode requires either:

Manually clicking through the TUI model selector
Editing the config file and starting a new session
There is no way to programmatically switch models at runtime via the plugin system or any scriptable interface.

What's Missing
Looking at the plugin API (@opencode-ai/plugin):

The chat.params hook provides model in the input (read-only), while the output only allows modifying temperature, topP, topK, maxOutputTokens. There's no way to change the model.
The config hook only receives input, with no output to modify the active configuration.
The client SDK object has no documented method like client.session.setModel() or similar.
The shell.env hook only affects child process environments, not OpenCode's own model selection.
This makes it impossible to implement model hot-switching as a plugin, which blocks several valuable use cases.

Proposed Enhancement
Add a mechanism for runtime model switching. Some possible approaches (any one would suffice):

chat.model hook — Allow plugins to modify the model selection before each chat turn:
"chat.model"?: (
input: { sessionID: string; agent: string },
output: { providerID: string; modelID: string },
) => Promise
client.session.setModel() API — Expose a method on the SDK client:
await client.session.setModel({ providerID: "mdc", modelID: "glm-5-server2" })
tui.command.execute enhancement — Allow plugins to programmatically execute the built-in model-switch command (e.g., model:switch), making it scriptable without TUI interaction.
Use Cases
Load balancing: Automatically route to a different server/model when one is overloaded or down (e.g., glm-5-server2 → glm-5-server3).
Cost optimization: Use cheaper models for simple tasks, powerful models for complex ones, switching dynamically within a session.
CI/CD integration: Scripts can select specific models without manual TUI interaction.
Multi-model workflows: Different agents or pipeline stages could use different models within the same session.
Current Workaround
The only workaround is to modify the config file and start a new session, which is disruptive and not suitable for automated workflows.

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions