Repository navigation
Description
Feature request: pre-dispatch model override hook (or model field in chat.message output)
Problem
Plugins currently have no way to influence which model is used for the user's in-flight turn. This blocks a class of plugins that want to route a single prompt to different models based on its content - for example:
- An "AutoModel" plugin that classifies prompt complexity with a small/cheap model and routes the actual answer to mini/medium/high/huge model tiers.
- A "thinking budget" plugin that picks a reasoning-heavy model only when the prompt looks like it needs one.
- A "safety / policy" plugin that downgrades to a less powerful model for prompts matching a pattern.
Current state (verified against opencode v1.15.7, plugin SDK v? same release)
The hook lifecycle for a user turn is:
chat.messageexperimental.chat.messages.transformexperimental.chat.system.transformchat.paramschat.headers- LLM call
tool.execute.*,experimental.text.complete- Event stream (
message.updated,session.idle, ...)
In every one of these hooks, model: Model (or equivalent) is input only. None of the output shapes accept a model field. The dispatcher resolves the model before the hook chain runs, and downstream hooks cannot change it.
I verified this by mutating input.model from inside chat.message and chat.params:
- Mutating
chat.messageinput.model.modelIDandinput.model.providerID: no effect on the assistant message that follows. Thechat.paramshook fired ~1s later still saw the original model. - Mutating
chat.paramsinput.model: the mutation persists in the params object (a subsequentparams.entrylog line shows the new value), but the dispatcher reads the model from elsewhere and the assistant still ran on the original model.
I also tested client.session.prompt({ body: { model: ... } }):
- The HTTP request is accepted and the new
chat.messagehook for the queued user message showsinput.model= the new model. - But the
opencode runCLI tears down the process when the original turn idles, before the queued follow-up is dispatched, so I could not confirm whether the queued turn actually runs on the requested model. Even if it does, this is "fire a separate plugin-initiated turn", not "influence the user's current turn".
There is also no Session.model field on the SDK Session type, so a plugin cannot pre-set a session-level default model between turns either. The TUI's model picker lives in TUI state, not server state.
Proposed solutions (any one would unblock the use case)
Option A - allow model in chat.message output
"chat.message"?: (input, output: {
message: UserMessage;
parts: Part[];
model?: { providerID: string; modelID: string }; // <-- new, optional override
}) => Promise<void>;If multiple plugins set model, last-write-wins (or define a precedence).
Option B - a new pre-dispatch hook
"chat.model.select"?: (input: {
sessionID: string;
agent: string;
message: UserMessage;
defaultModel: { providerID: string; modelID: string };
}, output: {
model: { providerID: string; modelID: string };
}) => Promise<void>;This fires after chat.message (so plugins can inspect the full message) but before experimental.chat.messages.transform / chat.params. Whatever output.model is set to becomes the model used for the rest of the lifecycle.
Option C - allow chat.params to override the model
Add model to the chat.params output shape. Same effect, less invasive to the hook surface, but couples a model-routing concern to the params hook.
I would mildly prefer Option B for clarity (the new hook's single purpose is model selection), but Option A is the minimum-surface-area change.
Why not work around this in user-land
The only workaround today is "let the user's turn run on the default model, then fire a second plugin-initiated turn with client.session.prompt({ body: { model } })". That doubles token cost on every mis-routed turn, produces two assistant replies in the transcript, and confuses the UX. It's not a workaround - it's a different feature.
Repro / reference
Source for the spike showing each mutation attempt and its (lack of) effect is available on request. I'm happy to file a PR for Option A or B if a maintainer signals which shape is preferred.
Activity
github-actions commentedon May 22, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
[FEATURE]:and include the verification checkbox confirming the feature hasn't been suggested before.Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
chat.modelplugin hook for overriding model selection (for blind LLM benchmarking, but same hook shape)If you believe this was flagged incorrectly, please let a maintainer know.
github-actions commentedon May 22, 2026
This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.
Feel free to open a new issue that follows our issue templates.