opencode
opencode copied to clipboard
feat(plugin): add chat.variant hook for programmatic thinking/variant control
Summary
Add chat.variant plugin hook that allows plugins to programmatically control the thinking/variant level (high, max) before LLM requests are made.
Changes
- Add
chat.varianthook type definition in@opencode/plugin - Trigger hook in
llm.tsbefore variant options are applied - Plugin receives current variant state and can override via
output.variantoroutput.options
Use Case
Plugins can now programmatically control:
- Anthropic's thinking budget (high/max)
- OpenAI's reasoning effort
- Other provider-specific variant options
This enables use cases like:
- Always use high thinking for specific models
- Dynamic thinking level based on conversation context
- Conditional variant selection based on session/agent type
Example Usage
const myPlugin: Plugin = async () => ({
"chat.variant": async (input, output) => {
// Always use high thinking for Claude
if (input.model.id.includes("claude")) {
output.variant = "high"
}
}
})
Generated with assistance of OhMyOpenCode