Skip to content
induwara.lk
Premium
Opinionai-codingclaude-codedeveloper-tools

Cutting Claude Code token usage 90%: Spotify's routing trick

Spotify says a routing plugin cut Claude Code token usage by ~90% on bulk file reads. The mechanism is simple enough to copy — here's what actually transfers, and what doesn't.

Induwara Ashinsana5 min read
Spotify Engineering blog feature image for the Portal AI plugins article
Image: Spotify Engineering

Cutting Claude Code token usage is suddenly a real engineering problem, and Spotify just published the most copyable answer I've seen. In Portal by Spotify cut my Claude Code token usage by 90% on Spotify Engineering, the author describes a plugin that stops Claude from reading big files itself and hands that job to a cheaper model.

The headline number is eye-catching. The idea underneath it is more useful, and you don't need Spotify's platform to steal it.


🔍 The actual insight is a payroll argument

The line that landed for me:

"Most of what an AI coding agent does for me isn't thinking. It's I/O."

That reframes the cost problem entirely. When Claude reads six files to answer one question, you are paying frontier-model input rates to do something closer to cat. The model is, in the author's words, wildly overqualified for it.

The article cites two numbers worth holding onto:

Claim As stated in the source
Current spend "A quarter of engineering leaders already burn $200–$500 per developer per month on tokens."
Trajectory "By 2028, AI coding costs are expected to blow past the average developer's salary."

Convert $200–$500 a month to LKR and you're looking at a line item that competes with a junior developer's salary here. That's the part a Colombo agency lead should sit with. Spotify is solving a budget problem. For a three-person team in Sri Lanka billing in LKR, it's closer to an existence problem.


🛠️ How the plugin works, in three layers

Portal is Spotify's internal platform for what they call AiKA Modes — declarative agents that run on ephemeral infrastructure, Lambda-style. You write instructions, pick a model, attach MCP tools, and call it from the CLI. No servers, no key management on your side.

On top of that, the shunt plugin (published at the spotify/portal-ai-plugins marketplace) defines two worker modes. Both use Gemini 2.5 Flash in the published examples, though the model field accepts anything configured in your Portal instance.

Mode Job Trigger
bulk-reader Read and summarise large files so Claude never loads them Files over 350 lines (configurable)
code-writer Produce predictable output — tests, configs, scaffolding — by matching existing patterns Delegated writing tasks

The enforcement is the clever bit, and it's three layers deep:

  1. HooksPreToolUse hooks intercept file reads and bash commands on large files, block them, and redirect to bulk-reader.
  2. Scripts — thin wrappers that call the Portal CLI, format the request, and strip markdown from the response.
  3. Skills — markdown files telling Claude when and how to delegate.

Key takeaway: The skills layer is advice; the hooks layer is law. Because the hook physically blocks the read, the system still works even if the model ignores the instructions. That's the design lesson — enforce routing at the tool boundary, not in the prompt.


📊 What the 90% actually measures

This is where I'd slow down before quoting the number in a pitch deck.

The source is specific about methodology: tested against a Java monorepo across four scenarios, comparing tokens Claude would consume reading files directly against consuming the bulk-reader summary or writing via code-writer. Mean bulk-read savings came out "around a whopping 90%."

So:

  • It's a mean across four scenarios, not a fleet-wide bill comparison.
  • It's measured on a Java monorepo — a codebase style with lots of long, verbose, low-information-density files. That's the best case for summarisation.
  • It measures tokens avoided on reads, not your total invoice. Reasoning tokens are untouched by design.

None of that makes it wrong. It makes it a ceiling rather than a floor. If your repo is a Next.js app with 120-line components, the 350-line threshold rarely fires and your savings will be a fraction of that.

The author is also honest about the limits, and I'd repeat all three:

Limitation Why it matters
"You can't delegate editing." Precise diffs still need the good model
"You can't delegate reasoning." Architecture, debugging, tradeoffs stay expensive
"Latency adds up." Delegation costs 10–30 seconds per round-trip; Portal caps invocations at 30 seconds

That last one is a real tax. You are trading wall-clock time for money. On a fast connection with a big budget, that trade is bad. On a metered connection with a small budget, it's obviously good.


💰 What a small Sri Lankan team should copy

You almost certainly can't run Portal. It's Spotify's internal platform. But the plugin is scaffolding around a pattern that is entirely yours to reimplement:

  1. Measure before you optimise. Find out what your context is actually made of. Our AI Token Counter will tell you how many tokens a given file costs across GPT, Claude, and Gemini tokenizers. If your biggest file is 400 tokens, stop reading this and go do something else.
  2. Pick a cheap worker. Compare input and output rates on the AI Model Comparison tool. The gap between a frontier model and a fast small one is where the entire saving lives.
  3. Enforce at the hook, not the prompt. Claude Code's PreToolUse hooks are documented and free. A hook that blocks reads over N lines and shells out to a cheap-model summariser is a weekend script, not a platform.
  4. Set your threshold from your own repo, not from Spotify's Java monorepo. Sort your files by line count and put the cutoff where the long tail starts.
  5. Budget in LKR. If you bill clients in dollars, the Freelancer USD-LKR Earnings Calculator is the honest way to see what a token bill costs you after conversion.

💡 What this means for you

The reusable idea here isn't Portal, and it isn't 90%. It's that an AI coding agent is a team, and you have been putting your most expensive engineer on file-reading duty.

For a large company, routing is a cost-optimisation. For a student on free tiers, a solo freelancer, or a small studio in Sri Lanka, it's the difference between using these tools daily and rationing them. The cheap model reads. The expensive model thinks. Enforce that split in code, because the model will not enforce it for you.

Start by measuring. Most people who assume they have a token problem actually have a context-hygiene problem, and that one is free to fix.

#ai-coding#claude-code#developer-tools
IA

Induwara Ashinsana

Information Systems student at UCSC and Executive Director at Ryzera Technologies. Writes about software, AI, and what it means for builders in Sri Lanka.

About the author →

Keep reading