Skip to content
IFAI

AI tools

Anthropic's cheat sheet for saving Claude Code tokens

Published Reach 42

Anthropic just shared an insider guide on optimizing token usage in Claude Code sessions. The core lesson is protecting your prompt cache: switching models or effort levels mid-conversation busts the cache, forcing full-price prefills. Engineers recommend running /clear between tasks, using @-mentions to skip file read calls, and running /compact before stepping away from the keyboard.

Anthropic's cheat sheet for saving Claude Code tokens
Image: claude.com

Coding tools used to come with flat monthly pricing, where running fifty compiler checks cost the exact same as running one. Agentic coding tools like Claude Code flip that model completely, turning every single decision into an inference cost.

Anthropic engineer Lydia Hallie just published an in-depth breakdown of how Claude Code handles tokens under the hood, along with actionable ways developers can keep their session costs under control.

How prompt caching actually behaves

Token pricing comes down to GPU inference time, which is split into two phases: prefill (reading context) and decode (writing output). Because generating tokens one by one keeps hardware occupied far longer, output tokens cost roughly five times more than inputs. Many of these output tokens are thinking tokens, directly governed by the /effort parameter.

Claude Code manages prompt caching automatically to offset prefill costs. Reading cached tokens costs just 10% of the standard input price. The catch is that caching relies on strict prefix matching, moving from tool definitions and system prompts to CLAUDE.md and the conversation log.

Appending tool results to the tail end preserves the cache smoothly. However, tweaking /model, altering /effort, or toggling Fast mode mid-session breaks the cache key. When that happens, the server throws away the cache and prefills the entire multi-turn transcript at full cost. Hallie also notes that the opusplan feature busts the cache whenever it toggles models in and out of plan mode.

Time is another factor. Cached states expire after one hour on subscriptions, and after just five minutes for standard API keys unless the ENABLE_PROMPT_CACHING_1H=1 environment variable is set.

Practical habits to cut token burn

Once the mechanics are clear, trimming token waste becomes straightforward.

Run /clear between distinct tasks. Carrying old grep logs and obsolete diffs into a new assignment wastes context space and forces the model to reason through files it no longer needs.

Lock in your model and effort tier before typing. If you need to switch gears, do it in a fresh session or right after clearing the context.

Use @-mentions to attach files directly. Simply typing the file path prompts Claude to spend an extra turn executing a Read or search call, whereas an @-mention loads the file into the initial message immediately.

Keep noisy shell commands quiet. Hallie suggests using quiet flags or executing noisy builds inside a subagent, because full terminal dumps remain stuck inside the session history indefinitely.

Finally, run /compact before stepping away from the keyboard. Summarizing a conversation while the cache is warm costs a tenth of the price; doing so after an hour-long break forces a full-price prefill of the entire raw history.

Why it matters

We think this guide marks an important transition in how developers need to think about their workflows. Managing context window economics is quickly becoming as essential as writing clean code.

For individual developers and teams building with AI agents, adopting these habits is an immediate win. Running /compact before stepping away or using @-mentions requires virtually zero setup, yet it prevents runaway API bills and keeps agent reasoning sharp by eliminating context bloat.

For the broader industry, Anthropic is setting a great precedent by demystifying agent inference economics. Rather than treating token burn as an inevitable black box, detailing exactly how prompt caches break gives developers actionable agency. It shows that in the agentic era, true platform value is not just about raw model benchmarks, but about helping users get the most compute out of every single turn.

Sources (1)

  1. [1]
    claude.com(opens in a new tab)Originalclaude.com

Best of AI, daily