Skip to content

devlog/token-math/routing-cheap-models-for-lint-refactors-and-docstrings-1100.md

Routing Cheap Models for Lint, Refactors, and Docstrings

Sending trivial editor tasks to the most expensive model

Most routing mistakes start the same way: Claude Code, Codex, or Gemini CLI is pointed at one powerful model and then left alone. It works, so nobody touches it again. Then the spend lands and half of it is renaming a field, wrapping a call in a try block, or adding three lines of docstring. None of that needed the best reasoning available, it needed a model that reads well and answers quickly.

Fix this before you write any routing code: name the task classes you actually run and map each one to a difficulty tier. Editor traffic usually falls into four buckets: mechanical edits, single-file comprehension, multi-file refactors, and hard debugging. The first bucket repeats dozens of times a day, so give it the cheapest model that still produces a clean diff instead of a half-finished thought.

On the Fluxo shelf, that is work for Claude Haiku 4.5 or DeepSeek V4 Flash, while a flaky test in a background queue deserves Claude Opus 5.5 or Gemini 4 Argon. Because Fluxo bills per real token including cache reads and writes, with no monthly fee, the cheap calls cost almost nothing and the expensive ones stay rare on purpose.

  • Log every automated edit request with its task class and the model that served it.
  • Set the default model per task class instead of per project or per developer.
  • Reserve flagship models for calls whose failure you would notice within a minute.
  • Revisit the mapping monthly, because the cheapest reliable option on the shelf keeps moving.

Judging task difficulty by prompt length instead of failure cost

Prompt length is a terrible proxy for difficulty. A four-hundred-line diff to summarise is long but easy; naming one variable inside a concurrency bug is short and expensive to get wrong. Any router keyed on token count will misroute both, and it will do it with total confidence.

Score difficulty by the cost of a bad answer instead. If a wrong response costs you two minutes of redoing work, it is cheap-tier by definition, even if the prompt is huge. If a wrong response ships a broken migration to production, it belongs at the top of the shelf no matter how short the request is.

Encode that score as a small header, a wrapper function, or a per-command flag in your terminal tooling. The mechanism barely matters; what matters is that the decision is made per request instead of once at install time, and that a human can read the rule without opening a debugger.

  • Score a request by what a wrong answer costs you in time or risk.
  • Keep a small set of task classes so the routing decision stays understandable.
  • Prefer explicit flags in your terminal commands over hidden heuristics you cannot debug.

Forgetting cache reads and cache writes in the routing math

Everyone counts output tokens and forgets the cache. Fluxo bills per real token including cache reads and writes, so a routing rule that saves a few thousand tokens on completion can still lose money if it busts the prompt cache three times before the task finishes. Cheap models are only cheap when their context is reused.

The usual culprit is switching models in the middle of an agent loop. The system prompt, tool schema, and file context get reprocessed from scratch, and those cache writes are billed like any other token. Keep one model for the whole session and route at session boundaries instead, so the expensive context is written once and read many times after that.

This also argues for sticky sessions in your editor plugins: pick the tier when the conversation starts, then let the same model finish the job. If you really need to escalate, do it at the top of the next session, when the cache was going to be rebuilt anyway.

  • Stay on one model for the whole session to keep the prompt cache warm.
  • Route between sessions, not between turns inside a single agent loop.
  • Count cache reads and cache writes in every cost comparison you make.

Hard-coding one model across every terminal tool

A single hardcoded model string in a dotfile is the most common routing mistake I see, because it hides the decision from every tool that shares it. With Fluxo there is one key and one base URL at https://api.fluxorelay.com for Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok and more, so swapping models is a one-line change in Claude Code, Codex, Gemini CLI, or any OpenAI SDK.

Take advantage of that. Give your terminal agent a cheap default for grep-and-patch loops and a stronger model for review passes. Point your editor inline completion at the fast tier and your long-running refactor command at the reasoning tier. You are not buying a plan, you are choosing a model per call, and the bill follows the work instead of the calendar.

While you are configuring, note that users earn a referral share when people they invite pay, which is a reasonable reason to share your routing config with the team rather than hoarding it in a private branch.

Escalating to a flagship model without a defined trigger

Cheap-first routing only pays off if you define what failure looks like. Without an escalation trigger, a weak model loops on the same failing test for twenty minutes and burns more tokens than one capable call would have cost. That is the hidden failure mode of aggressive routing: it looks thrifty in the short run and wasteful in the aggregate.

Pick mechanical triggers rather than vibes. Two consecutive identical patches, three failed lint runs, or a test suite that got worse all mean the task sits above the current tier, and the request should move up and stay there for the rest of the session instead of bouncing back down on the next turn.

  • Treat two identical failed patches as a signal to escalate immediately.
  • Raise the tier when lint or test results get worse after an edit.
  • Pin the higher model for the rest of the session once you escalate.
  • Record why you escalated so you can tune the trigger next week.

Measuring token savings without measuring rework

If you only measure tokens saved, you will route too aggressively and feel clever right up until the rework bills arrive. Track rework: how often a task comes back after a cheap model touched it, and how many tokens the repair cost. A tidy diff that gets reverted twice is not a cheap diff.

A reasonable default is a cheap-tier share above seventy percent of requests with a rework rate under five percent. Log the model name alongside each task, compare those two numbers weekly, and shift tiers only when both move in the same direction. That keeps you from optimising one number while quietly wrecking the other.

Routing by difficulty is not a one-time optimization, it is a habit you keep in your editor and your shell. If you want to try the same setup, creating a Fluxo account takes a minute and works with the tools you already have. If anything in your routing setup is confusing, sign in and leave a note on the contact page.

Next in the buffer