Wed, 9 Sep

Saving on Context: Spotify’s Open Plugin Cuts Claude Code Token Usage by 90%

Max Ivanov · 08.09.2026 11:39 · 2 min read

Spotify engineers have open-sourced a toolkit called Portal AI Plugins designed to optimize AI development costs. The package’s central module, Shunt, automatically intercepts Claude Code’s routine operations with large files and delegates them to fast, cheap models like Gemini 2.5 Flash. In the streaming service’s internal benchmarks, this routing cut the flagship model’s token usage by an average of 90% when reading code.

Automatic Filtering and Writing Outside the Context

The tool addresses a classic problem with expensive subscriptions: a powerful neural network spends a huge portion of its available context reading monolithic files, searching for function signatures, or writing boilerplate test stubs.

As explained in Spotify’s engineering blog, the Shunt module operates in two main modes:

  • bulk-reader: when Claude Code tries to load a source file longer than 350 lines into context, a built-in hook intercepts the request and hands the file to a helper model. Claude receives only a compact summary with key methods;
  • code-writer: generating boilerplate code, data structures, and tests from examples is delegated to a lightweight AI that saves the result directly to disk without consuming the main model’s tokens.

On a real Java project with 162,000 lines, the scheme proved highly effective: analyzing a 4,000-line file required 5,737 tokens instead of 33,684 (an 82% saving), and parsing a 7,400-line source-and-test bundle cut the system’s appetite from 75,990 to 4,148 tokens (a 94% saving).

Limitations and Loss of Nuance

Spotify cautions against inflated expectations: the 90% figure applies to batch reading of large listings, not to the overall bill for using Claude Code.

Moreover, the authors strongly advise against trusting cheap models with finding logic errors or designing architecture. During testing, the helper algorithm missed a hidden concurrency bug that Claude Code caught immediately once it received the relevant code section in full. Additionally, each external request adds network latency, making the optimization pointless on compact files up to a couple of hundred lines.

The source code for Portal AI Plugins is available on GitHub. The library supports integration with Codex and Cursor, but the Shunt router itself is currently optimized specifically for the Claude Code ecosystem.

Enjoy VseZavislo?

Add us to your preferred Google sources to see our news more often.

Add us to your Google

Share

Leave a comment