How a Spotify Engineer Cut Claude Code Token Costs by 90% Using Cheaper AI Models
AI coding assistants are becoming expensive luxuries for engineering teams, with token costs expected to exceed average developer salaries by 2028. A Spotify engineer has demonstrated a practical solution: delegate routine work to cheaper models and reserve expensive frontier models like Claude for tasks that actually require advanced reasoning. The approach cut token consumption by 90% in real-world testing.
Why Are AI Coding Costs Spiraling Out of Control?
The problem isn't the seat licenses for AI coding tools; it's the tokens. Every file read, every test generated, every documentation update consumes tokens that get billed to expensive frontier models. A quarter of engineering leaders already spend $200 to $500 per developer per month on tokens, with some teams burning past $2,000 monthly. By 2028, AI coding costs are expected to exceed the average developer's annual salary, making the economics unsustainable unless teams find ways to optimize.
The core issue is that most AI coding work isn't actually thinking. Reading five files to answer a question about one method, generating a test file that follows an existing pattern, or updating documentation after a meeting involves thousands of tokens but minimal reasoning. These tasks don't require Claude's advanced capabilities; they require efficiency.
How Can Teams Reduce AI Coding Costs Without Sacrificing Quality?
The Spotify engineer's solution uses a two-tier routing system that automatically delegates routine tasks to cheaper models while preserving expensive models for complex reasoning. The approach relies on three layers: hooks that intercept expensive operations, scripts that wrap cheaper model calls, and skills that guide Claude on when to delegate.
- Bulk Reading Mode: When Claude would otherwise read multiple large files to answer a single question, a cheaper model (Gemini 2.5 Flash in the examples) reads the files and returns a structured summary. This eliminates thousands of tokens that would otherwise flow through Claude's context window.
- Code Writing Mode: For predictable output like test files, configuration scaffolding, or type stubs, a cheaper model generates code based on reference files and existing patterns. The generated code goes directly to disk; Claude never sees it, eliminating expensive output tokens.
- Targeted Reads: When Claude needs to make edits based on analysis, it can still read specific sections directly using offset and limit parameters, avoiding the cost of re-reading entire files.
The system uses Claude Code hooks that fire before every tool call. A hook called check-file-size blocks reads on files exceeding 350 lines (configurable) and directs Claude to use the bulk-reader instead. Another hook, check-bash-read, catches shell commands like cat, head, tail, less, and more on large files. Targeted reads pass through because Claude already knows what section it needs.
What Are the Real-World Results?
Testing against a Java monorepo across four scenarios showed mean bulk-read savings of around 90% in tokens Claude would consume reading files directly versus consuming the cheaper model's summary. The code-write scenario is harder to measure in pure token terms because without the delegation system, Claude both reads reference files and generates output as expensive tokens. With the system in place, the code goes straight to disk, and Claude never processes it.
However, the approach has limitations. Delegation doesn't work for editing tasks; cheaper models' summaries don't include reliable line numbers, so Claude still needs to read specific sections directly when making changes. The system also can't delegate reasoning or debugging. In testing, the cheaper model found surface-level patterns but missed a subtle thread-safety bug that Claude spotted immediately once given the right context.
Latency is another consideration. Each delegation involves a network round-trip from Claude Code to the backend to the worker model and back, typically taking 10 to 30 seconds. Portal caps single invocations at 30 seconds, so very large generations need to be split into smaller calls. This is acceptable for large reads but counterproductive for quick tasks.
How Does the Routing System Actually Work?
The Spotify engineer's implementation uses Portal by Spotify, a platform for running declarative agents on ephemeral runtimes. Modes are defined with instructions, a chosen model, parameters like temperature, and attached tools. Portal handles infrastructure, API keys, and server management. Modes can be public (shared company-wide) or private.
The bulk-reader mode is configured with a temperature of 0.2 (favoring consistency over creativity) and instructions to read provided files and answer questions concisely using structured bullets only, with no greetings or prose. The code-writer mode uses the same temperature and instructions to generate code files based on a specification and reference files, matching existing patterns exactly and outputting only code without explanations.
A Claude Code plugin called shunt handles the routing logic. It registers PreToolUse hooks that intercept file reads and bash commands before they execute. If a file exceeds the threshold, the hook blocks the read and tells Claude to use the bulk-reader skill instead. The threshold is configurable via the SHUNT_MIN_LINES environment variable, allowing teams to adjust based on their needs.
Two bash scripts wrap Portal CLI calls. The bulk-read script wraps each file in XML tags for clear boundaries and sends them to the bulk-reader mode along with the question. The code-write script sends a specification and reference file to the code-writer mode, strips markdown fences from the output, and can write directly to disk. Claude never sees the generated code.
What Does This Mean for the Broader AI Coding Market?
The Spotify approach addresses a fundamental economic problem in AI-assisted development. As frontier models become more capable and more expensive, the cost-per-token economics make them unsuitable for routine work. The solution isn't to abandon expensive models but to use them strategically, reserving their reasoning capabilities for problems that actually require them.
This pattern suggests that future AI coding tools may need built-in cost optimization. Rather than routing all work through a single expensive model, tools that intelligently delegate routine tasks to cheaper alternatives could become table stakes for enterprise adoption. The 90% token reduction Spotify achieved demonstrates the potential savings, but the approach requires careful design to avoid degrading code quality or introducing latency that frustrates developers.