Most of what an AI coding agent does for me isn't thinking. It's I/O. The post Portal by Spotify cut my Claude Code token usage by 90% appeared first on Spotify Engineering.
Offloading bulk file reads and boilerplate generation to cheap worker models cut Claude Code token consumption by 90%. 👇
Most of what an AI coding agent does isn't heavy thinking—it's raw I/O. Frontier models burn thousands of expensive tokens reading hundreds of lines of code just to answer a simple question, or generating repetitive test boilerplate. Engineering teams regularly spend $200 to over $2,000 per developer every month feeding overqualified models basic grunt work.
An engineer at Spotify built `shunt`, a Claude Code plugin that intercepts heavy file reads and boilerplate generation, routing those tasks through Portal by Spotify to cheap worker models like Gemini 2.5 Flash.
The mechanism uses a three-layer pipeline:
Layer 1: PreToolUse Hooks. Every time Claude attempts a tool call, `check-file-size` and `check-bash-read` hooks inspect the request. If a file exceeds a threshold (default: 350 lines), the hook blocks direct execution and forces delegation. Targeted reads with line offsets pass through uninterrupted.
Layer 2: Execution Scripts. Custom bash scripts wrap Portal CLI actions. The `bulk-read` script packs files into XML boundaries and routes them to a worker model, returning a concise summary. The `code-write` script sends a specification and reference file to the worker, stripping prose markdown and writing output directly to disk—so Claude never consumes tokens for the generated code.
Layer 3: Skills Redirects. Markdown skill files supply Claude with explicit invocation syntax. When a hook blocks an expensive call, the block message points Claude directly to the skill instructions to execute the redirect.
The workflow explicitly keeps complex reasoning with Claude. cheap worker models missed subtle thread-safety bugs in testing and struggled with line-number precision, so architectural edits and debugging remain strictly in Claude's hands.
In benchmarks across a Java monorepo, delegating bulk reads reduced Claude's token usage by 90%. Boilerplate generation completely bypassed Claude's context window, with delegated round-trips taking between 10 and 30 seconds.
NayaRead shows a summary and links to the original article. The full article is hosted on engineering.atspotify.com.