These 33 Lines Cut Claude Code Token Usage by 90%

Por Cloud Codes · 11 sep 2026 · 13:27

Visualizaciones
24.6K vistas
Likes
283 likes
Comentarios
32 comentarios

Spotify Engineering’s open-source Shunt plugin (portal-ai-plugins) uses a 33-line PreToolUse bash hook to intercept Claude Code's file reading tools, cutting bulk-read token consumption by 82% to 94% on large monorepos. By enforcing a hard 350-line threshold and delegating large context ingestion to lightweight worker models like Gemini 2.5 Flash via Spotify's internal Portal gateway, this architecture replaces advisory CLAUDE.md prompt routing with deterministic execution boundaries. 🔔 Subscribe: https://www.youtube.com/channel/UC0DZj1PNa_Fp0MU6uPSKv5w?sub_confirmation=1 💙 Become a Member: https://www.youtube.com/channel/UC0DZj1PNa_Fp0MU6uPSKv5w/join 🐦 Twitter/X: https://x.com/cloud_codes 💬 Discord: https://discord.gg/4kJqEBMMf In this deep dive, Cloud Codes deconstructs the request lifecycle of Shunt: how it inspects JSON payloads on stdin, allows targeted offset/limit slices while blocking full-file ingestion, and exploits the 16:1 price ratio between frontier models (Claude Opus 5 at $5/M) and fast workers ($0.30/M). We run the 20-turn session math showing why cached prefix re-reads constitute 67% of an unoptimized bill, analyze JetBrains' counter-benchmark where an identical hook actually increased task costs by 7.6% due to turn amplification, and expose the critical architectural gap Spotify left un-enforced on code generation. If this breakdown helped you understand agentic token economics, PreToolUse hooks, and local developer tooling, subscribe to Cloud Codes for a new infrastructure deep dive every week. Build, solve, deploy. 🔗 Resources Mentioned: • Spotify Engineering Blog Post (Dimitri Mazmanov): https://engineering.atspotify.com/2026/9/portal-by-spotify-cut-my-claude-code-token-usage-by-90 • Spotify Portal AI Plugins (GitHub Repository): https://github.com/spotify/portal-ai-plugins • Shunt Plugin Documentation & Savings Table: https://github.com/spotify/portal-ai-plugins/tree/main/plugins/shunt • Shunt check-file-size Hook Source Code: https://github.com/spotify/portal-ai-plugins/blob/main/plugins/shunt/hooks/check-file-size • Claude Code PreToolUse Hooks Reference: https://code.claude.com/docs/en/hooks • JetBrains Research: Token Savings Autopsy (Denis Shiryaev): https://blog.jetbrains.com/ai/2026/07/rtk-claude-code-token-savings/ • Hacker News Discussion Thread: https://news.ycombinator.com/item?id=49571465 • Claude Code Issue #72940 (Explore Agent Model Inheritance): https://github.com/anthropics/claude-code/issues/72940 ⏱️ Chapters: 0:00 - The 602-Line File Claude Code Never Opens 0:29 - The Headline vs The Reality: "My" Token Usage 0:54 - The Real Benchmark Table: 82% to 94% Read Savings 1:44 - Why Advisory CLAUDE.md Rules Fail 1:59 - The Architecture: 33 Lines of PreToolUse Bash 4:09 - Delegating to Cheap Models: The 16:1 Price Ratio 6:08 - Token Savings vs Dollar Savings: The Math 7:14 - The 20-Turn Compounding Trap: Cache Re-Reads 8:31 - The Hidden Catch: No Enforcement for Code Writing 10:36 - The JetBrains Autopsy: Why rtk Increased the Bill by 7.6% 12:31 - Final Verdict: Take the Hook, Leave the Round Trip #claudecode #spotify #aiagents #anthropic #softwareengineering #devops #tokenomics #cloudcodes #llm #programming #technews User Queries: spotify claude code token usage portal by spotify cut my claude code token usage by 90 spotify shunt plugin claude code how to reduce claude code token consumption claude code pretooluse hook example claude code check file size hook spotify portal ai plugins github claude code prompt caching cost 20 turns claude code explore agent haiku to opus why claude.md routing rules fail jetbrains rtk vs spotify shunt how to delegate claude code reads to gemini flash claude code bulk reader skill spotify aika claude code integration reduce anthropic api bill coding agent claude code hooks json configuration smart model routing claude code claude code offset limit read tool is spotify shunt plugin open source cloud codes