The Coe Lab
← Back to Blog

How Spotify Cut Claude Code Token Usage by 90% With Smart Model Routing

September 5, 20266 min read
AISpotifyClaude Codedeveloper toolscost optimization

Spotify's Portal AiKA Modes route boring I/O work to cheaper models, saving 90% of frontier model tokens without sacrificing code quality. Here's how the two-mode system works and why it matters for every team burning through AI budgets.

Most of what an AI coding agent does isn't thinking. It's I/O. Reading five files to answer a question about one method. Generating a test file that follows the exact same pattern as twenty others. Updating docs after a meeting. Thousands of tokens gone, almost zero reasoning involved. The seat license isn't what hurts — it's the tokens. And you're feeding all of it to a frontier model that's wildly overqualified for the job.

Spotify's engineering team just published a detailed breakdown of how they solved this problem using Portal's AiKA Modes, cutting their Claude Code token usage by 90%. The approach is elegant, practical, and replicable by any team using AI coding agents. No platform team required. No new subscription. Just two declarative modes and a smart routing layer.

The Problem: Frontier Models Doing Grunt Work

By 2028, Gartner predicts AI coding costs will surpass the average developer's salary. A quarter of engineering leaders already burn $200–$500 per developer per month on tokens. Some are well past $2,000. The tooling pays for itself, but only if you stop burning frontier-tier tokens on work that doesn't need them.

The insight is simple: not every task needs your smartest model. Reading a large file to answer a specific question doesn't require GPT-6 Astra or Claude Opus 5. Generating boilerplate tests from an existing pattern doesn't either. These are I/O-heavy, low-reasoning tasks that a cheaper, faster model handles just fine.

The Solution: Two Modes, Zero Infrastructure

Portal by Spotify introduced AiKA Modes — declarative agents that run on an ephemeral runtime, like AWS Lambda but for AI agents. You define instructions, pick a model, set parameters like temperature, and attach MCP tools. Portal handles the infrastructure. No servers to manage, no API keys to rotate, no long-running processes.

The Spotify team created two modes that work together to intercept expensive operations before they hit Claude Code's context window.

Mode 1: bulk-reader

When Claude Code needs to read multiple large files to answer a question, the bulk-reader mode intercepts. It uses a cheaper model (Gemini 2.5 Flash in Spotify's case) to read the files and return a concise, structured summary. Claude never sees the raw file contents — only the distilled answer. The instructions are precise: output structured bullets only, no greetings, no prose, no preambles. Lead every bullet with the exact name, type, or line number.

This alone saves enormous amounts of tokens. Instead of loading a 2,000-line Java file into Claude's context (which costs input tokens and fills the window), the bulk-reader sends back a 20-line summary. The question gets answered. The tokens get saved.

Mode 2: code-writer

For tests, config scaffolding, type stubs, and anything where the output is predictable from existing patterns, the code-writer mode takes over. It takes a spec and a reference file, matches the existing patterns and conventions exactly, and outputs only the code — no explanations, no markdown fences. Claude never sees the generated code. It goes directly to disk.

The reference file is critical. Without a file to match patterns against, the worker model would generate context-free code that fits nothing in your project. With it, the output is indistinguishable from what your team would write.

The Routing Layer: Hooks, Scripts, and Skills

The magic isn't just in the modes — it's in how Claude Code is directed to use them. Spotify built a three-layer routing system called Shunt.

  • Layer 1 — Hooks: Claude Code hooks fire before every tool call. A PreToolUse hook called check-file-size blocks reads on files exceeding a configurable line threshold (default: 350 lines) and tells Claude to use the bulk-reader instead. Another hook catches cat, head, tail, less, and more on large files. The threshold is tunable via an environment variable.
  • Layer 2 — Scripts: Two bash scripts wrap the Portal CLI calls. Claude calls them with named arguments. The scripts handle building the request, invoking the actions, unwrapping errors, and reporting token usage. Every delegation is one-shot and ephemeral — nothing is stored server-side.
  • Layer 3 — Skills: Markdown skill files tell Claude when and how to call the scripts. When a hook blocks an expensive read, the block message points Claude to the skill, which shows the exact invocation syntax. The system degrades gracefully — even if Claude ignores the skill, the hook still prevents the expensive operation.

The Results: 90% Token Reduction

Tested against a Java monorepo across four scenarios, the results were striking. Mean token savings for bulk-read operations hovered around 90%. That's not a marginal optimization — it's an order of magnitude reduction in the most common operation an AI coding agent performs.

The implications go beyond cost. Less context bloat means Claude has more room for the tasks that actually need its reasoning capabilities. The frontier model spends its time thinking, not reading. The cheaper model spends its time reading, not thinking. Everyone wins.

Why This Matters for Every Team

You don't need to be Spotify to apply this pattern. The core insight — route I/O-heavy, low-reasoning work to cheaper models — is universally applicable. Whether you're using Claude Code, Cursor, Copilot, or any other AI coding agent, the same principle applies.

  • Identify which operations consume the most tokens (usually file reads and code generation)
  • Determine which of those operations require frontier-level reasoning (fewer than you think)
  • Route the rest to a cheaper model that handles it just as well
  • Measure the savings and reinvest them in the work that matters

The era of treating AI coding agents as a single flat cost is over. Smart routing is the next frontier of developer tooling — not because it's clever, but because it's the difference between AI coding that scales and AI coding that bankrupts your budget.

Spotify's approach proves you don't need a platform team or a new vendor to get there. Two modes, three layers of routing, and a willingness to let your cheapest model do the boring work. That's it.

Related Posts

GPT-6 Astra: When OpenAI Solved Intelligence, Alignment, and Abstract Reasoning in a Single Day

OpenAI's GPT-6 Astra saturates ARC-AGI-3 at 99.9%, scores 100% on ExploitBench, and never goes beyond authorized scope. The most intelligent and aligned model ever built just changed the AI race overnight.

Sep 4, 20268 min

How Three Sites With 215,000 Fake Pages Are Poisoning AI Search Recommendations

A new investigation reveals that 60% of Perplexity's product recommendation citations point to obscure domains, with three sites publishing 215,000 machine-generated pages specifically designed to be cited by AI models.

Sep 3, 20266 min

Claude Fable 5.1 and Mythos 5.1: When AI Started Doing Real Science

Anthropic's new Claude Fable 5.1 and Mythos 5.1 models aren't just better at coding — they're designing proteins, mapping Venus, and optimizing GPU kernels for biologists. The gap between AI as a chatbot and AI as a research collaborator is closing.

Sep 2, 20267 min