Skip to content

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

Closed as not planned

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.

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Apr 23, 2026
  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 23, 2026
  3. github-actions commented on Apr 23, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    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.

  4. removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  5. JGuck commented on Jun 3, 2026

    @JGuck

    Heads up: I opened #30457 with a minimal implementation of the chat.model hook.

    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.

  6. github-actions commented on Aug 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions