Skip to content

[FEATURE]: add chat.model plugin hook for pre-call model routing #18793

@v1truv1us

Description

@v1truv1us
  • I have verified this feature I'm about to request hasn't been suggested before.

Add a new plugin hook named chat.model that runs before an LLM call and can replace the active { providerID, modelID }.

Today plugins can modify params, headers, prompts, and tool behavior, but they cannot choose a different model at call time. That makes it hard to build plugin-driven routing patterns that feel like a good fit for OpenCode: cost-based switching, fallback to another model, per-tool routing, and review workflows that use multiple configured models without manually changing the session model.

I think this hook should stay minimal. It only needs the current call context: sessionID, agent, current model, provider context, current message, and step. It should return an optional replacement model and does not need full conversation history.

This seems related to fallback discussions like #7602, but broader: the goal is to expose model routing to plugins, not only add native fallback behavior. Since this changes core plugin infrastructure, I think it should start as a design discussion before implementation.

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions