How did Spotify engineers reduce Claude Code's token consumption by approximately 90%?

Music streaming service Spotify has revealed a method to significantly reduce token consumption by offloading simple tasks that consume large amounts of tokens in Claude Code to another AI model. Spotify's Dimitri Mazmanov reported that testing this method resulted in an average reduction of approximately 90% in token consumption on the Claude side in tests where a large number of file reads were delegated.
Portal by Spotify cut my Claude Code token usage by 90% | Spotify Engineering
Spotify Claude Agent SDK case study | Claude by Anthropic
https://claude.com/customers/spotify
The AI coding agent consumes many tokens for tasks such as reading five files to answer a question about a particular method, or writing new tests in the same format as 20 existing tests. Mazmanov felt that much of this work was simply input/output (I/O) rather than sophisticated reasoning, and that it wasn't necessary to leave everything to a high-performance model.
Mazmanov then utilized ' AiKA Modes ,' which is included in Spotify's developer platform, ' Portal by Spotify .' AiKA Modes allows you to declaratively configure instructions for the AI, the model to use, parameters such as temperature, and available MCP tools, and then call the configured settings as a single agent from the Portal CLI or API. Since the execution environment is created temporarily, there is no need to prepare a separate server for agents that runs continuously.
Mazmanov used this mechanism to create two modes: ' bulk-reader ' and ' code-writer .' He also specified Gemini 2.5 Flash as a lighter working model than Claude for both modes. However, it doesn't have to be Gemini 2.5 Flash; it can be replaced with another model configured in Portal.
The role of 'bulk-reader' is to read large files on behalf of Claude. For example, if Claude Code needs to examine multiple large source files, instead of putting the entire file into Claude's context, it passes the file and the question to bulk-reader. bulk-reader then reads the file, summarizes only the information necessary to answer the question, and returns it to Claude. In other words, instead of having Claude read thousands of lines of source code, it only has to read a short summary extracted from it, thus reducing the number of input tokens on Claude's side.

On the other hand, 'code-writer,' in contrast to bulk-reader, is a mechanism to separate the task of 'outputting' large amounts of code from Claude. For things that can be created by mimicking patterns in existing code, such as test code, configuration file templates, and type definitions, Claude passes the specifications and reference files to the working model to generate the code. The code generated by the working model can also be written directly to a file, in which case Claude doesn't even need to receive the generated code. Another key point is that specifying reference files is mandatory, so that the working model does not generate generic code unrelated to the project, but rather generates code that conforms to the naming conventions and writing style of the existing code.

However, simply instructing Claude to 'delegate simple tasks to another model' didn't make the system work reliably. Mazmanov initially wrote the distribution rules in the 'CLAUDE.md' file for each project. However, since the contents of CLAUDE.md are merely instructions, Claude sometimes didn't follow them, and it was also necessary to prepare the same rules for each project. Therefore, he adopted a method of enforcing distribution using a Claude Code plugin called '
'shunt' utilizes the 'PreToolUse' hook in Claude Code to check the process just before Claude executes a tool. For example, if Claude tries to open a file with the Read tool, shunt will, by default, block reading files larger than 350 lines and instruct Claude to use bulk-reader. It similarly detects operations that read large files using commands such as 'cat,' 'head,' 'tail,' 'less,' and 'more,' which are used to view the contents of files on Linux and macOS. On the other hand, if Claude already knows which part to read and specifies to read only that part, or if it narrows the content to read, such as with 'cat file | grep,' it is allowed without any problems.
The key to Mazmanov's method lies in its mechanical separation of 'information that Claude should read' and 'information that Claude does not need to read.' Specifically, the hook prevents the loading of unnecessarily large files, the Claude Code Skill instructs Claude on how to call the working model, and the shell script actually calls the working model via the Portal CLI. Even if Claude fails to properly reference the Skill, the hook itself prevents the loading of large files, thus significantly reducing token consumption compared to simple prompting.
Furthermore, the large amount of source code passed to the working model does not enter Claude's context. Each call to bulk-reader is independent and the server does not maintain the state of the conversation, so it may be necessary to resend the same file, but the working model is responsible for processing that large amount of tokens. Claude only receives the answer, so its context does not need to be filled with a large amount of source code.

Mazmanov used a Java monorepo to compare four different scenarios where Claude reads files directly versus reading summaries from bulk-reader. His results showed that using bulk-reader reduced token consumption on Claude's side by an average of approximately 90%.
On the other hand, for code-writers, while normally both input tokens are generated when Claude reads reference files and output tokens are generated when writing code, when delegating and writing directly to a file, the generated code does not pass through Claude at all, making a simple comparison of the number of tokens difficult.
Of course, it's not always best to delegate everything to another model. Mazmanov's testing showed that while the lightweight working model could find superficial code patterns, it sometimes missed thread safety issues. Therefore, the policy is to delegate tasks requiring advanced reasoning, such as debugging, architectural decisions, and creating safety-critical code, to Claude. Also, since calling another model typically takes 10 to 30 seconds, a certain threshold has been set to avoid delegating for small files.
Spotify isn't trying to reduce its use of Claude itself. As part of another initiative, Spotify is integrating the Claude Agent SDK into its large-scale code change platform, Fleet Management, and using Claude for code migrations across multiple repositories. According to Anthropic, the coding agent running in the background at Spotify generates more than 650 pull requests every month and has reduced the amount of time engineers spend on complex code migrations by up to 90%.
Related Posts:
in AI, Posted by log1i_yk







