Repository navigation
Description
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.
Activity
github-actions commentedon Apr 23, 2026
This issue might be a duplicate of existing issues. Please check:
chat.modelplugin hook with nearly identical proposed interface (pre-call model routing via plugins)Please review those issues, especially #18793 which overlaps very closely with this request. If you believe your request is meaningfully distinct, feel free to add a comment explaining the difference.
JGuck commentedon Jun 3, 2026
Heads up: I opened #30457 with a minimal implementation of the
chat.modelhook.This covers the per-call plugin-routing path proposed here.
The PR intentionally does not implement persistent session model switching,
client.session.setModel(), TUI command execution, or model picker/UI updates. Those would still be separate follow-ups if the goal is full runtime session-level switching.github-actions commentedon Aug 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.