RC RANDOM CHAOS

Context is the whole bill

A Claude Code plugin routes bulk file reads to a cheaper worker model, cutting token usage by around 90% on a Java monorepo benchmark.

· 4 min read
Context is the whole bill

Routing an AI coding agent’s bulk file reads to Gemini 2.5 Flash cut the tokens Claude would otherwise spend by around 90% on average, measured on a Java monorepo benchmark. The author’s reasoning: most of what a coding agent does for them is file I/O rather than thinking, like reading five files to answer a question about one method, or generating a test file that copies the pattern of the twenty next to it. A frontier model does that work at frontier prices, and the seat license is fixed while the tokens scale with how much the agent reads and writes. That is where the bill grows.

The post’s framing: a quarter of engineering leaders already spend $200 to $500 per developer per month on tokens, some well past $2,000, and it projects AI coding costs to pass the average developer’s salary by 2028.

Two modes

The fix runs on AiKA Modes in Portal by Spotify. A mode is a declarative agent on an ephemeral runtime, closer to a Lambda for agents than a running server. You give it instructions, a model, parameters like temperature, and MCP tools, and Portal handles execution with no infra, API keys, or long-running processes to manage. Both modes in this setup use Gemini 2.5 Flash, though the model field takes any model configured in your Portal instance.

bulk-reader reads the provided files and returns structured bullets and nothing else. code-writer generates a file from a spec and a reference file, matching the reference’s naming and style, and outputs only the code. That last instruction matters: without it the worker wraps output in markdown fences and explanation that Claude then spends tokens parsing back out.

The plugin and its three layers

The first version was a block of routing rules in CLAUDE.md. Those were advisory, so Claude could ignore them, and every project needed its own copy. The working version is a Claude Code plugin called shunt, built in three layers.

Hooks run first. Two PreToolUse hooks fire before tool calls. check-file-size blocks any Read of a file over a configurable line count, default 350, and points Claude at the /bulk-reader skill. check-bash-read catches cat, head, tail, less, and more against large files. Targeted reads pass through, including piped commands like cat file | grep and reads with offset and limit, because Claude already knows the section it wants. The threshold is set with the SHUNT_MIN_LINES environment variable.

Scripts do the delegation. Two bash wrappers call the Portal CLI. bulk-read wraps each file in XML tags for clear boundaries and sends them with the question. code-write sends the spec and reference, strips the markdown fences, and can write straight to disk, so the generated code never enters Claude’s context. The reference file is required; without one the worker produces code that fits nothing in the project.

Skills come last. They are markdown files that give Claude the exact invocation syntax, and the hook’s block message points to them. If Claude never reads the skill, the hook still blocks the expensive read, so the system falls back to blocking rather than breaking.

The detail worth copying: every delegation is one shot and stored nowhere server-side. Resending the same files on a follow-up question costs nothing in Claude’s window, because the corpus goes to the worker and never lands in Claude’s context. Modes resolve by name case-insensitively, preferring your own, then your team’s, then public ones, so you can fork the public bulk-reader, change the prompt or the worker model, and your version wins with no config change.

Where delegation stops

You can’t delegate editing. The worker’s summaries don’t carry reliable line numbers, so when Claude needs to make a change it reads the specific section itself. The targeted offset and limit reads the hooks allow exist for exactly that.

You can’t delegate reasoning. In testing the worker found surface-level patterns but missed a thread-safety bug that Claude caught in seconds once it had the right context. The routing explicitly excludes debugging, architectural decisions, and safety-critical code.

Latency sets a floor. Each delegation is a round-trip from Claude Code to Portal to the worker and back, usually 10 to 30 seconds, and Portal caps a single invocation at 30 seconds, so large generations have to be split into smaller calls. Below the line threshold the round-trip costs more than it saves, which is why the threshold exists.

Setup is three commands against the spotify/portal-ai-plugins marketplace: add the marketplace, install portal@portal for the CLI, and install shunt@portal for the routing. Run /portal:setup in a new session to authenticate against your Portal instance, then ask a question that spans several files. The bulk-reader and code-writer modes are already public, so there is nothing to create first.


Contains a referral link.

Share

Keep Reading

Latest on the Wire

Full wire →

New signal daily · RSS

Stay in the loop

New writing delivered when it's ready. No schedule, no spam.