How Spotify's new AiKA Modes and the shunt plugin reduce Claude Code token consumption by 90 percent using cheap worker models.

We have all been there. You spin up an agentic coding assistant to help refactor a legacy service or write unit tests. You expect deep architectural insight, but instead, the agent spends eighty percent of its time, and your budget, reading files. It reads the same configuration file over and over. It consumes thousands of tokens just to pull in boilerplate code. The final bill arrives, and you realize you just paid premium frontier model rates for basic input and output operations.
At Algoramming, we build modern digital products for clients worldwide, and we manage these token costs daily. When we are designing a web application design & development pipeline or managing a massive legacy migration, efficiency is everything. That is why a recent engineering breakthrough from Spotify caught our attention.
In September 2026, Spotify engineers revealed they slashed Claude Code token consumption by an average of ninety percent. They accomplished this not by writing less code or restricting developer access, but by routing routine tasks to cheaper models using declarative agents called AiKA Modes within Spotify Portal, their commercial internal developer portal built on Backstage. This architecture is a masterclass in modern agentic design. It solves a pain point that every scaling engineering team faces today.
Spotify Portal AiKA Modes cut Claude Code token costs by ninety percent by intercepting large file-reading and boilerplate-writing tasks and delegating them to cheaper worker models like Google Gemini 2.5 Flash. Using a specialized plugin called shunt, the system intercepts file reads exceeding 350 lines, summarizes them via an ephemeral background agent, and returns concise bullet points to the frontier model, keeping expensive tokens out of Claude's context window.
The promise of AI-assisted engineering has never been higher, but neither has the cost. In 2026, we are seeing teams spend thousands of dollars per developer every single month on API tokens alone. This is not because developers are asking complex architectural questions all day. It is because coding agents are incredibly chatty.
When an agent like Claude Code operates on a repository, it does not just think. It reads, writes, and executes. It might read five massive files to answer a question about a single helper method. It might generate hundreds of lines of predictable boilerplate that matches an existing pattern. Every single file read, and every line of generated code, represents tokens. Under standard configurations, all of those tokens pass through a premium frontier model.
This is a massive mismatch of capability and cost. You do not need a multi-billion-parameter frontier model to read a three-hundred-line Java class and list its dependencies. You do not need it to write basic unit test templates that follow a strict, pre-existing pattern. Yet, that is exactly what most teams do. The result is what we call token burn, where eighty percent of your AI budget is wasted on simple, repeatable input-output tasks, while only twenty percent goes toward actual reasoning.
At Algoramming, we help our clients design efficient AI implementations. We often see teams struggle with this exact issue when they try to scale developer tools. The tooling pays for itself, but only if you stop burning premium frontier tokens on work that does not need them. This is the exact challenge that Spotify set out to solve with its latest portal updates.
To understand how Spotify achieved these savings, we have to look at Spotify Portal. Portal is Spotify's commercial distribution of Backstage, the popular open source internal developer portal that centralizes software catalogs, documentation, and infrastructure templates. Earlier, Spotify introduced AiKA, its AI knowledge assistant built directly into Portal. You can read more about its initial release on Spotify's Backstage Blog.
AiKA acts as an organizational brain. Because it is embedded in the developer portal, it has direct access to the software catalog, TechDocs, and team ownership data. In 2026, Spotify expanded AiKA with a feature called Modes. A mode is a declarative, purpose-built agent designed for a specific workflow. Instead of a generic chatbot, a developer can invoke a specific mode, such as a code reviewer, platform support assistant, or incident responder.
These modes run on an ephemeral runtime, similar to AWS Lambda, but built specifically for AI agents. When a developer triggers a mode, Portal spins up the agent, executes the instructions, connects to the required Model Context Protocol, or MCP, tools, and shuts down. The developer does not need to manage API keys, host long-running servers, or configure complex infrastructure.
This declarative model management is incredibly powerful. Developers can write a simple configuration file specifying the agent's instructions, its model, and its parameters, and Portal handles the rest. This sets the stage for a highly optimized, multi-model routing system that can delegate tasks dynamically based on complexity and cost.
The magic that connects Claude Code to Spotify Portal AiKA Modes is a specialized plugin called shunt. Released as part of the spotify/portal-ai-plugins marketplace on GitHub, shunt acts as an intelligent traffic cop inside the developer's terminal.
When a developer starts an agentic coding session, shunt registers itself as a plugin within Claude Code. It utilizes PreToolUse hooks, which are entry points that allow plugins to inspect and intercept tool calls before they are executed by the LLM. When Claude Code decides to read a file, shunt steps in.
Instead of allowing Claude to read the raw file directly into its context window, shunt evaluates the request. It checks the size of the file. If the file is small, it lets the read pass through. But if the file exceeds a specific threshold, typically 350 lines of code, shunt blocks the raw read.
Instead of returning the file contents to Claude, shunt packages the request and forwards it to the Spotify Portal CLI. The CLI invokes a specific, cheaper AiKA mode running in the cloud. This mode processes the file, extracts the relevant details, and returns a high-level summary. Claude Code receives the summary instead of the massive raw file, preventing context window bloat and slashing input token costs.
The first of the two key modes configured by Spotify is the bulk-reader. This mode is designed specifically for scenarios where Claude Code would otherwise read multiple large files just to answer a single, simple question.
The bulk-reader mode is defined declaratively. It specifies Google Gemini 2.5 Flash as its worker model, though it can use any cost-effective model configured in the Portal instance, such as Anthropic Claude Haiku or GPT-4o-mini. The instructions for the bulk-reader are highly specific. It is told to act as a precise code analyst, read the provided files, and answer the developer's question using concise, structured bullet points. It is strictly instructed to omit greetings, introductory prose, or unnecessary explanations.
When shunt redirects a bulk read, the bulk-reader agent spins up on Spotify's ephemeral runtime. It reads the files, which are wrapped in XML tags to maintain clear boundaries. It extracts the exact patterns, dependencies, or methods that Claude is looking for. It then returns a structured list of bullet points, complete with file names, types, and line numbers.
Because the worker model handles the raw text, Claude never sees the hundreds or thousands of lines of code in those files. It only sees the bulleted summary. This keeps Claude's context clean and ensures that the developer is not paying frontier-model prices for basic file scanning.
The second declarative mode in this framework is the code-writer. If the bulk-reader handles input-heavy tasks, the code-writer is built to optimize output-heavy tasks.
When an AI agent writes code, it often generates a massive amount of output. If it is writing boilerplate, generating test files, or creating configuration scaffolding, that generated code must be transmitted back to the developer's machine. Under standard execution, the frontier model writes this code line-by-line into the active session. This means the generated code immediately enters the context window of the next turn.
The code-writer mode bypasses this entirely. It uses a cheap worker model to generate the required boilerplate based on a specification and a reference file. The instructions for the code-writer tell it to match existing patterns, conventions, naming styles, and formatting exactly. It is instructed to output only the code, with no explanations or markdown formatting, unless specifically requested.
Because this mode runs on Portal's ephemeral runtime, it can write the generated files directly to the developer's local disk via the Portal CLI's action registry. Claude Code does not have to consume the generated output in its own context window. It simply gets a notification that the file has been successfully written to disk. This keeps Claude's context window small, prevents output token accumulation, and ensures that you are not paying premium rates for predictable code generation.
This architecture is not just about having cheaper models available. It is about enforcing boundaries. If you simply ask Claude Code to use a cheaper model, it will often ignore you or forget the instruction after a few turns. In our experience, prompting alone is never enough to control costs at scale.
To solve this, Spotify's framework uses a three-layer routing enforcement pattern. This pattern can be applied to almost any agentic system, and it is something we recommend to our clients during tech partnership & consultation engagements. The three layers work in harmony to ensure that cheap tasks stay cheap, and expensive reasoning is saved for when it is truly needed.
First, we have the blocking interceptor. This is the hard boundary. In the shunt plugin, this is the PreToolUse hook that blocks any file read exceeding 350 lines. It does not ask Claude to be careful, it actively prevents Claude from accessing the file. This is the ultimate guardrail against accidental token burn.
Secondly, we have the cheap-worker script. This is the execution layer. It consists of highly optimized, low-cost models running on ephemeral runtimes. These workers are tuned for speed and efficiency, and they are restricted to specific, narrow tasks like file reading or boilerplate generation.
Finally, we have the redirect instructions. This is the guidance layer. It provides clear instructions to both the frontier model and the worker models, explaining how they should cooperate, what formats they should use, and where the boundaries of their responsibilities lie.
By combining these three layers, you create a system that is both incredibly robust and highly cost-effective. The frontier model is forced to delegate, the worker model handles the grunt work, and the developer gets the best of both worlds without having to constantly manage the routing themselves.
To prove the efficacy of this approach, Spotify engineer Dimitri Mazmanov tested the routing framework against a massive Java monorepo. Java repositories are notorious for being verbose, with deep package structures, extensive boilerplate, and large configuration files. This makes them the perfect testing ground for token optimization.
The test compared standard Claude Code execution against the optimized shunt routing across four common developer scenarios:
The results were staggering. In the bulk-reading scenarios, where the agent had to scan multiple large files to understand the codebase, the team measured a mean token saving of approximately ninety percent. Instead of consuming hundreds of thousands of premium tokens to read raw Java files, Claude Code consumed only a fraction of that, relying on the concise bullet points generated by the bulk-reader mode running on Gemini 2.5 Flash.
9 in 10 tokens previously used by Claude Code for file reading were eliminated, resulting in a mean cost reduction of 90% in monorepo tests.
While the savings on code generation were slightly harder to quantify due to the highly variable nature of creative coding, they were still substantial. By allowing the code-writer mode to write generated code directly to disk, the team prevented context window accumulation, ensuring that subsequent prompts in the session remained fast and inexpensive.
While a ninety percent reduction in token costs sounds incredible, we must look at the complete picture. Implementing an advanced multi-model routing system like this introduces new complexities and trade-offs that any engineering leader must carefully evaluate before making the transition.
First, let us talk about costs. Running this setup is not entirely free. While you save on premium Claude tokens, you are still paying for Google Gemini 2.5 Flash tokens. Fortunately, Gemini 2.5 Flash is priced at a fraction of the cost of Anthropic's frontier models, but it is still an active cost. if you are using Spotify Portal, you must account for the platform's licensing fees. If you choose to build a custom equivalent, you must budget for the engineering hours required to write and maintain the interceptors and worker runtimes.
Secondly, there are clear scenarios where this approach is not the right fit. If your team is working on a small repository, perhaps under ten thousand lines of code, the administrative overhead of setting up plugins and routing is simply not worth the effort. The savings will be negligible. cheaper worker models are not suitable for deep architectural reasoning, complex debugging, or mission-critical code changes. Delegated analysis does not always provide the line-level accurate information that Claude needs when editing highly sensitive files. If a worker's summary leaves out a subtle detail, the frontier model might make an incorrect assumption, leading to bugs.
Finally, we must flag what commonly goes wrong in practice. Spotify Portal has a strict thirty-second execution limit per call. If you attempt to process too many large files at once, the bulk-reader mode might time out, leaving Claude Code without any context at all. Managing these timeouts and ensuring fallback mechanisms are in place is critical to maintaining a smooth developer experience.
| Mode | Target Task | Default Model | Primary Benefit |
|---|---|---|---|
| bulk-reader | Reading large files or multiple files | Google Gemini 2.5 Flash | Reduces input token costs |
| code-writer | Generating boilerplate and unit tests | Google Gemini 2.5 Flash | Reduces output token costs |
The beauty of the three-layer routing pattern is that it is not locked into Spotify's ecosystem. While Spotify's Portal provides a fantastic out-of-the-box experience, any engineering team can replicate this architecture using open source tools. This is exactly the kind of custom integration work we handle for clients looking to optimize their maintenance & customer support systems or developer workflows.
To build a custom equivalent, you can write a local shell script or a lightweight CLI tool that wraps your preferred AI agent. Using a local tool like the Model Context Protocol, you can register custom tools that perform the heavy lifting.
For example, you can create a custom CLI tool called bulk-read. This tool takes a list of file paths, reads them locally, sends them to a cheaper API endpoint like Gemini 2.5 Flash with a custom summarization prompt, and prints the concise bullet points. You then instruct your primary agent, through its system prompt, to always use the bulk-read tool instead of the default file-reading tool whenever it needs to inspect files larger than a certain size.
This approach allows you to achieve similar savings without adopting a full internal developer portal. It is highly customizable, and you can easily swap out the worker models as newer, cheaper options become available. You can read more about running local agentic workflows on our blog post about Always-On Agentic Computing on M6 Mac Mini.
For enterprise engineering organizations, the implications of Spotify's breakthrough extend far beyond simple cost savings. It represents a fundamental shift in how we design and deploy AI agents at scale.
By decoupling reasoning from input-output operations, teams can build far more ambitious agentic workflows. Instead of restricting agent usage to prevent runaway API bills, you can encourage developers to use agents for continuous repository monitoring, automated code reviews, and real-time documentation updates. The cost barrier is effectively removed.
At Algoramming, we focus on building custom agent workflows as a core business differentiator. In our project case study on Building an AI-Native CMS That Writes, Illustrates, and Publishes Its Own SEO Content, we applied similar multi-model routing principles to manage high-volume content generation without breaking the bank. By routing heavy data processing to specialized, lower-cost models and saving frontier models for creative synthesis, we achieved exceptional quality at a fraction of the standard operating cost.
Whether you are building internal developer tools or shipping consumer-facing products, optimizing your token efficiency is key to achieving long-term viability. Spotify's AiKA Modes and the shunt pattern provide a clear, proven blueprint for how to do this successfully in 2026.
Key takeaways
- Decouple I/O from Reasoning: Eighty percent of coding agent activity is simple input-output, which should be routed to cheaper models.
- Enforce with Guardrails: Use hard boundaries, like blocking reads over 350 lines, rather than relying solely on prompt instructions.
- declarative Agent runtimes: Spotify Portal's AiKA Modes run on ephemeral, serverless runtimes that make agent deployment simple and secure.
- Substantial Cost Reductions: Monorepo testing demonstrated a mean token saving of ninety percent on bulk file reads.
Spotify Portal AiKA Modes are declarative, purpose-built agents designed for specific workflows within Spotify Portal, a commercial distribution of Backstage. They run on ephemeral, cloud-based runtimes, allowing developers to define specialized instructions, models, and tools without managing separate infrastructure.
They reduce costs by intercepting resource-intensive tasks, such as bulk file reading and boilerplate generation, and routing them to cheaper worker models. This prevents massive raw text files from entering the context window of expensive frontier models like Claude, saving up to ninety percent on token usage.
The shunt plugin is a Claude Code extension that intercepts file-reading tool calls using PreToolUse hooks. When Claude attempts to read files exceeding a certain size, shunt blocks the direct read and delegates the task to a cheaper AiKA mode running in the cloud.
By default, Spotify's public modes use Google Gemini 2.5 Flash as the primary cheap worker. It provides a massive context window, fast processing speeds, and extremely low token pricing, making it perfect for high-volume input and output tasks that do not require deep reasoning.
Yes, the AiKA framework is model-agnostic. You can configure any model supported by your Portal instance, including Anthropic Claude Haiku, OpenAI GPT-4o-mini, or even locally hosted models, depending on your team's specific compliance, cost, and latency requirements.
The 350-line threshold is the default limit configured in the shunt plugin. Any file read request exceeding this limit is blocked and redirected to the bulk-reader mode. Smaller files are allowed to pass through directly, ensuring Claude retains precise line-level context for minor edits.
You should avoid this delegation on small repositories where token costs are negligible, or during deep architectural debugging. Cheaper worker models can miss subtle context in their summaries, which might lead the frontier model to make incorrect assumptions about complex codebase behavior.
The code-writer mode generates boilerplate or test files and writes them directly to the developer's local disk via the Portal CLI actions registry. Because the generated code is written directly to disk, Claude does not need to load the output into its own context window, keeping the session fast.
No, the three-layer routing pattern is highly generalizable. You can implement a similar architecture using custom local scripts, open source Model Context Protocol tools, and standard API routing to achieve comparable token savings on any agentic platform.
Navigating the rapidly evolving landscape of AI-assisted development requires a careful balance of innovation and cost control. As Spotify has demonstrated with its Portal AiKA Modes, the key to scaling these tools successfully lies in intelligent, multi-model routing and strict enforcement of operational boundaries.
At Algoramming, we specialize in helping organizations design, build, and optimize custom software solutions that leverage the latest advancements in AI and agentic computing. Whether you are looking to integrate advanced developer tools, build custom internal portals, or optimize your existing cloud infrastructure, we are here to help.
If you are planning a project like this and want to discuss how to optimize your architecture for maximum efficiency and performance, we invite you to explore our custom software development services. Let us talk through your goals and design a solution that fits your business.
01 · RelatedVeracode's 2026 report shows 44% of AI-generated code has security flaws. Learn how our human-in-the-loop agency secures your custom builds against these rising risks.
Read post
02 · RelatedDiscover the critical lessons from Vercel's $1 Million Sandbox Challenge on HackerOne. Learn how to secure autonomous AI agents using microVMs, egress firewalls, and the Run SDK.
Read post
03 · RelatedLearn how to deploy Qwen 3.8-27B locally for private, offline AI coding agents. This guide covers hardware sizing, Ollama and SGLang setups, and sandbox security.
Read postWe will reply in plain English within one business day, NDA on request. Discovery call is free.
We design and engineer software, mobile, and web products end-to-end. Send the brief, we will reply within one business day.
Start a projectWe send a short email whenever we publish a new field note or ship a studio update. No fixed schedule, no filler.
Unsubscribe in one click. We never share your address.