Earlier this week, an engineer at Spotify published numbers that should make everyone running an AI coding agent sit up. By routing Claude Code's dumbest work, bulk file reading and boilerplate generation, to Gemini 2.5 Flash through their internal Portal platform, they measured mean token savings of around 90 percent across four scenarios against a Java monorepo (the full writeup is worth your time, and it was sitting at 200+ points on Hacker News within a day).
The number is impressive. But the reason I spent an evening picking this apart is the mechanism underneath it, because that mechanism has nothing to do with Spotify's platform. It is a three-layer enforcement pattern you can apply to Claude Code, Codex, Cursor, or whatever agent you drive, and it solves a problem I hit every single week.
Full disclosure before we go further: I have never used Spotify's Portal product. It is their internal developer platform, now GA, and I have no connection to it. Everything about Portal here comes from their published post. But the pattern itself I know intimately, because I run my own AI agent infrastructure and I pay my own token bills. I have just never wired the enforcement layers this cleanly. That is what this article is really about.
The problem: your agent's tokens go to I/O, not thinking
Start with the observation that makes the whole thing click. As the Spotify engineer puts it: most of what an AI coding agent does for you is not thinking. It is I/O.
Reading five files to answer a question about one method. Generating a test file that follows the exact pattern of the twenty test files next to it. Updating documentation after a meeting. Thousands of tokens, almost zero reasoning. And you are feeding all of it to a frontier model that is wildly overqualified for the job.
I feel this personally. My agent setup processes article research, repo maintenance, and scheduled jobs around the clock, and when I audited where the tokens actually went, the answer was embarrassing. The expensive model spent most of its time reading things and restating them. The actual reasoning, the part I am paying premium prices for, was a fraction of the volume.
The industry numbers back this up. The post cites a Gartner prediction that AI coding costs will surpass the average developer salary by 2028. A quarter of engineering leaders already burn $200 to $500 per developer per month on tokens. Some are past $2,000. The tools pay for themselves, but only if you stop burning frontier tokens on work that does not need them.
The fix that failed first: asking nicely
Here is the detail most coverage will skip, and it is the most instructive part of the whole story.
Spotify's first version of this was a block of routing rules in CLAUDE.md, the instruction file Claude Code reads at the start of every session. The idea: tell Claude to route bulk reads to the cheap model itself. It sort of worked, and the two failure modes are ones every developer who has ever written an agent instruction file will recognize.
- The rules were advisory, not enforced. Claude could read them and then ignore them, especially deep into a long session when the instructions have fallen out of the context window's effective attention.
- Every project needed its own copy. Instructions in a repo file do not travel. New project, new copy, drift between copies.
So they rebuilt it as a Claude Code plugin called shunt, and the rebuild is the pattern worth stealing. It has three layers.
Layer 1: hooks that physically block the expensive action
Claude Code hooks fire before every tool call, and shunt registers two PreToolUse hooks.
check-file-size fires on every Read call. If the file exceeds a configurable line threshold, 350 lines by default, the hook blocks the read outright and tells Claude to use the bulk-reader delegation instead. Targeted reads with offset and limit pass through, because when Claude already knows which section it needs, reading it directly is correct and cheap.
check-bash-read catches the sneaky workaround: cat, head, tail, less, more on large files. Piped commands like cat file | grep pass through, since those are targeted reads in disguise.
The threshold is configurable through a SHUNT_MIN_LINES environment variable in your settings. This is the heart of the pattern: the agent does not get a vote. Prompt instructions are suggestions. Hooks are architecture.
Layer 2: scripts that do the delegation
Two bash scripts wrap the actual calls to the cheap worker model. The agent calls them with named arguments, and the scripts handle request building, error unwrapping, and token usage reporting.
- bulk-read wraps each file in XML tags for clear boundaries and ships them to the worker model along with the question. Follow-up questions re-send the files, which sounds wasteful until you realize the corpus goes to the cheap model and never enters the expensive model's context at all. That is where the 90 percent lives.
- code-write sends a spec plus a reference file to the worker, strips markdown fences from the output, and can write straight to disk. The expensive model never sees the generated code. The reference file is mandatory: without a file to match patterns against, the worker produces context-free code that fits nothing in your project.
One instruction detail in their worker config matters more than it looks. The code-writer mode says output only the code, no explanations. Without that, the cheap model wraps everything in markdown fences and prose that the expensive agent then has to parse, quietly eating the savings.
Layer 3: skills that smooth the redirect
Two skill files teach the agent when and how to call the scripts. When a hook blocks a read, the block message points at the bulk-reader skill, which shows the exact invocation syntax.
The layering is what makes it robust. Even if the agent never reads the skill description, the hook still blocks the expensive read. Graceful degradation instead of all-or-nothing compliance.
The three things this pattern cannot do
The honest section of the Spotify post is the one I would make every AI-coding enthusiast read, because it draws the line between where cheap models shine and where they quietly sabotage you.
- You cannot delegate editing. The worker's summaries do not carry reliable line numbers. If the agent needs to edit based on the analysis, it still reads the specific section directly. Delegation saves tokens on understanding, not on modification.
- You cannot delegate reasoning. In their testing, the cheap worker found surface-level patterns but missed a subtle thread-safety bug. Claude spotted it in seconds once given the right context. Their routing explicitly excludes debugging, architectural decisions, and safety-critical code.
- Latency adds up. Each delegation is a network round trip, typically 10 to 30 seconds, and their platform caps a single invocation at 30 seconds. Below the line threshold, delegation overhead exceeds the savings. The threshold is not a tuning knob for greed, it is a guardrail against making things worse.
That second point deserves a hard stare from anyone who has ever been told smaller models are catching up. For pattern-following and information extraction, a fast cheap model is genuinely enough. For the reasoning that makes a senior engineer valuable, it is not, and pretending otherwise moves bugs from your token bill into your production code.
The pattern, generalized to your own setup
You do not need Spotify's platform to use this. Strip away Portal and the shape is three decisions, and they port to any agent with a hook system, which in 2026 means most of them.
- Find your I/O-heavy tool calls and gate the expensive ones. In Claude Code, that is PreToolUse hooks on Read and Bash. In other agents, look for the equivalent policy or permission layer. The question to ask of your own sessions: which tool calls moved the most tokens and moved the least thinking?
- Give the work to a cheap model through a script, not a prompt. A wrapper script around any budget API, a local model via Ollama if the task is simple enough, or a batch-tier endpoint if you can tolerate latency. The script reports its own token usage so you can verify the savings are real.
- Keep reasoning on the expensive model, and write the exclusion down. Debugging, architecture, security review, anything where a subtle miss costs more than the tokens saved. If the exclusion list only lives in your head, the routing will eventually eat something that matters.
The save-worthy version, if you only take one thing from this article: delegate reading and boilerplate, never debugging and design, and enforce the boundary with hooks rather than hoping the model follows instructions. Prompt compliance decays over a long session. A blocked tool call does not.
What I would measure first
If you run agents on metered tokens, do what I did after reading the Spotify post: pull your own usage data before building anything. My audit of my own infrastructure showed the classic split, the bulk of tokens going to file reads and restatement rather than reasoning, which is exactly the shape this pattern targets. If your profile looks different, if you are mostly generating novel code rather than navigating large codebases, your savings will land well below 90 percent, and you should know that before you invest an evening in the plumbing.
The post does not publish absolute costs, only percentage savings, so I cannot tell you what this saves in dollars per developer per month. Against the Gartner numbers above, though, a quarter of teams burning $200 to $500 per developer monthly have real money on the table.
I write about AI agents, developer tools, and the engineering judgment behind them every week. Subscribe, it is free, and it tells me this kind of deep-dive is worth the token bill.
Have you tried model routing in your own agent setup, whether through a platform like Portal or a homegrown script? What did you delegate, and what blew up? I am genuinely curious whether others are seeing savings anywhere near Spotify's 90 percent, because my instinct says their Java monorepo, large and pattern-heavy, is close to the best case for this technique.
The following examples are from Spotify's engineering blog and their public portal-ai-plugins repository: the bulk-reader and code-writer mode configs, the hook thresholds, and the benchmark figures. I have not run Portal myself.
Top comments (0)