Model routing
An agent spends most of its tokens reading: searching files, re-reading context, running routine edits. Those don't need your best model. Larik lets the main agent plan and review on a strong model while subagents do the volume work on cheap ones, across providers.
Run /routing to set it up. The wizard lists the models of every provider you've connected, with prices, and offers presets:
- Balanced: your current model stays in charge; the cheapest models it finds become
workerandexplore. The main model proactively delegates broad searches and well-specified mechanical work, but keeps trivial steps local. - Cheapest: the lowest-priced capable models for every subagent, with aggressive delegation of separable routine work.
- Local and plan first: Ollama, LM Studio or your ChatGPT plan before paid APIs, also with aggressive delegation.
Then you can adjust each role, add fallbacks and set a budget. The result is saved as plain settings, for example for a student with a small Anthropic budget, a free Gemini key and Ollama:
{
"model": "anthropic/claude-sonnet-5",
"delegation": "balanced",
"roles": {
"worker": "ollama/qwen3-coder",
"explore": "gemini/gemini-3.8-flash"
},
"fallbacks": {
"worker": ["gemini/gemini-3.8-flash"],
"explore": ["anthropic/claude-haiku-4-5"]
},
"role_options": {
"worker": { "isolation": "worktree", "max_turns": 40 },
"explore": { "max_turns": 30 }
},
"budget": { "session_usd": 2.0, "warn_at": 0.8 }
}
-
Roles:
workerruns the built-ingeneral-purposesubagent,explorethe read-onlyexploresubagent.smartis a strong model the main agent can hand hard subproblems to, andcompactsummarizes the conversation when the context fills. An unset role uses the main model, so nothing changes until you set one. You can add roles of your own and use them in agent definitions (model: reviewer), in--modeland in/model. -
Delegation policy:
manualkeeps delegation optional,balancedproactively sends broad exploration and well-specified multi-step mechanical work to cheap roles while avoiding trivial handoffs, andaggressivedelegates most separable searches, routine implementation, tests and boilerplate. The policy guides the main model; it is not a deterministic per-tool classifier. Change it withpin the wizard or/routing policy=balanced. Policy instructions are part of the cached tool prefix, so a change applies after/clearor in a new session. A shared project setting may make delegation less aggressive, but only personal settings can widen provider use. -
Per task: once a role has a model, the
tasktool gets amodelinput listing the roles with their prices. Built-ingeneral-purposeandexploreagents already default to theworkerandexploreroles, so the main model need not select the role manually. Subagent rows show the model they ran on. -
Fallbacks: when a model fails before answering with a rate limit, an exhausted quota, an auth problem, an outage or no response at all (see
stall_timeout), Larik switches to the next model in its list and says so. It never switches once output has started. A model that failed is left alone for a minute (rate limits, server errors) or ten (a missing model, a bad key, no credit, a stopped server), so later requests don't pay for the same failure. Useful with free tiers that run out mid-session. Fallbacks can be keyed by role or byprovider/model. -
Keeping cheap models on a leash: small and mid-size models sometimes lose the thread. They create stray files, "clean up" by deleting things, or repeat one command forever. Three safeguards cover this, and the presets turn them on:
role_options.<role>.isolation: "worktree"runs that role's subagents in their own git worktree (see Subagents). Their edits come back as a branch for the main agent to review and merge, so a bad run never touches your checkout. It applies unless the task or agent definition chooses otherwise; outside a git repository the subagent works in place, with a notice.role_options.<role>.max_turnscaps the role's subagents (default 100).- Every subagent is stopped when it repeats the same tool call with the same result 4 times within 8 turns. The main agent is told the subagent got stuck and to check its changes. The main agent itself isn't stopped this way, since you can see it and interrupt it.
In the wizard,
wtoggles the worktree,ctoggles a minimal prompt (below) and+/-change the turn cap. From the command line:/routing worker.isolation=worktree worker.max_turns=30. -
A smaller prompt for cheap models:
role_options.<role>.context: "minimal"drops your global instruction file (~/.config/larik/AGENTS.md) and the skills index from that role's subagents, keeping only this project's ownAGENTS.md/CLAUDE.md. The presets set it forworkerandexplore: it's a smaller prompt with less to misread, and it stops a small model from loading a skill that has nothing to do with the task. From the command line:/routing worker.context=minimal(or=empty for the full prompt). -
Budget: Larik warns once at
warn_at(default 80%) and stops before the next request once the session, subagents included, has spentsession_usd. Raise it with/routing budget=5. Local and plan-included models count as free, sosession_tokens(/routing tokens=2000000) caps them too: it counts every token the session and its subagents sent and received, cache reads included, warns at the same fraction and stops before the next request. These checks also apply before compaction, overflow retries and Claude Code CLI runtime passes; runtime usage is retained on resume. Caps are admission limits, not reservations: requests already in flight, concurrent subagents, or a whole CLI-runtime pass can overshoot before usage is reported. A shared project file can lower either cap but never raise it. -
Comparing models before you trust one:
larik bench --models worker,anthropic/claude-haiku-4-5,ollama/qwen3-coderruns small, self-checking tasks against each model in its own throwaway directory, then reports pass/fail, cost, time, tokens, peak context, malformed tool calls and runs that stopped without finishing — no separate judge model. Coding tasks usego testor an exact expected file. Three of them have a shortcut — a change that makes the visible test pass without doing what was asked — and are checked by tests the model never sees:fix-without-overfitting(a one-case test that a +1 satisfies),fix-at-the-source(a parser bug that surfaces in one of its callers, where a local workaround is shortest) andfollow-conventions(an easy fix, where the project'sAGENTS.mdalso asks for a changelog entry the prompt doesn't mention). They are where models and harness variants differ when the easy tasks all pass. Thepersistent-script-statetask requireshybridandcodemodels to carry an aggregate throughstoreandloadin two separate scripts (and has an ordinary-tools fallback), so persistent script state is measured rather than only unit-tested. Thecompaction-retentiontask forces a fixed synthetic project conversation through compaction, mechanically checks ten decisions, identifiers, constraints and next steps in the summary, then requires an exact JSON recovery answer from the compacted context; its row also reports retained facts and estimated context freed. It deliberately sends the same input to every model, so it compares summary quality rather than behavior at each model's different context-window limit. Select it alone with--tasks compaction-retention; in--models,mainmeans the configured primary model, alongside roles such ascompactandworker. Every run also counts the calls the model formed so badly they never reached a tool — truncated or unparseable arguments, arguments a tool's schema rejects, a tool that doesn't exist — broken down by kind, with the share of all calls in the per-model summary. A pass rate hides this: a model that fumbles a third of its calls and retries still passes, only slower and for more tokens. A call the tool actually ran, or that a permission check refused, is not counted — the metric measures the model, not the task.
Alongside it, runs the model ended by talking instead of acting are reported as "stopped without finishing", or "answered without calling a tool" when it made no call at all. This is the other way tool calling fails, and the more common one: the model never commits to a call rather than emitting a broken one. The two counts are independent, and a weak model often shows nothing malformed while failing every run this way. A passing run also ends in prose — that is how an agent reports it is done — so only unfinished work counts, and a timeout, the turn cap or the loop guard are not counted at all, since none of them is the model choosing to stop. --execution tools,hybrid,code runs each setting side by side, --harness none,./terse,./strict compares harness variants — directories laid out like ~/.config/larik, whose AGENTS.md becomes the global instructions and whose skills/ the skills index, so you can test a prompt or skill change before adopting it (none is the default empty one and personal your own instructions and skills; rows are named after each directory), --as worker runs each task the way that role's subagent runs it — its agent prompt, only its tools, its role_options turn cap and context setting — so you see how a cheap model does in the job it will actually have, and --context full,minimal compares the minimal setting against the full one (pair it with --harness personal for the difference to show). Under --as, a minimal-context subagent gets neither the harness's instructions nor its skills index, so those rows run the same prompt under every harness and are marked unseen: compare harnesses on the full rows, and read the minimal ones as how much runs vary on their own. --as explore runs only the tasks a read-only agent can answer in its reply. --runs 3 repeats each task and adds a table of medians and ranges, and --keep-failed keeps a failed run's directory with its transcript and every tool call (scripts' included) so you can see why. A run that ended on an error, such as a rate limit or a provider outage, shows the provider's message, and its kept transcript ends with it. Use it to see whether a role you're about to add is actually good enough, not just cheap, and which execution setting suits it. See larik bench -h.
- Compaction: the
compactrole is usually best left unset. With prompt caching, the main model re-reads the conversation at the cache price (for Opus, $0.50 per million tokens), which can cost less than a cheap model reading it all uncached. - Measuring the result:
/costreports delegated task count, the subagents' token and cost share, and—when prices are known—an estimated saving from pricing the same tokens on the main model. That estimate is directional: a direct run might use a different number of tokens because each subagent starts with a fresh context and the main model must review its result. Delegating one read or one tiny edit can cost more; broad searches and repetitive work are where routing usually pays off. - Quick edits:
/routing policy=aggressive,/routing worker=groq/llama-4-scout,/routing explore=(back to the main model),/routing budget=(no cap),/routing tokens=(no token cap).