personal finance : Your Money Personal Finance : Your Money 2026: How One Spotify Engineer Slashed Claude Code Token Costs by 90%

Tuesday, September 15, 2026

How One Spotify Engineer Slashed Claude Code Token Costs by 90%

 

How One Spotify Engineer Slashed Claude Code Token Costs by 90%

Most of what an AI coding agent does is not deep reasoning. It is I/O. Reading five files to answer a question about a single method. Generating a test file that mirrors the twenty already sitting in the same directory. Scaffolding configuration or type stubs that follow established project conventions. Each of those operations burns thousands of tokens, yet almost none of them require the sophisticated judgment of a frontier model. The seat license is rarely the real cost. The tokens are. And far too often those tokens are spent on a model that is dramatically overqualified for the task.

By 2028, industry forecasts suggest AI coding costs could exceed the average developer’s salary. Already a meaningful share of engineering leaders report spending $200–$500 per developer per month on tokens, with some organizations well past $2,000. The tools deliver real productivity gains, but only if teams stop feeding every routine operation to the most expensive model available.

In early September 2026, Spotify engineer Dimitri Mazmanov published a practical demonstration of how to stop that waste. Using Spotify’s internal Portal platform and a lightweight Claude Code plugin called shunt, he routed bulk file reading and predictable code generation to a cheaper worker model—Gemini 2.5 Flash in the examples—while reserving Claude for genuine reasoning. Across carefully measured scenarios on a large Java monorepo, the approach reduced the frontier-model context Claude consumed by an average of roughly 90 percent on bulk-read workloads.

The insight is straightforward. Claude Code, like other agentic coding systems, spends a large fraction of its context window on material that does not need frontier-level intelligence. The solution is not to abandon the powerful model, but to stop asking it to perform every mechanical step itself. Portal’s AiKA Modes made the separation practical. A mode is a declarative agent that runs on an ephemeral runtime—comparable to a serverless function but designed for language-model workloads. Developers define instructions, choose a model, set parameters such as temperature, and attach any needed tools. Portal manages authentication, execution, and scaling. Modes can be public (shared company-wide) or private, and they are callable from a CLI or API.

Mazmanov created two modes. The first, bulk-reader, accepts one or more files plus a focused question and returns concise, structured answers. It is instructed to lead with exact names, types, or line numbers, use nested bullets for detail, and omit greetings or prose. The second, code-writer, generates code from a natural-language specification and a reference file that exemplifies project style and patterns. Its system prompt insists on pure code output—no markdown fences, no explanations—so the result can be written directly to disk without further parsing by Claude. Both modes used Gemini 2.5 Flash in the published examples, though any model configured in the Portal instance can be substituted.

Simply defining the modes was not enough. Early experiments that placed routing rules in a CLAUDE.md file proved advisory rather than binding; Claude sometimes ignored them. The durable solution is the open-source shunt plugin, available in Spotify’s portal-ai-plugins marketplace. Shunt enforces the routing through three coordinated layers.

First come PreToolUse hooks. One intercepts every Read tool call. If the target file exceeds a configurable line threshold (default 350), the hook blocks the full read and instructs Claude to use the bulk-reader skill instead. Targeted reads that already specify an offset or limit are allowed to proceed, because Claude already knows the precise section it needs. A second hook watches Bash tool calls and blocks naïve uses of cat, head, tail, less, or more on large files, while still permitting piped or filtered commands that extract only relevant portions.

Second are thin wrapper scripts. Claude never constructs complex shell pipelines from natural language. It simply calls a named script with explicit arguments—paths and a question for bulk-read, or a specification, reference file, and optional target path for code-write. The scripts handle message construction (wrapping each file in clear XML tags), invocation of the Portal action registry, error unwrapping, and reporting of token usage.

Third are skill files—short markdown documents that tell Claude when and how to invoke the scripts. When a hook blocks a read, the blocking message points directly at the bulk-reader skill, which supplies the exact invocation syntax. The layering is deliberate: even if Claude never consults the skill, the hard gate still prevents the expensive operation. The skill merely makes the redirect smoother.

Benchmarks were run against a 162,000-line Java monorepo. Three bulk-read scenarios produced the headline savings: a single 4,014-line file dropped from an estimated 33,684 Claude tokens to 5,737 (82 percent reduction); a 7,408-line source-and-test pair fell from 75,990 to 4,148 tokens (94 percent); and a 1,281-line cross-service set declined from 16,221 to 821 tokens (94 percent). The mean across those three cases was approximately 90 percent. A fourth code-generation scenario is harder to quantify in pure token terms because, without the plugin, Claude both reads reference material and emits the generated code as expensive output tokens. With shunt, the worker model writes the code straight to disk; Claude never sees the full content.

 Key Points

- Most AI coding agent token spend is I/O (large file reads, boilerplate generation), not deep reasoning.

- Spotify’s approach routes bulk reads and predictable code generation to a cheaper worker model (e.g., Gemini 2.5 Flash) via Portal AiKA Modes.

- Two public modes handle the work: bulk-reader for concise analysis and code-writer for pattern-matched generation that can write directly to disk.

- The open-source shunt plugin enforces routing with three layers: PreToolUse hooks that block expensive full-file reads (default threshold 350 lines), wrapper scripts that cleanly invoke the modes, and skill files that guide Claude.

- Benchmarks on a large Java monorepo showed average ~90% reduction in Claude context tokens on bulk-read scenarios (82–94% range).

- Targeted reads (with offset/limit) and deep reasoning remain with Claude; the system deliberately avoids delegating edits or subtle correctness work.

- Latency of 10–30 seconds per delegation and a 30-second Portal limit mean the technique is best for larger files and tasks.

- Modes are reusable, shareable, and easily customized; the same pattern can extend to documentation, review summaries, or other repetitive work.

- The core architecture—deterministic boundaries that keep frontier models focused on judgment—is portable beyond Spotify’s stack.

The approach is not without limits. Summaries returned by the worker model do not reliably preserve line numbers, so edits still require Claude to perform targeted reads of the relevant sections. Deep reasoning and subtle correctness issues—such as a thread-safety bug that the cheaper model missed—remain the province of the frontier model. Each delegation adds network latency, typically 10–30 seconds, and Portal imposes a 30-second ceiling on a single invocation, so very large generations must be split. The line threshold exists precisely because for small files the overhead of delegation exceeds the savings.

Token reduction is only the beginning. Because modes are named, reusable, and shareable, the same bulk-reader and code-writer configurations work across every project and every tool that can call the Portal CLI. Teams can fork the public modes, customize the system prompt or swap the worker model, and their versions automatically take precedence. The same pattern can be extended: a documentation writer, a code-review summarizer, an internationalization helper. The routing decision lives in the plugin; the behavior lives in the mode. Changing the worker model or the instructions requires no change to the enforcement layer.

 Conclusion

Mazmanov’s implementation is specific to Claude Code and Spotify’s Portal, yet the three-layer pattern is portable. Any agent framework that supports pre-tool hooks or equivalent interception points can adopt the same discipline: identify the high-volume, low-reasoning operations, route them to an appropriately sized model, and enforce the boundary rather than merely suggest it. The result is not merely a lower bill. It is a clearer separation of concerns between mechanical throughput and genuine intelligence—an architecture better matched to the economics and the capabilities of today’s models.

As AI coding tools become standard, teams that continue treating frontier models as universal file readers and boilerplate engines will face rising costs and diluted focus. Those that deliberately shunt routine I/O to cheaper specialists while protecting the expensive model for judgment will extract more value from every token. Spotify’s experiment shows that the technical pieces already exist. The remaining work is cultural and architectural: deciding which tasks truly need frontier intelligence and building the guards that keep everything else out of its context window.

Popular Posts