Portal by Spotify cut my Claude Code token usage by 90%
Dimitri Mazmanov ยท article ยท 2026-09-03 source โ Reader ๐ฅ๏ธ
Agent HarnessAI Unit EconomicsClaude CodeContext EngineeringDelegated Editing & Document CorruptionHooksModel RoutingToken Efficiency
Because most of what a coding agent does is I/O rather than reasoning, routing that I/O-bound work (bulk file reads, pattern-following boilerplate generation) to a cheap worker model โ and enforcing that routing deterministically via harness-level hooks rather than relying on advisory instructions the model can ignore โ cuts Claude Code's token spend by around 90% on the delegated work while reserving the frontier model for editing, debugging, and anything safety-critical.
practical ยท mixed โ A personal engineering report structured as a how-to: it opens with a narrative problem statement, argues a general thesis (I/O work should be routed off the frontier model), documents a concrete mechanism (Portal AiKA Modes + a three-layer Claude Code plugin called shunt), cites benchmark evidence, and closes with install instructions. The propositions are ultimately in service of 'you should route I/O work to a cheap worker model and enforce it with hooks,' not a claim about what is true in general.
Structure
| Part | Role |
|---|---|
| Opening problem framing: 'most of what an AI coding agent does isn't thinking, it's I/O,' plus industry cost trend data (Gartner 2028 projection, $200-2000/dev/month survey figures). | motivation and stakes |
| Two modes defined: bulk-reader (read + answer concisely) and code-writer (generate code matching existing patterns, output-only), both declarative Portal AiKA Modes running on Gemini 2.5 Flash. | solution definition |
| Routing architecture: Layer 1 (PreToolUse hooks that block large reads/cats), Layer 2 (bash scripts wrapping the Portal CLI), Layer 3 (skill files telling Claude when/how to call the scripts) โ replacing an earlier, advisory CLAUDE.md-based version. | mechanism / evidence for how enforcement actually works |
| Benchmark section: four scenarios on a Java monorepo, ~90% mean token savings on bulk-read; code-write savings harder to quantify but qualitatively described. | evidence |
| 'What doesn't work': can't delegate editing (no reliable line numbers), can't delegate reasoning (missed a thread-safety bug), latency adds up (10-30s round trip, 30s cap). | scope boundary / qualification |
| Generalization: modes are reusable, shareable, composable, and decouple the routing decision (plugin) from the response (mode) โ reframed as 'model routing turned from a systems engineering problem into a configuration problem.' | conclusion / broader claim |
| Try-it-yourself install steps (marketplace plugin install, /portal:setup). | call to action |
Key terms
- I/O
Coding-agent work whose token cost is dominated by moving and restating text through the model rather than by any decision the model makes โ reading files to answer a question, generating boilerplate that follows an existing pattern, updating docs. The category the author claims is safe to hand to a cheaper model. - Mode (AiKA Mode)
A declarative agent definition in Portal by Spotify โ instructions, model, parameters like temperature, and attached MCP tools โ that runs on an ephemeral, serverless-like runtime and is callable by name from the Portal CLI or API, with no infrastructure or API-key management. - Worker model
The cheaper model (Gemini 2.5 Flash in the author's examples, but configurable) that a Mode actually runs on, doing the delegated I/O work in place of the orchestrating frontier model (Claude). - shunt
The Claude Code plugin (hooks + scripts + skills) that enforces routing of I/O-heavy work to Portal modes, replacing an earlier CLAUDE.md-based advisory version. - Delegation Delegated Editing & Document Corruption
Routing an entire sub-task's execution (reading a set of files and answering about them; generating a file from a spec and reference) to the worker model such that the corpus or generated code never enters Claude's own context โ Claude sees only the compact result.
Propositions
- explicitMost of what an AI coding agent does for the author isn't thinking โ it's I/O: reading multiple files to answer a question about one method, generating boilerplate that follows an existing pattern, updating docs.conf: high
- explicitAI coding costs are trending toward exceeding the average developer's salary by 2028 (per a cited Gartner prediction), and a quarter of engineering leaders already spend $200-500 per developer per month on tokens, with some past $2,000.conf: high
- explicitA Portal 'Mode' is a declarative agent โ instructions, model choice, parameters like temperature, attached MCP tools โ that runs on an ephemeral runtime requiring no infrastructure, API keys, or long-running servers, and is callable by name from the Portal CLI/API as public or private.conf: high
- explicitDelegating I/O-heavy work (bulk file reads via the bulk-reader mode) to a cheaper worker model (Gemini 2.5 Flash in the author's setup) cut token usage by a mean of around 90% in benchmark testing.conf: highextendsThe Pulse: a new trend, smart model routing ยท p2 โ Reports a much higher (~90%) savings figure than the 20-30% vendor-claimed general routing savings cited there, but for a narrower, precisely-defined delegation category (I/O-heavy bulk reads and boilerplate) rather than general-purpose per-request model routing.
- explicitAn earlier, advisory version of the routing logic โ a block of rules in CLAUDE.md instructing Claude to self-route to Portal โ worked only partially: Claude could ignore the rules, and every project needed its own copy of them.conf: highsupportsAlex Wang's Post ยท p7 โ A concrete instance of the general claim: an advisory routing rule in CLAUDE.md proved ignorable, which is what motivated moving enforcement into a hook.
- explicitPreToolUse hooks that deterministically block Read calls above a configurable line threshold (default 350) and equivalent bash reads (cat/head/tail/less/more on large files) enforce delegation to the bulk-reader mode regardless of whether Claude reads or follows written routing instructions.conf: highsupportsWhen Guardrails Go Wrong ยท p7 โ Recounts, first-hand, exactly the failure mode that proposition names: an advisory, harness/prompt-level routing policy (in CLAUDE.md) that Claude could simply ignore, which is why it was replaced with an enforced PreToolUse hook.
- explicitEditing cannot be delegated: the worker model's summaries don't include reliable line numbers, so if Claude needs to make an edit based on the analysis it still has to read the specific section directly.conf: high
- explicitReasoning cannot be delegated: the worker model found only surface-level patterns and missed a subtle thread-safety bug that Claude caught in seconds once given the right context, so debugging, architectural decisions, and safety-critical code are explicitly excluded from the routing.conf: highrefinesGitHub - Doorman11991/smallcode: AI coding agent optimized for small LLMs. 87% benchmark with 4B-active model. ยท p15 โ Cuts against the optimistic edge of that claim (that most agentic 'reasoning' in coding is bounded navigation/format/decomposition doable by small models): here the worker model was given a genuine reasoning task without smallcode's heavier scaffolding and missed a subtle thread-safety bug, which is why the piece explicitly excludes reasoning and debugging from delegation rather than trying to scaffold a small model into handling them.
- explicitEach delegation is a network round trip (Claude Code to the Portal backend to the worker model and back) typically taking 10-30 seconds, with Portal capping a single invocation at 30 seconds, making delegation counterproductive for reads below the configured line threshold.conf: high
- explicitDelegated reads are cheap to repeat because each invocation is ephemeral and stateless (nothing stored server-side) and the underlying file corpus goes to the worker model and never enters Claude's own context โ so re-sending the same files on a follow-up question doesn't cost against Claude's context budget.conf: high
- explicitThe value of AiKA modes lies in the router/harness layer (mode definitions plus hooks, scripts, and skills), not in the specific worker model chosen โ modes are reusable across projects, shareable across a company, composable into new roles (doc-writer, reviewer, translator), and decouple the routing decision (the plugin's job) from the response (the mode's job).conf: highsupportsGitHub - musistudio/claude-code-router: Use Claude Code as the foundation for coding infrastructure, allowing you to decide how to interact with the model while enjoying updates from Anthropic. ยท p11 โ Another instance of the 'harness, not model, is the durable value' thesis: Portal's mode/hook/script/skill stack is reusable and shareable while the worker model itself is an interchangeable parameter ('pick whichever works for you').
- implicitThe router/harness layer, not the choice of worker model, is what makes the pattern reusable, shareable, and composable across projects and teams.conf: medium
- implicitThe frontier model doing routine I/O work is 'wildly overqualified' for that work โ there is a large capability-cost mismatch when the most expensive model in the stack performs routine reads and boilerplate generation.conf: mediumsupportsThe Pulse: a new trend, smart model routing ยท p8 โ Independently arrives at the same diagnosis โ that frontier models are routinely used on work that doesn't require them โ from one practitioner's own Claude Code usage rather than from an industry-wide survey.
- implicitThe token/cost problem in AI coding agents is primarily a task-classification and enforcement problem (correctly deciding what's I/O vs. reasoning, and making that decision stick against a model that can ignore instructions) rather than a raw model-capability or model-cost problem.conf: medium
- explicitModes resolved by name with 'own > team > public' precedence let an individual or team override a shared default (e.g. forking bulk-reader) without any central coordination or configuration change on the caller's side.conf: high
Arguments
Coding-agent token spend can be cut by roughly 90% on I/O-heavy tasks without sacrificing output quality where it matters. strength: medium
Explicit premises:
- Reading files to answer a question and generating pattern-following boilerplate are I/O tasks, not reasoning tasks.
- A cheaper worker model (Gemini 2.5 Flash) given a tightly scoped, output-only prompt can perform these I/O tasks adequately.
- Benchmarking across four scenarios on a Java monorepo showed a mean ~90% token savings on the bulk-read scenario.
Implicit premises:
- The four benchmark scenarios and the one Java monorepo generalize to other codebases and task mixes.
- The worker model's output being 'adequate' was judged by the author's own inspection rather than an independent or blinded evaluation.
Inferences:
- Teams with high per-seat token spend and an I/O-heavy mix of Claude Code usage should see comparable savings from a similar routing setup โ though the piece never establishes what fraction of a typical coding session is genuinely I/O-bound versus reasoning-bound, so the achievable session-level (not per-delegated-task) savings remain unestablished.
Routing decisions must be enforced by the harness (deterministic hooks), not left to the model to self-apply from written instructions. strength: high
Explicit premises:
- The CLAUDE.md-based version of the routing rules was advisory: Claude could ignore them.
- Every project needed its own copy of the CLAUDE.md rules, with no central update path.
Implicit premises:
- A model instructed to prefer a cheaper path, without being directly constrained from taking the expensive path, will not reliably follow that instruction across many turns and contexts.
Inferences:
- Any cost-control policy for an agent that depends on the model reading and voluntarily following prose instructions is fragile by default and should be treated as a stepping stone toward a hook-enforced implementation, not a stable end state.
Narratives
- The opening vignette: "Reading five files to answer a question about one method. Generating a test file that follows the exact same pattern as the twenty test files next to it. Updating docs after a meeting."
โ Dramatizes the I/O-versus-reasoning distinction before any argument is stated, so the reader recognizes the pattern in their own agent usage before being told the fix โ carries proposition 1 without arguing for it abstractly. - The evolution from a block of advisory routing rules in CLAUDE.md (which Claude could ignore and which had to be copied into every project) to the shunt plugin's PreToolUse hooks that block the expensive call outright.
โ Narratively demonstrates the 'guardrails must be enforced, not merely advised' argument through the author's own iteration rather than stating it as an abstract design principle. - The worker model missed a subtle thread-safety bug that Claude then spotted in seconds once given the right context.
โ A concrete before/after case that grounds the 'you can't delegate reasoning' boundary claim in a specific failure rather than an assertion.
Questions addressed
- โ
How can AI coding-agent token/cost spend be reduced without giving up frontier-model quality where it matters?
Route I/O-heavy work (bulk reads, pattern-following boilerplate) to a cheap worker model via hook-enforced delegation; keep the frontier model for editing, debugging, and safety-critical or architectural work. - โ
What kinds of coding-agent work are safe to delegate to a cheaper model, and what kinds aren't?
Safe: understanding-oriented bulk reads and boilerplate generation from an existing pattern. Unsafe: edits that require precise locations, debugging, architectural decisions, and safety-critical code. - โ
How do you make a token-saving routing policy actually stick, given that a model can choose to ignore written instructions?
Enforce it at the harness level with PreToolUse hooks that block the expensive tool call outright, rather than relying on the model reading and following a policy document. - โญ Once a task has been delegated and the worker model returns a confident-looking summary, how is that output verified as actually correct, beyond the one anecdote where a bug happened to be caught?
Gaps
- incompleteThe ~90% savings figure is measured across only four scenarios on a single Java monorepo, run and interpreted by the author, with no description of how the scenarios were selected, no independent replication, and no confidence interval โ a self-benchmark on one codebase presented as a general result.
Read next: Compare against vendor-claimed general model-routing savings of roughly 20-30% (extract-pragmatic-engineer-pulse-smart-model-routing#p2) to see whether Portal's much higher figure is a genuine property of narrowly-scoped I/O delegation or an artifact of scenario selection and codebase choice. - incompleteThere is no account of how 'good enough' worker-model output is verified on an ongoing basis. The piece surfaces exactly one failure (a missed thread-safety bug), caught only because Claude was independently asked about the same code โ it doesn't describe any systematic check for cases where a confident-looking bullet summary is subtly wrong and nobody re-reads the source to catch it.
Read next: extract-pragmatic-engineer-pulse-smart-model-routing#g2 raises exactly this evaluation gap for routing systems generally โ read together for the recurring 'good enough is asserted, never verified' critique. - uninformedNo systematic latency or throughput accounting beyond a rough 10-30 second range and a 30-second hard cap; no data on how often the line-count threshold forces marginal-size reads through the expensive path anyway, and no measurement of cumulative added wall-clock time across a full real session.
Read next: extract-cloudflare-code-mode-mcp-server#g4 flags the identical missing latency/wall-clock analysis for a different token-saving pattern (Code Mode) โ this looks like a recurring blind spot across token-optimization write-ups worth reading together. - incompleteThe article frames the setup as requiring 'zero code,' but that's zero code once an organization has already stood up a Portal (AiKA) instance with modes, plugins, and marketplace access configured โ it doesn't address what the equivalent hooks/scripts/skills layering costs to build from scratch for the (much larger) population of Claude Code users without an existing Portal-shaped platform.
Read next: Read against platform-engineering and agent-tool-management material on what it actually takes to stand up a shared internal AI platform, to price the 'zero code' claim against the platform-build cost it presupposes.
Closes gaps elsewhere
- How the 4 New AI Models Change How You Work ยท g3 โ Supplies the concrete price/failure-mode account that gap asked for, for the specific case of a frontier orchestrator delegating I/O work to a cheap worker mode: names the round-trip latency (10-30s, capped at 30s), the coordination overhead (a network hop through the Portal backend to the worker model and back), and explicit, named failure boundaries (delegation breaks for edits needing precise locations, and for reasoning-heavy work like the missed thread-safety bug) that mark exactly when tiering degrades outcomes.
Related documents
- When Guardrails Go Wrong
- The Almedra Token-Efficiency Benchmark, Updated For GLM 5.2
- GitHub - musistudio/claude-code-router: Use Claude Code as the foundation for coding infrastructure, allowing you to decide how to interact with the model while enjoying updates from Anthropic.
- Alex Wang's Post
- Claude Code: Best practices for agentic coding
- Lessons from building Claude Code: How we use skills
- Downstream #1: Where Do Our Tokens Go?
- Fragments: July 6
- Google Just Dropped a Masterclass on Agentic Engineering (It's SO Good)
- The New SDLC With Vibe Coding: From ad-hoc prompting to Agentic Engineering