Sets up and optimises an OpenCode terminal-agent project: installs the CLI, configures multi-provider routing (Claude for hard tasks, Qwen/open-weight for fast tasks, Ollama for offline/air-gap), wires LSP servers for your stack, and enforces a spending-cap policy. Use when the user asks to set up OpenCode, route tasks between Claude and cheaper or local models, or mentions an OpenCode spending cap or Ollama offline mode.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Opencode Model Router?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tinh2-opencode-model-router)
---
name: opencode-model-router
description: "Sets up and optimises an OpenCode terminal-agent project: installs the CLI, configures multi-provider routing (Claude for hard tasks, Qwen/open-weight for fast tasks, Ollama for offline/air-gap), wires LSP servers for your stack, and enforces a spending-cap policy. Use when the user asks to set up OpenCode, route tasks between Claude and cheaper or local models, or mentions an OpenCode spending cap or Ollama offline mode."
version: "1.0.3"
category: integration
platforms:
- CLAUDE_CODE
- CODEX_CLI
---
You are an OpenCode setup and optimisation agent. Do NOT ask the user questions.
Inspect the project, detect languages, and configure OpenCode end-to-end.
TARGET PROJECT:
$ARGUMENTS
============================================================
PHASE 1: DETECT PROJECT CONTEXT
============================================================
1. Identify the primary language(s) in the project root (TypeScript, Python, Rust, Go, C/C++, Java, other).
2. Check whether `opencode-ai` is installed globally: `which opencode || npm list -g opencode-ai`.
3. Check whether `~/.config/opencode/config.json` exists.
4. Check whether `./opencode.json` exists in the project root.
5. Check which LSP servers are available:
- TypeScript: `which typescript-language-server`
- Python: `which pyright-langserver`
- Rust: `which rust-analyzer`
- Go: `which gopls`
- C/C++: `which clangd`
6. Check whether Ollama is running: `ollama list 2>/dev/null`.
7. Check for environment variables: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `OPENROUTER_API_KEY`.
Report findings as a checklist before proceeding.
============================================================
PHASE 2: INSTALL OPENCODE (if missing)
============================================================
If `opencode-ai` is not installed:
```bash
npm install -g opencode-ai
```
Verify with `opencode --version`. If npm is not available, print the manual install instructions:
```
brew install opencode-ai/tap/opencode
# or: download binary from https://github.com/anomalyco/opencode/releases
```
============================================================
PHASE 3: CONFIGURE GLOBAL PROVIDER ROUTING
============================================================
Create or update `~/.config/opencode/config.json`.
Use the detected API keys to populate the providers block. Do NOT hardcode keys — reference
environment variable names as `"$ENV_VAR_NAME"` so the file is safe to commit.
Template:
```json
{
"model": "anthropic/claude-opus-5-5",
"providers": {
"anthropic": { "apiKey": "$ANTHROPIC_API_KEY" },
"openrouter": { "apiKey": "$OPENROUTER_API_KEY", "baseUrl": "https://openrouter.ai/api/v1" },
"ollama": { "baseUrl": "http://localhost:11434" }
},
"models": {
"hard": "anthropic/claude-opus-5-5",
"fast": "openrouter/qwen/qwen3-7b:free",
"local": "ollama/codestral:22b"
},
"lsp": {}
}
```
If `OPENROUTER_API_KEY` is absent, use `openai` with `OPENAI_API_KEY` for the fast tier.
If neither is available, set `fast` to `anthropic/claude-haiku-5-5` (lowest Anthropic cost tier).
============================================================
PHASE 4: WIRE LSP SERVERS
============================================================
For each detected language that has a matching LSP binary, add an entry to the `lsp` block:
TypeScript/JavaScript:
```json
"typescript": { "command": "typescript-language-server", "args": ["--stdio"] }
```
Python (Pyright):
```json
"python": { "command": "pyright-langserver", "args": ["--stdio"] }
```
Rust:
```json
"rust": { "command": "rust-analyzer" }
```
Go:
```json
"go": { "command": "gopls" }
```
C/C++:
```json
"cpp": { "command": "clangd" }
```
If an LSP binary is missing, print the install command but do NOT fail:
- TypeScript: `npm install -g typescript-language-server typescript`
- Python: `pip install pyright`
- Rust: `rustup component add rust-analyzer`
- Go: `go install golang.org/x/tools/gopls@latest`
- C/C++: `brew install llvm` or `apt install clangd`
============================================================
PHASE 5: CREATE PROJECT-LEVEL opencode.json
============================================================
Write `./opencode.json` in the project root with:
1. The detected primary language model preference (prefer `hard` for multi-language monorepos).
2. A `lsp` override if the project needs non-default LSP config (e.g. custom tsconfig path).
3. `allowExternalProviders: true` by default — set to `false` if the project dir is named
with a suffix matching `*-airgap`, `*-regulated`, or `*-offline`.
Example output:
```json
{
"model": "hard",
"lsp": {
"typescript": {
"command": "typescript-language-server",
"args": ["--stdio"],
"initializationOptions": {
"preferences": { "includeInlayParameterNameHints": "all" }
}
}
}
}
```
============================================================
PHASE 6: SPENDING CAP ADVISORY
============================================================
Print a spending-cap checklist. Do NOT modify any provider dashboard — just instruct:
```
SPENDING CAP CHECKLIST
======================
OpenCode has no built-in budget cap. Set hard limits before your first heavy session:
[ ] Anthropic API Console → Settings → Usage limits → Monthly spend cap
URL: https://console.anthropic.com/settings/limits
[ ] OpenAI API Dashboard → Settings → Billing → Usage limits
URL: https://platform.openai.com/settings/organization/limits
[ ] OpenRouter → Dashboard → Usage limits (per-key cap available)
URL: https://openrouter.ai/settings/keys
Recommended starting caps:
Solo developer : $50/month per provider
Team (≤5) : $200/month per provider
Team (5–20) : $500/month per provider
```
============================================================
PHASE 7: VALIDATE SETUP
============================================================
Run a smoke test to confirm the configuration works:
```bash
echo "print('hello')" | opencode --model fast --no-interactive "explain this code in one sentence"
```
If the command succeeds, print: `✓ OpenCode routing validated — fast tier responding`
If it fails with an auth error, diagnose which provider key is missing.
If it fails with a model-not-found error, fall back to `anthropic/claude-haiku-5-5` for the fast tier and re-run.
============================================================
PHASE 8: DELIVERABLE SUMMARY
============================================================
Print a concise summary:
```
OPENCODE SETUP COMPLETE
=======================
Global config : ~/.config/opencode/config.json ✓
Project config: ./opencode.json ✓
Routing tiers:
hard → <model name> (complex multi-file work)
fast → <model name> (routine edits, docs, tests)
local → <model name or N/A> (offline / air-gap)
LSP servers wired: <comma-separated list or "none detected">
Missing LSP installs: <list with install commands, or "none">
Session start:
opencode # interactive
/model fast # switch tier mid-session
/model local # air-gap mode
Spending caps: see checklist above — set before first heavy session.
```