Brifing

Spotify Portal Cuts Claude Code Token Usage by 90%

New solution optimizes AI coding costs with smart routing.

Spotify Engineering2 min

1AI Coding Cost Crisis

By 2028, AI coding costs are projected to exceed developer salaries. Engineering teams currently spend $200-500 monthly per developer on tokens, with some exceeding $2000. The core issue is using overqualified models for simple I/O operations. Spotify Portal's new solution introduces a dual-mode approach to address this wasteful token consumption and rising costs.

2How Modes Work

Portal's AiKA modes provide ephemeral declarative agents. Users can define instructions and select models to create modes. These operate on a Lambda-like runtime specifically for agents. Each mode has its own instructions, model, and parameters. Modes are callable via Portal CLI or API and can be shared company-wide. The system requires no long-running server management.

3Bulk-Reader Mode

The Bulk-Reader mode handles large file reading tasks instead of Claude. It uses cheaper models like Gemini 2.5 Flash to optimize file operations. The mode provides precise answers with structured bullets, eliminating unnecessary explanations. By preventing Claude from reading large files for simple queries, it achieves significant token savings.

4Code-Writer Mode

Code-Writer generates predictable outputs like test files and scaffolding. It strictly follows patterns and styles from reference files, outputting only code without explanations. This mode reduces Claude's workload for boilerplate generation. Particularly in large projects, it saves considerable time and tokens when creating repetitive code blocks.

5Shunt Plugin

The shunt plugin automatically routes Claude Code's tool usage. It offers two PreToolUse hooks: check-file-size and check-bash-read. The former blocks large file reads and redirects to bulk-reader mode. The latter catches bash commands on large files. The SHUNT_MIN_LINES environment variable configures the threshold, centralizing delegation rules.

6Bash Script Integration

The system completes with two bash scripts: bulk-read and code-write. bulk-read wraps files in XML tags for the bulk-reader mode. code-write sends specs and references to the code-writer mode. The scripts handle request building, error processing, and token usage reporting. Claude never sees generated code, preventing context consumption.

7Mode Resolution System

Portal's mode resolution system follows user priority. Modes are called by name, checking user-specific modes first, then team modes, then public ones. Forking public modes for customization is supported, with customized versions automatically taking precedence. This creates a flexible yet centralized mode management approach.

8Cost Benefits

This system can reduce token costs by up to 90%. By using cheaper models for simple I/O, it reserves Claude for complex problems only. Ephemeral invocations mean nothing is stored server-side. For large codebases, monthly savings can reach thousands of dollars. This solution proves particularly valuable for large engineering teams.

Original article: Spotify Engineering — Spotify Portal ile AI Kodlama Maliyetlerini %90 Azaltmak