anomalyco / anomalyco/opencode
Plugins: `chat.params` hook cannot override the model (only sampling params) — model-switch plugins are forced to abort+resend, which breaks one-shot `opencode run` callers
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Plugins: chat.params hook cannot override the model (only sampling params) — model-switch plugins are forced to abort+resend, which breaks one-shot opencode run callers
Environment
- opencode: v1.18.31 (also observed on v1.18.30)
- Context: plugin ecosystem, specifically model-fallback plugins (
opencode-auto-fallbackv0.4.59) - OS: Linux (Debian 13)
Summary
The chat.params plugin hook allows overriding sampling params only — temperature, topP, reasoningEffort, maxTokens, thinking — but not providerID/modelID of the upcoming request. Verified in the plugin's dist code: the hook handler maps exactly those fields onto the output; a model change is impossible from inside the hook.
Consequence: any plugin that needs to switch the model for an in-flight task (rate-limit fallback, context-overflow large-model switch, A/B routing) must abort the session and re-send a new prompt with body.model. There is no abort-free path.
Why that hurts: opencode run callers
For long-lived clients (TUI, HTTP POST /session/:id/message against a serve instance) abort+resend works: the process survives the abort, the plugin's follow-up prompt lands, the task continues on the new model.
But opencode run is a one-shot CLI: when its prompt is aborted, it prints Error: Aborted and exits — taking the plugin's in-flight follow-up prompt with it. The task is silently lost. Real-world case: a daily cron research job (opencode run -s <long-running-session> "<task>") failed 4 days in a row with Error: Aborted because the session context was over the model's threshold and the fallback plugin aborted to switch to a large-context model. Nothing executed; nothing logged on the plugin side that the continuation was lost.
Feature request
Enable plugins to change the model of the upcoming request without aborting the session, e.g.:
- Extend the
chat.paramshook soproviderID/modelID(and small-model/large-model variants) can be overridden for the request being built, or - Add a dedicated hook (e.g.
chat.model) that runs before provider resolution and can return a model override.
This would allow abort-free model switching (fallback on rate limit, large-context switch on overflow) and fix the whole class of „scheduled task silently lost" failures. It also complements the native model-fallback discussions (#7602, stalled PR #26292): even with native fallback, plugin-level per-agent routing still needs a clean way to redirect the model.
Related
- #7602 (Native Model Fallback / Failover Support — open)
- #26292 (fallback PR, stalled)
Happy to test patches and provide detailed logs from the real-world failure case.
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the chat.params hook and the request path before provider resolution, focusing on how providerID/modelID are currently handled. Compare the proposed chat.params extension with a dedicated chat.model hook, and review related issues #7602 and #26292. Done means a plugin can switch the upcoming model without aborting the session, including for one-shot opencode run callers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100