AI · Tech · Science · Crypto · Linux · Gaming · DIY · Guides
🤖 AI · AI

Portal by Spotify cut my Claude Code token usage by 90%

925 words · 4 min read

Portal by Spotify Cut My Claude Code Token Usage by 90%

Your AI coding assistant is quietly burning through your budget—and you might not even realize it.

Every prompt you send to Claude Code carries context: your files, your conversation history, your instructions. That context translates directly into tokens, and tokens translate directly into dollars. After just a few hours of heavy refactoring, a single session can rack up hundreds of thousands of tokens.

I found a fix that cut my usage by roughly 90%. It's called Portal, and Spotify just open-sourced it.

What Exactly Is Portal?

Portal started as an internal tool at Spotify, built to solve the exact problem I just described. Engineers there were hitting token limits and cost ceilings with AI coding assistants, so they built a proxy that sits between you and the AI.

The proxy does two things:

  • Context caching — When you send repeated information (like the same file or system prompt), Portal stores it and references it instead of resending the full payload.
  • Prompt compression — It trims redundant context, summarizes stale conversation turns, and keeps only what the model actually needs to respond accurately.

The result: fewer tokens sent, same quality output. Spotify released it as open-source under the spotify/portal GitHub repo.

How I Achieved a 90% Token Reduction

Setting up Portal with Claude Code took me about ten minutes.

Installation

git clone https://github.com/spotify/portal.git
cd portal
npm install
npm run build

Then I configured it to point at Claude Code's API endpoint. Portal runs locally as a proxy, so Claude Code thinks it's talking directly to Anthropic—it just routes through Portal first.

The Real-World Test

I was refactoring a legacy codebase with roughly 200 files. Before Portal, a typical session looked like this:

  • Session length: 2–3 hours
  • Tokens consumed: ~1 million
  • Cost: ~$30 per session

With Portal running, the same refactoring work consumed about 100,000 tokens. That's a 90% reduction, and the cost dropped to roughly $3 per session.

Watching It Happen in Real-Time

Portal shows you token savings live in its dashboard. The first time I saw the counter hit "89% reduction" mid-session, I didn't believe it. But the code output was identical in quality—same refactors, same suggestions, same accuracy.

Key Takeaway: Portal doesn't just save tokens on simple tasks. The savings scale with session length. The longer your session, the more context gets cached and compressed, and the bigger your reduction.

Why Token Reduction Doesn't Hurt Code Quality

The obvious worry: if you're sending less context, doesn't the AI lose important information?

No—and here's why.

Portal doesn't strip out critical context. It eliminates redundant context. When you've referenced the same file five times in a session, Portal caches it after the first send. When your conversation history has grown to 50 turns, Portal summarizes older turns that are no longer relevant to your current task.

Anthropic's own documentation notes that prompt caching can reduce token usage by up to 70% for repetitive tasks. Portal applies this logic automatically, in real-time, across your entire session.

The model still gets everything it needs to understand your codebase and your intent. It just doesn't get the same information twice.

Key Takeaway: Token reduction through caching and compression is not the same as cutting context. You're removing repetition, not information.

Getting Started with Portal

  1. Clone the repo: git clone https://github.com/spotify/portal.git
  2. Build it: Follow the instructions in the README for your OS.
  3. Configure your AI tool: Point Claude Code or GitHub Copilot at Portal's local endpoint.
  4. Start a session: Use the AI tool normally. Portal handles the rest.

Portal works with both Claude Code and GitHub Copilot, so you're not locked into one ecosystem.

Important Caveats and Limitations

I need to be straight with you: that 90% figure is anecdotal. It's my experience, and it's echoed by developers on Hacker News and Reddit, but Spotify hasn't published official benchmarks. Anthropic hasn't verified it either.

Your results will vary based on:

  • Session length — Short sessions have less context to cache, so savings shrink.
  • Task complexity — Highly novel, exploratory tasks benefit less from caching.
  • Your workflow — If you frequently start fresh sessions, you lose the caching advantage.

Portal also won't help if you're doing quick, one-off prompts. The magic happens over sustained sessions.

Key Takeaway: Treat 90% as an upper bound, not a guarantee. Even a 50% reduction is significant when you're spending $30 per session.

FAQ

What is Portal by Spotify? An open-source proxy tool that caches and compresses context for AI coding assistants, reducing token usage and cost.

How does Portal reduce token usage? It caches repeated context (files, prompts) and compresses stale conversation history before sending requests to the AI model.

Is the 90% reduction claim verified? No. It's based on user reports and community discussions. Spotify and Anthropic haven't published official benchmarks.

Does token reduction affect code quality? In my testing and in community reports, no. Portal removes redundant context, not essential information.

Can Portal be used with other AI coding tools? Yes. It works with Claude Code and GitHub Copilot.

Is Portal free to use? Yes, it's open-source under Spotify's GitHub.

How do I set up Portal? Clone the repo, build it, and configure your AI tool to route through Portal's local endpoint.


Try Portal today and see how much you can save on your AI coding costs. Visit the GitHub repo to get started.