4 min read AI-generated

Spotify Engineer Cuts Claude Code Tokens by 90%: Hooks Block Expensive Reads and Hand Them to Gemini Flash

Copy article as Markdown

A principal product manager at Spotify built a Claude Code plugin that delegates large file reads and boilerplate code to a cheap model. The idea: let the frontier model think, not read. The post has been sitting near the top of Hacker News since Friday night.

Featured image for "Spotify Engineer Cuts Claude Code Tokens by 90%: Hooks Block Expensive Reads and Hand Them to Gemini Flash"

Dimitri Mazmanov’s thesis is simple: most of what a coding agent does for him isn’t thinking, it’s I/O. Reading five files to answer a question about one method. Generating a test file that looks exactly like the twenty next to it. Thousands of tokens, almost zero reasoning, all of it fed to a frontier model that is wildly overqualified for the job. So he rerouted the grunt work. His September 3 post on the Spotify Engineering blog hit the Hacker News front page on Friday with 250 points.

The setup

Mazmanov uses Portal by Spotify, the commercial version of Backstage. It has something called “AiKA Modes”: declarative agents that run on an ephemeral runtime. He compares it to AWS Lambda, just for agents. You define instructions, model, temperature, and MCP tools in a few lines of YAML, and that’s it. He built two.

A bulk-reader takes the files you pass it and answers a question with structured bullets only, no greeting, no prose, every bullet starting with an exact name or line number. A code-writer takes a spec plus a reference file and returns nothing but code that copies the reference’s patterns exactly. Both run on Gemini 2.5 Flash in his examples.

The interesting part is how it plugs into Claude Code. Version one was a set of routing rules in CLAUDE.md. That sort of worked: Claude could ignore the rules, and every project needed its own copy. The current version is a plugin called shunt, built in three layers.

Hooks: Two PreToolUse hooks fire before every tool call. One checks the file size on every Read. Above 350 lines, the read is blocked and Claude is told to use the bulk-reader skill instead. Targeted reads with offset and limit pass through. The second hook catches cat, head, tail, less, and more on large files but lets pipes like cat file | grep go through.

Scripts: Two bash scripts wrap the Portal CLI calls. bulk-read wraps each file in XML tags and sends them along with the question. code-write sends spec and reference, strips markdown fences from the response, and can write straight to disk. Claude never sees the generated code.

Skills: Two markdown files tell Claude when and how to call the scripts. When a hook blocks a read, the error message points directly at the skill. The system degrades gracefully: even if Claude never reads the skill, the hook still blocks the expensive read.

The numbers and the limits

Tested on a Java monorepo across four scenarios, bulk-read saved around 90 percent of the tokens Claude would otherwise have spent reading directly. code-write is harder to measure, because without shunt, both reading the references and writing the output show up as expensive output tokens.

Mazmanov also writes down what doesn’t work. Editing can’t be delegated, because the worker model’s summaries don’t carry reliable line numbers. Neither can reasoning: the worker found surface-level patterns but missed a subtle thread-safety bug that Claude spotted in seconds once it had the right context. Debugging, architectural decisions, and safety-critical code are excluded from routing. And every delegation costs 10 to 30 seconds of latency, with Portal capping at 30. Below the line threshold, the overhead eats the savings.

What I’m taking from this

The Portal dependency means most of us can’t use the plugin as is. The pattern underneath is a different story, and you can rebuild it with stock parts: a PreToolUse hook that blocks large reads, a script that ships the file to a cheap model, a skill that shows Claude the way. The real insight is that hooks enforce rules where CLAUDE.md merely asks.

With the weekly limit cuts landing on September 14, this question is about to get interesting for a lot of people: what actually needs the big model, and what doesn’t? Mazmanov’s answer is less than you’d think. I’ll be trying this with a Haiku worker over the next few days.

Sources: Spotify Engineering: Portal by Spotify cut my Claude Code token usage by 90%, Hacker News discussion