Productivity

A Spotify engineer cut Claude Code token use about 90% by blocking large file reads and sending them to a cheaper model

September 5, 2026 at 1:05 AM PT

Spotify Engineering's feature illustration for its post on routing coding-agent work to cheaper models

Image: Spotify Engineering

Why it mattersMost agent spending goes on reading and generating files rather than reasoning, so the cheapest cost control is blocking the expensive model from doing work it is overqualified for.

Spotify Engineering published a post on 3 September describing how one of its engineers cut token spending in Claude Code by stopping the model from reading large files at all. The agent is forced to hand them to a cheaper model and receive a summary back. Across four scenarios tested on a Java monorepo, the post reports mean savings on bulk reads of around 90%.

The argument behind it is that most of what a coding agent does is input and output rather than thinking: reading five files to answer a question about one method, or generating a test file that copies the pattern of the twenty beside it.

How the block works

The mechanism is a Claude Code plugin called shunt, which registers hooks that fire before a tool call runs. One hook watches every file read. When a file is longer than a configurable threshold, 350 lines by default, the hook refuses the read and points the model at a delegation skill instead. A second hook catches the same thing arriving through shell commands such as cat and head. Targeted reads with an offset and a limit pass through, because the agent already knows which section it wants.

The work then goes to what Spotify calls a mode: a declarative agent defined by a name, instructions, a model and some parameters, running on an ephemeral runtime. Two modes carry the routing. One reads files and answers a question about them. The other generates predictable code, such as tests or config stubs, against a required reference file so the output matches existing patterns. Both use Gemini 2.5 Flash in the examples, and the post says the model field accepts any model configured in the Portal instance.

The generated code goes straight to disk and the expensive model never sees it, which is where the saving on the writing path comes from. The post says this second path is harder to measure in tokens, and gives no percentage for it.

What the author says does not work

Three limits are stated in the post. Editing cannot be delegated, because the worker model's summaries carry no reliable line numbers, so the agent still has to read the exact section it intends to change. Reasoning cannot be delegated either: in the author's testing the worker model found surface patterns but missed a thread-safety bug that Claude caught quickly once given the right context. The routing therefore excludes debugging, architectural decisions and safety-critical code by design.

The third limit is latency. Each delegation is a network round trip, replies typically take 10 to 30 seconds, and Portal cuts off a single invocation at 30 seconds, so large generations have to be split. Below the line threshold the delay costs more than the saving.

The 90% figure is Spotify's own measurement of its own tooling on its own repository, with no independent verification. The plugin also requires a Portal instance, a Spotify product sold as a seat licence plus token use. The plugins are published under Apache-2.0 at spotify/portal-ai-plugins.

The transferable part needs none of that. A hook that refuses an expensive operation is enforcement, where a rule written into a config file is advice the model may ignore. The post says the first version was exactly that, routing rules in a CLAUDE.md file, and that it worked only sometimes because nothing made it binding. Any team paying per token can apply that distinction today, whatever it routes the work to.

Source

Portal by Spotify cut my Claude Code token usage by 90%, Spotify Engineering, 3 September 2026. The post carries 103 points on Hacker News.

Source: Spotify Engineering

This item was written by an AI system from the linked source. Reveneau is responsible for what it publishes.

More from AI News

Spotify published a Claude Code plugin that hands file reading to a cheaper model, and measured a 90% cut in bulk-read tokens

Spotify published a Claude Code plugin called shunt that sends file reading and boilerplate writing to Gemini 2.5 Flash workers, and reports mean savings of about 90% on bulk reads against a Java monorepo.

Productivity

Spotify open-sourced the Claude Code plugin that sends its big file reads to a cheaper model

Spotify published a Claude Code plugin that intercepts large file reads and routes them to a cheaper worker model, and says the mean saving on bulk reads was around 90 percent.

Productivity

Spotify's Claude Code plugin blocks big file reads and sends them to a cheap model instead

Spotify published a Claude Code plugin that intercepts reads of files over 350 lines and routes them to a cheaper worker model, reporting mean savings of around 90 percent on bulk reads in its own tests.

Productivity