Case Studies

Spotify Open-Sources Portal, a Proxy That Cut Claude Code Token Use by 90%

Spotify's engineering team released Portal, an in-house optimization layer for Claude Code that reduced token consumption by 90% in production. It is not a model release, but a practical case study in cutting AI coding costs at scale.

Font size

In early September, the Spotify engineering blog published a provocatively titled post: "Portal by Spotify: Cut my Claude Code token usage by 90%".

Notice the wording: "cut my token usage," not "we invented a new model." Portal is neither a new model nor a new product. It is an optimization layer Spotify has been running internally with Claude Code, and the team recently open-sourced it.

The post climbed to the front page of Hacker News, sitting at 31 points with 7 comments at the time of writing. The comment thread split into two camps: one insisting the 90% figure was marketing fluff, the other asking "why not just switch to Haiku?"

Both sides missed the point. The real story is that Spotify took a path distinct from Cursor or GitHub: don't swap the model, compress the input.

What Portal Is, and Why Spotify Built It

One-line summary: Portal is a middleware layer that sits between Claude Code and the editor. Every request Claude Code sends first passes through Portal, which trims context, compresses prompts, and then forwards the request.

The problem it tackles is not that models are too dumb. It is that tokens are too expensive.

Spotify engineers readily admit their internal Claude Code usage is "very, very large." Once a team's monthly AI coding bill starts climbing into five-figure territory, the question stops being "is the model good enough?" and becomes "how do we get the same work done with fewer tokens?"

The conventional approaches are to switch to a cheaper model (Sonnet → Haiku) or to lean on prompt caching. Spotify went further: keep the model, attack the input side.

Where the 90% Number Comes From

Spotify breaks the token reduction into three contributing factors:

  1. Context pruning — for large files, send only the relevant sections, not the full file.
  2. Prompt compression — deduplicate system prompts and repeated instructions.
  3. Tool call optimization — send incremental diffs instead of resending entire files.

Worth emphasizing: this is measured engineering work, not a model upgrade. The Claude model didn't change. Claude Code didn't change. The layer in the middle did.

That is also why the 90% figure draws skepticism. One Hacker News commenter asked sharply: "If you're just trimming irrelevant files, does 90% mean you were sending a bunch of stuff that should never have been sent in the first place?"

The question is harsh, but not unfounded. If a team is overstuffing the context window, any pruning will produce dramatic numbers.

Technical Details: What Portal Actually Does

The Spotify engineering team disclosed several key mechanisms:

  • Context window management: maintains a sliding window that keeps only the most recent N turns of conversation plus files relevant to the current task.
  • File relevance filtering: infers which other files might be referenced based on the file currently being edited, and sends only those.
  • Incremental diffs instead of full retransmission: after a file is modified, only the diff is sent, not the entire new file.

Below is a minimal usage example from the README:

# Install
npm install -g @spotify/portal

# Configure Claude Code to route through Portal as a proxy
portal config --set anthropic_base_url=http://localhost:8080

# Start Portal
portal serve --port 8080
# Core pruning logic inside Portal (simplified)
class ContextPruner:
    def __init__(self, max_tokens=50000):
        self.max_tokens = max_tokens
        
    def prune(self, files: list[File], current_focus: str) -> list[File]:
        # 1. Score each file's relevance to the current focus
        scored = [(f, self._relevance(f, current_focus)) for f in files]

        # 2. Sort by score and greedily fill the token budget
        scored.sort(key=lambda x: x[1], reverse=True)

        result = []
        used = 0
        for f, score in scored:
            if used + f.tokens > self.max_tokens:
                continue
            result.append(f)
            used += f.tokens

        return result

To be clear, this analysis is bounded by what Spotify has made public. Internal heuristics, thresholds, and caching strategies haven't been disclosed, and I won't speculate on them. The confirmed picture: this is not magic, just a proxy plus context engineering.

What the HN Thread Was Arguing About

Three of the seven comments stand out:

"90% reduction is suspicious. What was your baseline? If you're sending entire repos as context, of course you can cut 90%."
"Why not just use Haiku? It's 1/10 the cost and good enough for most coding tasks."
"This is the real lesson: context engineering > model swapping. Most teams waste tokens before they need a better model."

The first questions the baseline (whether the comparison is fair). The second questions the approach (why not switch models). The third lands on Spotify's core argument.

These three commenters represent the community's three stances: skeptics, pragmatists, and believers. The 31 points suggest believers hold the majority, though how many of those upvotes came from Spotify's own engineers is anyone's guess.

How This Differs From Previous AI Coding Cost-Cutting Stories

Over the past two years, AI coding cost reduction has generally followed three paths:

ApproachExampleLogic
Swap to a cheaper modelSonnet → HaikuTrade model capability for cost
Prompt cachingCursor, CopilotDon't bill twice for repeated content
Model distillation / fine-tuningVendor-specific small modelsRun small models on narrow tasks

Spotify represents a fourth path: the model stays, the cache isn't specially optimized, and tokens are eliminated directly at the input.

How does it differ from the Sonnet → Haiku route? Capability. Haiku still lags Sonnet on complex refactors and long-chain reasoning. Spotify clearly didn't want to sacrifice that capability; it just wanted to spend less.

How does it differ from Cursor's prompt cache? Granularity. Cursor's cache is "don't bill twice for repeated portions within the same conversation." Portal is "don't include parts of the conversation that shouldn't be there in the first place." The former is a backend optimization; the latter is an input-side one.

For high-frequency use cases (dozens to hundreds of Claude Code runs per day), Portal's marginal gains are larger. Caches have a ceiling; input pruning does not.

Editorial Take

For most teams, 30-50% is probably a more realistic reproduction of the 90% figure.

The reason is straightforward: Spotify measured this against its own monorepo, its own coding conventions, and its own Claude Code usage patterns. A different team with a different project type will have a different baseline. But that's beside the point.

What's genuinely worth noting is the shift in attitude this represents: big tech is starting to treat AI coding costs as an engineering problem.

For the past two years, the AI coding story has been about productivity: Copilot helps you write faster, Cursor helps you be more precise, Devin automates work in demos. Cost has been the topic nobody wants to touch. Everyone assumes tokens are an infinite resource.

Spotify's post is unusual in that it opens up the bill for inspection. This is the first time a major tech company has publicly stated "here's what we spent, here's how we cut it, here's how much we saved."

My prediction: over the next 6-12 months, more large companies will open-source similar tools. Not out of generosity, but because AI coding bills have grown large enough that CFOs start asking questions. Google, Microsoft, and Meta almost certainly have comparable systems internally; they just haven't published.

One caveat: Portal doesn't mean much for individual developers. The configuration overhead, learning curve, and setup cost won't pay off for small projects. If your monthly Claude Code bill is under $100, installing Portal will likely be a net negative. It's designed for heavy daily use.

Another open question I haven't fully resolved: will middleware like Portal eventually be absorbed by Anthropic itself? If Claude Code 2.0 ships with built-in context pruning, does Portal still have a role? Anthropic's product cadence will determine whether Portal is a transitional solution or a lasting ecosystem niche.

What makes this story distinctive: it's not a model story, not a product story, it's an engineering story. At a moment when everyone is racing on models and products, Spotify picked the least glamorous angle, optimizing the middle layer, but it may also be the easiest one for others to replicate.


References:

Source: https://engineering.atspotify.com/2026/9/portal-by-spotify-cut-my-claude-code-token-usage-by-90