Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

opencode-ollama-small-model-plugin

Forces small_model to track the active provider's main model — but only for local Ollama.

opencode's top-level small_model setting is a global string and cannot be scoped per-provider through config. This plugin hooks experimental.provider.small_model (the same hook GitHub Copilot uses internally) to inject the correct model when the active provider is ollama. For every other provider, the plugin is a no-op and opencode's normal small-model selection (cfg.small_model → auto-pick → fall back to main) takes over.

Why

Title generation and other auxiliary prompts routed to the configured small_model should run locally on Ollama when Ollama is the active provider — not on a remote model that costs tokens per session. By forcing small_model = main for the Ollama provider, every auxiliary prompt goes through Ollama end-to-end.

Install

Drop the plugin file into your opencode config directory:

# Unix / macOS
cp ollama-small-model.ts ~/.config/opencode/plugins/

# Windows (PowerShell)
Copy-Item ollama-small-model.ts "$env:USERPROFILE\.config\opencode\plugins\"

opencode loads ~/.config/opencode/plugins/*.ts automatically — no rebuild, no restart of any service. The plugin takes effect on the next session.

How it works

"experimental.provider.small_model": async (incoming, output) => {
  if (incoming.provider.id !== "ollama") return
  const models = incoming.provider.models as Record<string, unknown> | undefined
  if (!models) return

  const candidate =
    models["qwen3.5:9b"] ??
    Object.values(models).find((m) => {
      const id = (m as any)?.api?.id ?? (m as any)?.id
      return typeof id === "string"
    })

  if (candidate) output.model = candidate
}
  1. The hook fires whenever opencode resolves small_model for a provider.
  2. If the provider is not ollama, return immediately — opencode's default behaviour applies.
  3. For ollama, look up qwen3.5:9b in the already-registered provider.models map. If absent (defensive — the provider only ships qwen3.5:9b today, but the fallback keeps title generation working if the model id changes), fall back to whichever model the provider exposes.

The result is written to output.model. Title generation then runs through Ollama.

Requirements

  • opencode with the Ollama provider configured.
  • @opencode-ai/plugin type definitions (declared as a dev dependency in package.json; opencode provides these at runtime — no install step required).

License

MIT

About

Forces small_model to track the active Ollama model id so auxiliary prompts (title generation, etc.) stay on Ollama end-to-end. No-op for non-Ollama providers.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages