deniz.in

Markets

Weather

Loading weather

· via Hacker News – Front Page (hnrss.org)

Spotify's Portal routes Claude Code I/O to cheaper models and cuts token usage by 90%

A Spotify Engineering post explains how delegating Claude Code's file reads and boilerplate generation to a cheaper worker model via Portal's AiKA Modes cut bulk-read token usage by about 90%.

Spotify's Portal routes Claude Code I/O to cheaper models and cuts token usage by 90%

A Spotify Engineering post, which surfaced on the Hacker News front page, describes a setup that cut Claude Code token consumption by roughly 90% by treating most agent activity as what it largely is: input and output rather than reasoning. File reads and boilerplate generation were delegated to a cheaper worker model running on Portal, Spotify's agent platform, leaving the frontier model for work that actually needs judgment.

The cost problem

The author's starting observation is that an agent routinely reads five files to answer a question about one method, or writes a test file that mirrors the twenty test files beside it. Tasks like these consume thousands of tokens while demanding almost no reasoning, yet by default all of it runs on an expensive frontier model.

The post frames this as a fast-scaling budget problem, citing figures that a quarter of engineering leaders already spend $200 to $500 per developer per month on tokens, with some well past $2,000, alongside projections that AI coding costs could exceed the average developer salary by 2028.

Two declarative modes on Portal

The mechanism is AiKA Modes, a Portal feature where a mode is a declarative agent running on an ephemeral, serverless-style runtime. You define the instructions, pick a model, set values such as temperature and attach MCP tools; Portal handles infrastructure, keys and process lifecycle. Modes are callable from the Portal CLI or API, can be private or shared across a company, and Portal resolves mode names case-insensitively, preferring your own mode, then your team's, then public ones.

Two modes were created. bulk-reader takes a set of files and a question and answers in structured bullets, with instructions that forbid greetings, preambles and prose and require every bullet to lead with an exact name, type or line number. code-writer generates a file from a spec and a reference file, matching the reference's conventions exactly and outputting nothing but code. The examples run Gemini 2.5 Flash as the worker, though the model field accepts anything configured in the Portal instance.

Enforcing the route with the shunt plugin

An earlier attempt put routing rules in CLAUDE.md, but those rules were advisory, so Claude could simply ignore them, and every project needed its own copy. The current version is a Claude Code plugin called shunt, layered in three parts.

PreToolUse hooks intercept tool calls before they run. One checks every Read and blocks files above a configurable line threshold, 350 by default, adjustable through the SHUNT_MIN_LINES environment variable, redirecting Claude to the bulk-reader skill. Another catches cat, head, tail, less and more against large files while letting piped, filtered commands through, since those are targeted reads.

Wrapper scripts do the delegation. bulk-read wraps each file in XML tags and sends them with a question to the bulk-reader mode; each call is one-shot and ephemeral, and because the corpus goes to the worker model rather than into Claude's context, re-sending the same files for a follow-up is effectively free. code-write takes a spec plus a required reference file, strips markdown fences from the response and can write straight to disk, so Claude never sees the generated code.

Skill files tell Claude when and how to call the scripts, and the layering degrades gracefully: even if the skill goes unread, the hook still blocks the expensive read.

Results and limits

Benchmarked against a Java monorepo across four scenarios, mean savings on bulk reads landed around 90%. The code-writing case is harder to measure in tokens, because the baseline charges Claude for reading the references and for generating the output as expensive tokens.

The post is candid about what cannot be delegated. Editing stays with Claude, since worker summaries lack reliable line numbers, so targeted reads with offset and limit still pass through. Reasoning also stays with Claude: the worker model noticed surface-level patterns but missed a subtle thread-safety bug that Claude caught quickly once given the right context, so debugging, architectural decisions and safety-critical code are excluded from routing. Latency is the remaining tax, since each delegation is a network round trip of 10 to 30 seconds, Portal caps a single invocation at 30 seconds, and very large generations must be split into smaller calls, which makes delegation counterproductive for small files and explains the line threshold.

Why it matters

Token spend is becoming a line item that engineering organizations actually budget for, and this is one of the more concrete demonstrations of the standard remedy: push mechanical I/O to a cheap model and reserve frontier models for judgment. The specific stack is Spotify's, but the shape of the solution, intercepting tool calls with hooks, delegating to a cheaper endpoint and keeping edits plus debugging local, transfers to any Claude Code setup. Documenting the failure modes alongside the headline figure also makes the claim far more credible than a benchmark in isolation, though readers should note the numbers come from one author's tests on a single monorepo rather than an independent audit.

  • #spotify
  • #claude-code
  • #ai-agents
  • #developer-tools
  • #token-costs

Related posts