/route — Token-Saving Model Router
Route each task to the cheapest model that can actually do it, instead of burning frontier tokens on work a small/local/subscription model handles fine. Two mechanisms:
- Delegate (works live, no restart): keep Claude as the brain, shell out a sub-task to a cheaper CLI or local model, bring the result back.
- Base-switch (whole session, needs restart): repoint Claude Code's base model to a cheaper provider for an entire session — same mechanism as
/free-mode.
When to use
/route or "route this", "do this on the cheapest model", "run it locally", "save tokens / save $", "which model for X?"
- Before a batch / mechanical job (bulk refactors, find-replace-at-scale, boilerplate, test generation)
- Before a huge-context read (summarize a giant file / repo) that doesn't need deep reasoning
- When the work is private and shouldn't leave the machine
Don't route a single genuinely-hard reasoning task — just run it on the frontier model. Routing has overhead; only pay it when the task is cheap-able.
Step 1 — Detect what's available
Run this first and read the result (caches a profile to ~/.claude/skills/route/providers.json):
ROUTE_DIR=~/.claude/skills/route
echo "=== Agent CLIs ==="
for c in ollama codex gemini grok hermes claude; do
p=$(command -v "$c" 2>/dev/null) && echo " $c: $p" || echo " $c: MISSING"
done
echo "=== Local Ollama models ==="
ollama list 2>/dev/null | tail -n +2 | awk 'NF{print " "$1}' || echo " (ollama not running)"
[ -z "$(ollama list 2>/dev/null | tail -n +2)" ] && echo " ⚠ NO MODELS PULLED — run: ollama pull qwen2.5-coder:7b"
echo "=== Provider keys ==="
for k in OPENAI_API_KEY OPENROUTER_API_KEY XAI_API_KEY GEMINI_API_KEY ANTHROPIC_API_KEY; do
[ -n "$(printenv $k)" ] && echo " $k: set" || echo " $k: —"
done
[ -f ~/.config/jack-keys.env ] && echo " (also source ~/.config/jack-keys.env for stored keys)"
Step 2 — First run: confirm the stack
If providers.json is missing (or the user says "re-detect" / "I added a provider"), ask which of these they have and want to use, then save the answers:
- ChatGPT / OpenAI — Codex CLI (
codex) or OPENAI_API_KEY
- Google Gemini —
gemini CLI or GEMINI_API_KEY
- Grok / xAI —
XAI_API_KEY
- OpenRouter —
OPENROUTER_API_KEY (gives free + cheap models; see /free-mode)
- Hermes (Nous) —
hermes CLI
- Local (Ollama) — and which models are pulled
Persist to ~/.claude/skills/route/providers.json so later runs skip the questions.
The routing table
| Task class |
Route to |
Why |
| Private / sensitive data |
Local Ollama only |
Never leaves the machine |
| Bulk / mechanical / boilerplate |
Local Ollama → else cheapest API |
Volume work, low reasoning |
| Huge-context read / summarize |
Gemini CLI |
Big context window, cheap per token |
| Agentic code grunt (refactor, scaffold) |
Codex CLI (in a git repo) |
Purpose-built, runs on your ChatGPT sub |
| Multi-tool / autonomous run |
Hermes |
Native tool-calling + routing |
| Cheap overflow when local is busy |
OpenRouter free/cheap model |
$0–pennies |
| Hard reasoning / architecture / final synthesis |
Stay on Claude (or frontier) |
Worth the tokens |
Step 3 — Route the task (delegation, works live)
Pick the target, then shell out via Bash and bring the output back for Claude to review/assemble:
# Local / private / bulk (free, offline)
ollama run qwen2.5-coder:7b "<prompt>"
# Huge-context read or summary (cheap, big window)
gemini -p "<prompt>" # or: cat bigfile | gemini -p "summarize"
# Agentic code grunt work (must be inside a git repo)
codex exec --full-auto "<prompt>"
# Autonomous / multi-tool run
hermes -z "<prompt>"
Then Claude reviews/finishes the cheap model's output. The frontier model stays the orchestrator; it just stops doing the cheap parts itself.
Whole-session cheap mode (base-switch, needs restart)
When the entire session is routine work, switch the base model for the whole session instead of delegating task-by-task — identical mechanism to /free-mode: set ANTHROPIC_BASE_URL + ANTHROPIC_MODEL in ~/.claude/settings.json to a cheaper provider, then restart Claude Code. Use /free-mode on for the OpenRouter/Qwen path. Always confirm with the user before a base-switch — it forces a restart.
Cost ladder (try cheapest first, escalate only on failure)
- Local Ollama — $0, private, offline
- A subscription you already pay for (ChatGPT via Codex, Gemini) — sunk cost, no marginal tokens
- OpenRouter free / cheap models
- Frontier (Claude / GPT / Grok premium) — reserve for the hard ~20%
Principles
- Default to the cheapest plausible model; escalate only when it fails or the output is weak.
- Private/sensitive → local only. Never route confidential code or client data off-machine.
- The frontier model is the brain; cheap models are the hands.
- One model is never strictly best — route by the specific task in front of you.
- Confirm before any base-switch (restart required).
Setup gaps (the detector flags these)
- No Ollama models →
ollama pull qwen2.5-coder:7b (great small coder; use :32b if you have ~24GB+ RAM). This is the #1 thing to fix — without it there's no local tier.
- No OpenRouter key → run
/free-mode to get the free Qwen3-Coder path.
- No Grok → add
XAI_API_KEY (or wire Grok via OpenRouter).
1---2name: route3description: Token-saving model router. Detects which AI providers and CLIs you have (ChatGPT/Codex, Gemini, Grok, OpenRouter, Hermes, local Ollama), then routes each task to the cheapest capable one — delegating grunt work to a cheaper CLI/local model, or switching the whole session's base model. Trigger on /route, "route this", "run this locally", "use the cheapest model", "save tokens", "which model should I use for X", or before any big batch/mechanical/long-context job that doesn't need frontier reasoning.4---56# /route — Token-Saving Model Router78Route each task to the **cheapest model that can actually do it**, instead of burning frontier tokens on work a small/local/subscription model handles fine. Two mechanisms:910- **Delegate** (works live, no restart): keep Claude as the brain, shell out a sub-task to a cheaper CLI or local model, bring the result back.11- **Base-switch** (whole session, needs restart): repoint Claude Code's base model to a cheaper provider for an entire session — same mechanism as `/free-mode`.1213## When to use1415- `/route` or "route this", "do this on the cheapest model", "run it locally", "save tokens / save $", "which model for X?"16- Before a **batch / mechanical** job (bulk refactors, find-replace-at-scale, boilerplate, test generation)17- Before a **huge-context read** (summarize a giant file / repo) that doesn't need deep reasoning18- When the work is **private** and shouldn't leave the machine1920**Don't route** a single genuinely-hard reasoning task — just run it on the frontier model. Routing has overhead; only pay it when the task is cheap-able.2122## Step 1 — Detect what's available2324Run this first and read the result (caches a profile to `~/.claude/skills/route/providers.json`):2526```bash27ROUTE_DIR=~/.claude/skills/route28echo "=== Agent CLIs ==="29for c in ollama codex gemini grok hermes claude; do30 p=$(command -v "$c" 2>/dev/null) && echo " $c: $p" || echo " $c: MISSING"31done32echo "=== Local Ollama models ==="33ollama list 2>/dev/null | tail -n +2 | awk 'NF{print " "$1}' || echo " (ollama not running)"34[ -z "$(ollama list 2>/dev/null | tail -n +2)" ] && echo " ⚠ NO MODELS PULLED — run: ollama pull qwen2.5-coder:7b"35echo "=== Provider keys ==="36for k in OPENAI_API_KEY OPENROUTER_API_KEY XAI_API_KEY GEMINI_API_KEY ANTHROPIC_API_KEY; do37 [ -n "$(printenv $k)" ] && echo " $k: set" || echo " $k: —"38done39[ -f ~/.config/jack-keys.env ] && echo " (also source ~/.config/jack-keys.env for stored keys)"40```4142## Step 2 — First run: confirm the stack4344If `providers.json` is missing (or the user says "re-detect" / "I added a provider"), ask which of these they have **and want to use**, then save the answers:45461. **ChatGPT / OpenAI** — Codex CLI (`codex`) or `OPENAI_API_KEY`472. **Google Gemini** — `gemini` CLI or `GEMINI_API_KEY`483. **Grok / xAI** — `XAI_API_KEY`494. **OpenRouter** — `OPENROUTER_API_KEY` (gives free + cheap models; see `/free-mode`)505. **Hermes (Nous)** — `hermes` CLI516. **Local (Ollama)** — and which models are pulled5253Persist to `~/.claude/skills/route/providers.json` so later runs skip the questions.5455## The routing table5657| Task class | Route to | Why |58|---|---|---|59| Private / sensitive data | **Local Ollama only** | Never leaves the machine |60| Bulk / mechanical / boilerplate | Local Ollama → else cheapest API | Volume work, low reasoning |61| Huge-context read / summarize | **Gemini CLI** | Big context window, cheap per token |62| Agentic code grunt (refactor, scaffold) | **Codex CLI** (in a git repo) | Purpose-built, runs on your ChatGPT sub |63| Multi-tool / autonomous run | **Hermes** | Native tool-calling + routing |64| Cheap overflow when local is busy | **OpenRouter** free/cheap model | $0–pennies |65| Hard reasoning / architecture / final synthesis | **Stay on Claude** (or frontier) | Worth the tokens |6667## Step 3 — Route the task (delegation, works live)6869Pick the target, then shell out via Bash and bring the output back for Claude to review/assemble:7071```bash72# Local / private / bulk (free, offline)73ollama run qwen2.5-coder:7b "<prompt>"7475# Huge-context read or summary (cheap, big window)76gemini -p "<prompt>" # or: cat bigfile | gemini -p "summarize"7778# Agentic code grunt work (must be inside a git repo)79codex exec --full-auto "<prompt>"8081# Autonomous / multi-tool run82hermes -z "<prompt>"83```8485Then **Claude reviews/finishes** the cheap model's output. The frontier model stays the orchestrator; it just stops doing the cheap parts itself.8687## Whole-session cheap mode (base-switch, needs restart)8889When the *entire* session is routine work, switch the base model for the whole session instead of delegating task-by-task — identical mechanism to `/free-mode`: set `ANTHROPIC_BASE_URL` + `ANTHROPIC_MODEL` in `~/.claude/settings.json` to a cheaper provider, then restart Claude Code. Use `/free-mode on` for the OpenRouter/Qwen path. Always **confirm with the user** before a base-switch — it forces a restart.9091## Cost ladder (try cheapest first, escalate only on failure)92931. **Local Ollama** — $0, private, offline942. **A subscription you already pay for** (ChatGPT via Codex, Gemini) — sunk cost, no marginal tokens953. **OpenRouter** free / cheap models964. **Frontier** (Claude / GPT / Grok premium) — reserve for the hard ~20%9798## Principles99100- Default to the cheapest plausible model; escalate **only** when it fails or the output is weak.101- Private/sensitive → local only. Never route confidential code or client data off-machine.102- The frontier model is the **brain**; cheap models are the **hands**.103- One model is never strictly best — route by the *specific* task in front of you.104- Confirm before any base-switch (restart required).105106## Setup gaps (the detector flags these)107108- **No Ollama models** → `ollama pull qwen2.5-coder:7b` (great small coder; use `:32b` if you have ~24GB+ RAM). This is the #1 thing to fix — without it there's no local tier.109- **No OpenRouter key** → run `/free-mode` to get the free Qwen3-Coder path.110- **No Grok** → add `XAI_API_KEY` (or wire Grok via OpenRouter).