Modern software engineering is currently locked in a battle with the context window. Developers using high-end AI coding assistants often find themselves paying a steep token tax simply because the agent needs to read a thousand-line boilerplate file to understand a single function call. This inefficiency creates a tension between the desire for deep codebase awareness and the practical reality of escalating API costs and latency. The industry has long sought a way to treat LLMs not as monolithic brains, but as a tiered workforce where expensive frontier models only handle the hardest problems.

The Architecture of AiKA Modes and the Shunt Plugin

Spotify is addressing this inefficiency through Portal, a system centered around a declarative agent structure called AiKA Modes. These modes operate within an ephemeral runtime, conceptually similar to AWS Lambda, allowing developers to define specific instructions, model selection, and temperature parameters without managing underlying infrastructure or API keys. By integrating the Model Context Protocol (MCP), Portal enables these agents to connect to a variety of tools and be invoked via a CLI or API with granular public and private visibility settings.

To specifically optimize Claude Code, Spotify developed a plugin called shunt. This plugin hooks into the PreToolUse event of Claude Code, acting as a traffic controller that intercepts requests before they reach the expensive frontier model. When a specific condition is met, shunt diverts the task to a lower-cost worker model, which by default is Gemini 2.5 Flash, though Portal allows this to be swapped for any other configured model.

The primary trigger for this diversion is file size. The shunt plugin employs a check-file-size hook that monitors all read calls. If a file exceeds a predefined line threshold, the plugin blocks the direct read and instead triggers a specialized skill called /bulk-reader. While the default threshold is set to 350 lines, developers can override this via environment variables or a configuration file located at `.claude/settings.json`:

{

"env": {

"SHUNT_MIN_LINES": "500"

}

}

The Trade-off Between Token Efficiency and Logical Precision

This routing mechanism operates through two primary delegation modes: bulk-reader and code-writer. The bulk-reader mode processes multiple large files and returns a structured summary in bullet points, wrapping each file in XML tags to maintain clear boundaries. Because only the summary enters Claude's context rather than the raw source code, the token footprint is drastically reduced. Similarly, the code-writer mode analyzes patterns in reference files to generate test files or configuration scaffolding. Crucially, it writes this code directly to the disk without using markdown fences, removing the need for Claude to read and parse the generated output back into its own context.

In benchmarks conducted on a Java monorepo across four different scenarios, this approach yielded an average token reduction of approximately 90% compared to direct file reading. However, this efficiency comes with a distinct cognitive cost. During testing, it became evident that while worker models are excellent at identifying surface-level patterns, they struggle with deep logical nuances. In one instance, the worker model missed a subtle thread-safety bug during a test generation task—a bug that Claude identified immediately when given the same raw context.

Latency is another critical factor. Because the request must travel from Claude Code through the Portal backend to the worker model and back, each delegated call typically takes between 10 and 30 seconds. Portal imposes a strict 30-second timeout per call, meaning exceptionally large generation tasks must be broken into smaller chunks. This latency explains why the line threshold is necessary; delegating small files would introduce more delay than the token savings justify.

To integrate these tools, developers must install the necessary plugins from the Spotify marketplace:

bash
claude plugin marketplace add spotify/portal-ai-plugins
claude plugin install portal@portal
claude plugin install shunt@portal

Once installed, running the `/portal:setup` command in a new session completes the authentication. Users can then utilize the default bulk-reader and code-writer modes or fork them within Portal to customize instructions and model selection for their specific project needs.

Despite the power of this routing, there are hard boundaries to what can be delegated. Because worker model summaries do not provide reliable line numbers, any actual code editing must be performed by Claude. The shunt hook is specifically designed to allow target reads that include an offset and limit, ensuring the frontier model can still access the exact slice of code it needs to modify.

This creates a clear operational divide: simple I/O and pattern-based generation are routed to low-cost workers, while debugging, architectural decisions, and safety-critical analysis remain the exclusive domain of the frontier model.

This shift toward tiered model orchestration marks the end of the single-model era and the beginning of the AI agent swarm.