O guia de engenharia para Claude Code que corta 65–90% do consumo de tokens sem mudar o que você pede. Arquitetura implementável, benchmarks reproduzíveis.
The engineering guide for Claude Code that cuts 65–90% of token consumption without changing what you ask. Implementable architecture, reproducible benchmarks.
Cada turno do Claude Code recarrega ~100K tokens de contexto. Você não paga só pelo que ele escreve — paga por tudo que ele relê, repetidamente.
Every Claude Code turn reloads ~100K tokens of context. You don't pay only for what it writes — you pay for everything it rereads, repeatedly.
96% dos seus tokens são Cache Read — o Claude relendo o que já leu. Invisível nos logs, devastador no plano.
96% of your tokens are Cache Read — Claude rereading what it already read. Invisible in logs, devastating to your plan.
67% das calls vão pra Opus, mas o output médio é igual ao Sonnet. Você está pagando 5x por tarefa que custaria 1x.
67% of calls go to Opus, but average output is the same as Sonnet. You're paying 5x for tasks that would cost 1x.
A cada ~30 turnos, o Claude apaga o histórico para caber na janela. Tudo que você carregou no init: perdido. Sem alerta.
Every ~30 turns, Claude wipes history to fit the window. Everything you loaded at init: gone. No alert.
Cada tool call carrega novamente 10K+ tokens de definição de MCPs. Overhead silencioso que nunca aparece como linha de custo.
Each tool call reloads 10K+ tokens of MCP definitions. Silent overhead that never shows up as a cost line.
Cada padrão é uma decisão arquitetural com benchmark medido em produção. Tudo que você precisa para implementar — sem prompting magic.
Each pattern is an architectural decision with production-measured benchmark. Everything you need to implement — no prompting magic.
L1-Lite (mapa, ~3K tokens, sempre carregado) + L1-Full (contexto completo, sob demanda). Stack Redis + SQLite + vector store.
L1-Lite (map, ~3K tokens, always loaded) + L1-Full (full context, on demand). Redis + SQLite + vector store stack.
Classificador YAML (haiku/sonnet/opus) sem LLM, <1ms. Auto-correção por feedback. Inverte a proporção Opus/Sonnet de 67/33 para 20/80.
YAML classifier (haiku/sonnet/opus), no LLM, <1ms. Self-correcting via feedback. Flips Opus/Sonnet ratio from 67/33 to 20/80.
Hooks PreToolUse que rastreiam quota, fazem cache de resultados e reutilizam respostas idênticas dentro da janela TTL.
PreToolUse hooks that track quota, cache results, and reuse identical responses within the TTL window.
Tabela de custo real por operação (Bash, Read, Edit, Grep, Subagents). Onde investir otimização e onde ignorar.
Real cost table per operation (Bash, Read, Edit, Grep, Subagents). Where to invest optimization and where to ignore.
Anti-compressão por hook: a cada ~30 turnos, recarrega o mapa Lite antes que a compressão destrua o contexto. ~3K tokens previnem ~50K.
Anti-compression hook: every ~30 turns, reload the Lite map before compression destroys context. ~3K tokens prevent ~50K.
Modelo leve (Haiku) lê 10–20 arquivos e entrega briefing denso de 5K tokens. Compressão típica 200:1. Cache Redis com TTL 36h.
Light model (Haiku) reads 10–20 files, delivers dense 5K-token briefing. Typical 200:1 compression. Redis cache with 36h TTL.
Pipeline Planner (Opus) → Gerador (Sonnet/Haiku) → Auditor (Opus, vê só o diff). Reduz custo de geração longa em 65–85%.
Pipeline Planner (Opus) → Generator (Sonnet/Haiku) → Auditor (Opus, sees only diff). Cuts long-generation cost by 65–85%.
UserPromptSubmit + PreToolUse + PostToolUse. Classificação na entrada, web search gate, critical path guard. Disciplina como infraestrutura.
UserPromptSubmit + PreToolUse + PostToolUse. Entry classification, web search gate, critical path guard. Discipline as infrastructure.
Tudo neste guia foi extraído de logs reais de produção. Nada de teoria, nada de promessa. Os benchmarks são reproduzíveis nos seus próprios dados.
Everything in this guide is from real production logs. No theory, no promises. Benchmarks are reproducible on your own data.
Você usa Claude Code todo dia, paga Pro/Max, e sente o plano acabar antes da semana terminar.
You use Claude Code every day, pay for Pro/Max, and feel the plan run out before the week ends.
Você delega execução técnica ao Claude e precisa que cada token entregue valor proporcional ao custo.
You delegate technical execution to Claude and need every token to deliver value proportional to its cost.
Você constrói sistemas multi-agente e precisa de arquitetura de cache, roteamento e auditoria que escale.
You build multi-agent systems and need cache architecture, routing and auditing that scales.
Os padrões aplicam-se a qualquer agente LLM com tool use intensivo (Cursor, Aider, custom agents). Os exemplos são em Claude Code porque foi onde rodamos os benchmarks, mas a arquitetura é portável.
The patterns apply to any LLM agent with intensive tool use (Cursor, Aider, custom agents). Examples are in Claude Code because that's where we ran benchmarks, but the architecture is portable.
Os snippets são em Python, mas a lógica é replicável em qualquer linguagem. Hooks, dispatch, cache — tudo isso é arquitetura, não tecnologia específica.
Snippets are in Python, but the logic is replicable in any language. Hooks, dispatch, cache — all of this is architecture, not specific technology.
Fase 1 (diagnóstico) em 1 dia. Fase 2 (quick wins, 30–50% de redução) em 2–3 dias. Stack completo em 2–3 semanas. O ROI é incremental: você começa a economizar no segundo dia.
Phase 1 (diagnosis) in 1 day. Phase 2 (quick wins, 30–50% reduction) in 2–3 days. Full stack in 2–3 weeks. ROI is incremental: you start saving on day two.
Download imediato dos PDFs (PT + EN) e do pack de snippets. Atualizações futuras notificadas por email.
Instant download of PDFs (PT + EN) and snippet pack. Future updates notified by email.
É um manual de engenharia. Denso, técnico, direto. Cada capítulo tem o porquê, o como, e o benchmark. Sem fluff, sem encheção.
It's an engineering manual. Dense, technical, direct. Each chapter has the why, the how, and the benchmark. No fluff.
7 dias, sem perguntas. Se você implementou as estratégias da Fase 2 e não viu redução de pelo menos 30%, devolvemos integral.
7 days, no questions. If you implemented Phase 2 strategies and didn't see at least 30% reduction, full refund.
Abra seus logs em ~/.claude/projects/ agora.
O baseline é o primeiro passo de qualquer engenharia séria.
Open your logs in ~/.claude/projects/ now.
The baseline is the first step of any serious engineering.