An OpenCode plugin that classifies a development task with a local Ollama model and recommends the right cost tier and agent to use.
It is designed to keep simple work on free local models and reserve paid models for tasks that actually need them.
- A
route_tasktool for task-to-model routing recommendations - Cost-tier recommendations:
free,cheap,moderate,expensive - Agent guidance based on the recommended tier
- Lightweight learning from your past routing decisions
ollama serve
ollama pull qwen3:8bIf your global OpenCode config uses enabled_providers, include ollama there too:
Add the plugin package to your OpenCode config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-task-router"]
}Then restart OpenCode. OpenCode installs npm plugins automatically with Bun at startup.
Ask OpenCode to call the tool directly:
Use the route_task tool to analyze this task: refactor the authentication module
Typical output:
## Task Routing Recommendation
| Factor | Assessment |
|--------|-----------|
| Complexity | **moderate** |
| Context needs | **medium** |
| Cost tier | **moderate** |
**Reasoning:** Multi-file refactoring usually needs broader codebase context.
The npm package guarantees the route_task tool.
If you also want the /route shortcut, a local free-tier agent, and an example Ollama provider config, copy the example files from examples/opencode/ into your project:
examples/opencode/
├── opencode.json
└── .opencode/
├── agents/
│ └── local-worker.md
└── commands/
└── route.md
Suggested mapping:
examples/opencode/.opencode/commands/route.md->.opencode/commands/route.mdexamples/opencode/.opencode/agents/local-worker.md->.opencode/agents/local-worker.mdexamples/opencode/opencode.json-> merge into your projectopencode.json
route_tasksends your task description to a local Ollama classifier- The classifier returns task complexity, context estimate, and cost tier
- The plugin recommends an agent and model tier
- When the session goes idle, the plugin logs what was recommended to
.opencode/router-history.jsonl - Recent history is reused as calibration on future routing decisions
The plugin currently defaults to:
const OLLAMA_BASE_URL = "http://localhost:11434"
const CLASSIFIER_MODEL = "qwen3:8b"
const MAX_HISTORY_EXAMPLES = 20These live in src/index.ts.
Install dependencies and build the package:
npm install
npm run build
npm testFor local OpenCode development in this repo, the project plugin entrypoint at .opencode/plugins/task-router.ts re-exports the package source from src/index.ts.
The smoke test automates what is practical without depending on a real OpenCode session:
- builds the package
- creates a tarball
- installs the tarball into a temporary directory
- imports the installed package
- executes
route_taskwith a mocked Ollama response - verifies the history file is written
The unit tests cover the internal routing logic directly:
- cost-tier inference from provider/model ids
- classifier response parsing and normalization
- prompt construction with calibration history
- history file read/write helpers
- plugin recommendation, retry, and idle logging behavior
This repo includes GitHub Actions for:
- CI on pushes to
mainand pull requests - npm publishing from version tags like
v0.1.0 - manual publish dry runs through
workflow_dispatch
Publishing can be fully automated through GitHub Actions using npm trusted publishing with GitHub OIDC.
See RELEASE.md for the release checklist and tag-based publishing flow.
Make sure Ollama is running and the model is installed:
ollama serve
ollama pull qwen3:8bThat usually means the classifier returned invalid output. The plugin retries once, then falls back to a safe default.
The history file is only written after a routing recommendation and when the session goes idle.
MIT
{ "enabled_providers": ["github-copilot", "ollama"] }