The Spotify AI Routing Architecture for Claude Code is an internal engineering design and open-source system created by music streaming company Spotify. It is designed to lower computing costs when software engineers use Claude Code, an autonomous computer program (an AI coding agent) made by Anthropic that writes and edits software code.
In September 2026, Spotify engineer Dimitri Mazmanov published benchmark results showing that routing simple tasks away from high-end AI models to smaller, cheaper models decreased token consumption on the primary model by approximately 90%.
Background and Motivation
Modern software teams use large language models (computer programs trained on massive amounts of text to understand and generate language) to build and edit code. AI services bill customers based on tokens (small word fragments, typically around four letters or one syllable, used as units to measure text and compute costs).
When an AI coding agent examines a large codebase (a full collection of source code for a software project), it frequently loads large files directly into its memory window. Spotify identified that a significant majority of agent operations involve I/O (input and output, meaning reading files and writing repetitive text) rather than deep logical problem-solving. Because top-tier "frontier" models charge premium prices for processing tokens, using them to read hundreds of unchanged lines creates high server bills.
Technical Mechanism
The routing setup relies on three primary components:
- Shunt: An extension (a small software add-on) built for Claude Code. It uses interceptors called hooks (automated triggers that stop an action before it happens to inspect it). By default, if Claude attempts to read any file larger than 350 lines, Shunt blocks the read and instructs the agent to hand the task to a helper.
- Bulk-Reader Mode: A sub-agent configured to run on a lightweight model, specifically Gemini 2.5 Flash. The reader inspects the full file, summarizes only the relevant functions or lines, and returns that short summary to Claude.
- Code-Writer Mode: A secondary mode that generates boilerplate code (standard, repetitive code blocks that follow a set pattern, such as software tests or basic templates) and writes them directly to the disk without sending every generated line back through the expensive model.
Developer Prompt
│
▼
┌──────────────┐ File > 350 lines? ┌───────────────────────┐
│ Claude Code │ ───────────────────────────> │ Bulk-Reader │
│ (Frontier AI)│ <─────────────────────────── │ (Gemini 2.5 Flash) │
└──────────────┘ Concise Summary └───────────────────────┘
│
▼ Deep Reasoning Only
Limitations and Trade-offs
Spotify outlined three key constraints of this delegation pattern:
- Lack of Reasoning for Hard Bugs: Smaller worker models can identify simple patterns but miss nuanced flaws, such as concurrency bugs (errors where two computer operations clash while trying to run at the same time). Debugging and core architectural planning remain restricted to the primary model.
- No Direct Line Numbers: Summaries from the reader model do not provide exact line counts, preventing the main agent from using them directly for line-by-line file edits.
- Network Delay: Delegating tasks to a secondary service introduces a latency (time delay) penalty of 10 to 30 seconds per request, making the pattern counterproductive for files under the 350-line threshold.
References
- Mazmanov, Dimitri. (September 2026). Portal by Spotify cut my Claude Code token usage by 90%. Spotify Engineering Blog.
- Koundinya, Supreeth. (September 7, 2026). Spotify Cuts Claude Code Token Usage by 90%. Analytics India Magazine.
- How did Spotify engineers reduce Claude Code's token consumption by 90%? (September 12, 2026). GIGAZINE News.
- Gupta, Ayush. (September 7, 2026). Spotify's 90% Token Cut: Sell AI Coding Cost Audits. Figuring Out AI Playbooks.

Top comments (0)