You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have verified this feature I'm about to request hasn't been suggested before.
Feature: Dynamic Model Routing via Plugin Hook - Update Active Model State
What it is
A plugin hook that allows plugins to dynamically change the active model for the entire OpenCode session. When a plugin overrides the model, it should update OpenCode's active model state, so that all subsequent agents and tasks using inherited model (no explicit model pin) will use the new model.
Partially implemented. The existing chat.message hook allows plugins to mutate output.message.model, but this only affects the current turn's chain (user → assistant → subagent). It does NOT update OpenCode's active model state or UI, and future turns revert to the old model.
Test coverage exists at packages/opencode/test/session/chat-message-model-routing.test.ts.
Enforce policy-based model selection (e.g., cost limits, compliance)
Audit trail of model selection decisions
Context-aware routing
Analyze file types, project size, or task complexity
Select appropriate model tier dynamically
Implementation Notes
What exists:
chat.message hook allows plugins to mutate output.message.model
Model inheritance chain works (user → assistant → subagent)
Test coverage at packages/opencode/test/session/chat-message-model-routing.test.ts
What needs to be added:
Update OpenCode's active model state when plugin changes model
Update the UI/model picker to reflect the new active model
Ensure future turns use the new active model by default
Key change needed:
In prompt.ts where chat.message is triggered, when output.message.model is mutated, also update the session's active model. This should propagate to the UI so the model picker reflects the change.
Files involved:
packages/plugin/src/index.ts - Hook type definition
packages/opencode/src/session/prompt.ts - Update active model when hook mutates model
packages/opencode/src/tool/task.ts - Already respects parent assistant model (lines 108-111)
UI components - Display active model from session state
Feature: Dynamic Model Routing via Plugin Hook - Update Active Model State
What it is
A plugin hook that allows plugins to dynamically change the active model for the entire OpenCode session. When a plugin overrides the model, it should update OpenCode's active model state, so that all subsequent agents and tasks using inherited model (no explicit model pin) will use the new model.
Current behavior
Proposed behavior
chat.messagehookKey distinction from current
chat.messagebehavioroutput.message.model, but it only affects the user message and subsequent assistant/subagent for that turnBenefits
Current Status
Partially implemented. The existing
chat.messagehook allows plugins to mutateoutput.message.model, but this only affects the current turn's chain (user → assistant → subagent). It does NOT update OpenCode's active model state or UI, and future turns revert to the old model.Test coverage exists at
packages/opencode/test/session/chat-message-model-routing.test.ts.This is insufficient because:
This request is to:
Problem
Describe the problem or limitation that this feature would solve.
Related issues:
Proposed Solution
Extend the
chat.messagehook (or add a dedicatedchat.modelhook) to update OpenCode's active model state when a plugin changes the model.Hook semantics:
output.modelis set, OpenCode updates its active model stateResolution order:
chat.model/chat.messagemodel mutation (updates active model)agent.modelpin in agent configurationEffect on active model:
modelinherit the active modelUse Cases
Dynamic model routing based on prompt content
Model fallback/failover
A/B testing and benchmarking
Enterprise model governance
Context-aware routing
Implementation Notes
What exists:
chat.messagehook allows plugins to mutateoutput.message.modelpackages/opencode/test/session/chat-message-model-routing.test.tsWhat needs to be added:
Key change needed:
In
prompt.tswherechat.messageis triggered, whenoutput.message.modelis mutated, also update the session's active model. This should propagate to the UI so the model picker reflects the change.Files involved:
packages/plugin/src/index.ts- Hook type definitionpackages/opencode/src/session/prompt.ts- Update active model when hook mutates modelpackages/opencode/src/tool/task.ts- Already respects parent assistant model (lines 108-111)Complementary Approaches
Questions for Discussion
chat.modelhook or extendchat.message?