Open a Claude Code session in the morning. Work for a few hours. Step away for lunch. Come back and ask a one-line question.
That one line can bill you for the whole morning again. The reason is how the request is built.
The model does not keep state between turns. Every time you press Enter, Claude Code sends the full conversation again. That means the system prompt, your CLAUDE.md, every file it read, every command it ran, and your new message on the end. Anthropic’s prompt caching page says it plainly: “The model doesn’t remember anything between requests, so Claude Code re-sends the full context.”
You can see this in Anthropic’s own sample output for the /usage command. The session in the example ran for six and a half hours on Sonnet 4.6. Claude Code's local estimate put it at $0.55. Of roughly 991,000 tokens sent to the model, 940,000 were cache reads (text the model had already processed and could reuse) and 50,000 were cache writes (text stored for reuse). Only 1,200 were plain, uncached input. The session was almost entirely the model re-reading what it had already seen.
It was cheap because cache reads are billed “at roughly 10% of the standard input rate.” Without the cache, the same re-reading costs roughly ten times as much.
That is the whole subject: every turn re-reads your morning, and the cache is the only reason you can afford it.
Two levers decide your bill: how big the re-sent context is, and how much of it the cache serves at the discounted rate. Almost every habit below pulls one of those two. The rest change the price per token, or how much the model writes back.
How a request is built, and why that decides your bill
Claude Code orders each request so the parts that rarely change come first. The prompt caching page describes three layers: The API caches the start of each request. That start is called the prefix. The match must be exact. Change anything early in the prefix and everything after it is recomputed. Append at the end and only the new part is processed at full price.
Two settings are not part of the prompt text but still count for the cache match: the model, and on most models the effort level (how much thinking the model does). Switch either one mid-session and the entire request is recomputed even though the text is identical.
The cache also expires. Its lifetime is called the TTL, or time to live. On a Claude subscription, within your plan’s usage, the main conversation survives a one-hour gap. On usage credits, an API key, or a cloud provider, the default is five minutes. The first message after a longer break misses the cache and reprocesses your full context. That is the lunch-break bill from the opening.
Hold those three facts: context is re-sent, the prefix is cached, the cache expires.
Anthropic does not publish a ranking. The order below starts with what the costs page calls “the highest-impact habits to share”. Those are clearing between unrelated tasks and matching the model to the job. After that, habits that protect more of the request rank higher. The first three are the ones to adopt this week. The rest add up over time.
This is the habit Anthropic names first. “Stale context wastes tokens on every subsequent message,” the costs page says.
The fix is /clear when you switch to unrelated work. Run /rename before clearing so you can /resume the old session later.
Why it ranks first: every other habit shrinks a piece of the context. This one resets all of it, and it is free. The costs page contrasts it with compaction directly: “When you want a fresh start instead of continuity, /clear costs nothing."
Anthropic’s best practices name the failure mode “the kitchen sink session”: one task, then an unrelated question, then back to the first. A second trigger: if you have corrected Claude more than twice on the same issue, clear and write a better prompt. “A clean session with a better prompt almost always outperforms a long session with accumulated corrections.”
For side questions that do not need to stay in the conversation, use /btw. It sees your full conversation but has no tools, and the answer never enters the conversation history. While the cache is warm (still holding your conversation), "a side question costs little beyond the answer itself." Model choice is the second habit Anthropic names. It changes the price per token rather than the token count.
The costs page keeps it short: “Sonnet handles most coding tasks well and costs less than Opus. Reserve Opus for complex architectural decisions or multi-step reasoning.”
The same page names two usual causes of surprise bills on an API or cloud-provider plan: “Opus left as the default model” and sessions that are never cleared. Check what your default is. On Pro and Team Standard plans it is Sonnet 5. On Max, Team Premium, seat-based Enterprise (since v2.1.251), and the API it is Opus 5, unless your admin set an organization default.
One rule makes this cheaper: pick the model at the top of the session. Each model has its own cache. Switching mid-session with /model means "the next request reads the entire conversation history with no cache hits, even though the content is identical."
Claude Code asks you to confirm a switch only while the cache is still warm and the model you are switching to is not the one that answered last. That prompt is your cue that the switch is not free. A team can enforce it. Since v2.1.251 a PreModelSwitch hook (a script Claude Code runs before a model switch) can block the switch outright.
For subagents (helper sessions that do a side task and report back), set model: haiku in the definition for simple work. To do it for every subagent at once, set CLAUDE_CODE_SUBAGENT_MODEL=haiku and CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 (v2.1.257). Caching is automatic. Breaking it is easy.
Anthropic lists the actions that invalidate the cache on the prompt caching page: Each of these costs you one slow turn that misses part or all of the cache. The longer your conversation, the bigger the hit. Anthropic’s tip: “Pick your model and effort level at the top of a session, then save /compact for natural breaks between tasks."
One exception is new. On Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache (v2.1.260). It still invalidates on Bedrock, Google Cloud’s Agent Platform, or a Claude apps gateway, and under CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS or a HIPAA configuration.
Three things are safe. Editing files in your repository appends a change notice. It does not touch the prefix. Invoking a skill or a command appends its instructions as a message. The one exception: if the skill names a different model, that turn counts as a model switch. And /rewind cuts back to a prefix that is already cached, so it is cheaper than compacting when you want to abandon a path.
Cache lifetime is the other half. Recall the five-minute default on usage credits, an API key, or a cloud provider. Since v2.1.242 the fix is a setting: promptCacheTtl: "1h" for the main conversation, and subagentPromptCacheTtl for everything else. The hour is not free. Cache writes bill at a higher rate, so it pays off only when you idle past five minutes.
If your requests pass through a gateway (a proxy between you and the API), check that it forwards the cache_control markers that ask the API to cache. A gateway that strips them while returning success bills "your entire conversation history" as uncached input on every turn. One last check. A run of silent cache-miss bugs was closed between v2.1.248 and v2.1.275, including an hourly miss after an OAuth token refresh and /model re-sending every tool definition. If your cache numbers looked wrong this summer, upgrade first.
CLAUDE.md loads at session start and rides along on every request. The costs page is specific: “Aim to keep CLAUDE.md under 200 lines by including only essentials.” Detailed workflow instructions, such as a PR review procedure, belong in skills, which “load on-demand only when invoked.”
The best practices page gives the test for each line: “Would removing this cause Claude to make mistakes?” If not, cut it. Bloat is not only a cost problem: “Bloated CLAUDE.md files cause Claude to ignore your actual instructions!”
One thing people get wrong: splitting CLAUDE.md into @path imports helps organization but does not reduce context, since imported files load at launch.
Skills need discipline too. Their descriptions load at session start, and “every skill in the skill listing adds to your context on every turn, whether or not Claude ever uses it.” Run /skill-doctor (v2.1.252, in a terminal session) to see what each skill costs and how often it is used, then turn off the ones you never invoke. Once a skill loads, "every line is a recurring token cost," so keep SKILL.md under 500 lines.
MCP tool definitions used to be a silent tax on every request. On Claude 4.5-generation and later models they no longer are by default, unless your requests go through a non-first-party gateway. The costs page notes that definitions are “deferred by default, so only tool names and server instructions enter context until Claude uses a specific tool.”
Two habits still matter. Prefer CLI tools: gh, aws, gcloud, and sentry-cli "are still more context-efficient than MCP servers because they don't add any per-tool listing." And run /mcp to disable servers you are not using. /context shows what is taking space.
When tools are deferred, a server connecting or disconnecting only appends content and leaves the cache intact. When tools are loaded into the prefix, such as behind a custom gateway or on a server marked alwaysLoad, any change to them invalidates the cache. And if only one subagent needs a server, define it inline in that subagent's mcpServers "to keep an MCP server out of the main conversation entirely."
Running tests, fetching documentation, and reading logs produce a lot of output. The costs page says to hand that work to a subagent “so the verbose output stays in the subagent’s context while only a summary returns to your main conversation.”
The context window walkthrough puts a number on it. In the simulated session, a research subagent reads 6,100 tokens of files and returns a 420-token summary. The file reads never touch the main context. The best practices page puts it this way: “Since context is your fundamental constraint, use subagents to keep research out of it.”
The built-in Explore and Plan agents skip your CLAUDE.md files and git status, so they start even smaller. Since v2.1.271 a custom subagent can skip the user, project, and local CLAUDE.md files too, with omitClaudeMd: true in its definition. Explore inherits your session's model, capped at Opus on the Claude API. So it never runs on a more expensive model than the one you picked, unless you force one as in habit 2.
Subagents are not free. Each one starts its own conversation with its own prefix, and its first request does not read the parent’s cache. And “running many subagents that each return detailed results can consume significant context,” so ask for a summary, not a transcript.
Vague prompts cost tokens in a specific way. “Vague requests like ‘improve this codebase’ trigger broad scanning,” the costs page says. Specific requests, like adding validation to one named function, “let Claude work efficiently with minimal file reads.” Anthropic calls the failure “the infinite exploration”: an unscoped “investigate” that reads hundreds of files. Scope it, or move it to a subagent.
For complex tasks, the same page recommends plan mode. Claude explores and proposes an approach before editing, “preventing expensive re-work when the initial direction is wrong.” The best practices page adds the counterweight: “If you could describe the diff in one sentence, skip the plan.” And press Escape the moment Claude heads the wrong way, then /rewind to a checkpoint. The wrong turn leaves the conversation instead of riding along in every later request.
When Claude explores unfamiliar code, file reads pile up in the conversation layer and ride along on every later turn. Two settings cut them without changing how you work.
First, code intelligence plugins. They connect Claude to a language server, the same engine behind go-to-definition in your editor. The costs page puts the saving concretely: “A single ‘go to definition’ call replaces what might otherwise be a grep followed by reading multiple candidate files.” This works in local sessions only. Cloud sessions do not start plugin language servers.
Second, Read deny rules for paths Claude should never open: build output, generated code, vendored dependencies. Anthropic's large codebase guide shows the pattern in permissions.deny, for example Read(.//dist//*). Content searches already respect .gitignore, so node_modules and build stay out of results without any setup.
A hook is a script Claude Code runs at a set moment, such as before a tool call. It can filter tool output before it reaches the model. Anthropic’s example is on the costs page: “Instead of Claude reading a 10,000-line log file to find errors, a hook can grep for ERROR and return only matching lines, reducing context from tens of thousands of tokens to hundreds."
The page includes a working PreToolUse hook that rewrites npm test, pytest, and go test to show only failures. To confirm it fires, start with claude --debug-file ./claude-debug.txt, run the tests, and look for a modified tool input keys line in the log.
Hooks cost “Zero, unless hook returns additional context” in Anthropic’s own table, and what they return is capped at 10,000 characters per string. A SessionStart hook with a compact matcher can re-inject critical context after every compaction.
Extended thinking (the model reasoning before it answers) is on by default because it “significantly improves performance on complex planning and reasoning tasks.” Thinking tokens bill as output tokens. The costs page says the default budget “can be tens of thousands of tokens per request depending on the model.”
For simpler work, lower the effort level with /effort or in /model. The model configuration page says the default is high on every model that supports effort. The exceptions are Opus 4.7, which defaults to xhigh, and the level your admin set for the organization's default model. Its own table warns that max "may show diminishing returns and is prone to overthinking." Since v2.1.251 Claude Code saves the level per model, so a cheap level chosen for Sonnet does not follow you to Opus. An admin can cap effort for the whole organization with maxEffortLevel. It works on every provider.
For a single hard turn, put the word ultrathink in the prompt instead of raising the session level. Claude Code "adds an in-context instruction. The effort level sent to the API is unchanged." Because the effort level in the cache match never moves, this also avoids the cache miss an effort change would cause. Output style is a smaller dial. “A style’s instructions add input tokens, though prompt caching reduces this cost after the first request in a session.” The built-in Concise style keeps responses short. Explanatory and Learning “produce longer responses than Default by design.” A switch with /output-style keeps the cache, and since v2.1.251 it applies from your next message instead of waiting for /clear.
Fast mode is a different trade. It “is not a different model,” just Opus configured for speed, with “identical quality and capabilities.” It costs $10 per million input tokens and $50 per million output tokens. It works only on Opus 5 and Opus 4.8, and it is a research preview, so pricing may change. Turn it on at the start of the session. The first fast-mode turn pays the uncached input price for the whole conversation so far.
Auto-compaction is a safety net, not a strategy. Claude Code “clears older tool outputs first, then summarizes the conversation if needed.” Your requests and key snippets survive. Early instructions may not, which is why Anthropic says to put persistent rules in CLAUDE.md, not in the conversation.
Compaction has a cost of its own. “/compact reads the conversation it summarizes, so compacting a large context is itself a large request." While the cache is warm it costs a fraction of what the context size suggests. After a break longer than the cache lifetime, "the summarization request reprocesses the full history as uncached input." So compact "at a natural break in your work, such as between tasks, instead of waiting for auto-compaction to trigger mid-task."
Three controls give you the summary you want. Run /compact with a focus, such as /compact Focus on code samples and API usage. Add a "Compact instructions" section to CLAUDE.md. Or open the rewind menu and choose "Summarize up to here" to compress only part of the conversation.
You can also decide how full the window gets before the automatic pass runs, with /autocompact 500k or the CLAUDE_CODE_AUTO_COMPACT_WINDOW variable. On the Anthropic API, models with a native 1M window compact at about 967,000 tokens by default. That covers Sonnet 5, and since v2.1.260 the Fable models and Opus 4.7 and later. CLAUDE_CODE_DISABLE_1M_CONTEXT=1 brings them down to the 200K boundary.
The 1M window is not a discount. It “uses standard model pricing with no premium for tokens beyond 200K.” But every turn still re-reads everything you have built up. So a lower auto-compact window is a cost control, not just a safety rail.
On Pro and Max plans, resuming a large session after a long break opens a dialog first. Large means over 100,000 tokens. Long means idle for more than about an hour. “Resume from summary” runs /compact and keeps the summary, your most recent exchanges, and up to five recently read files. Resuming as-is re-caches everything and keeps paying for every detail on each later request.
A session you are not typing in can still spend tokens. The costs page lists most of the usual suspects, and the interactive-mode page adds one more:
Two smaller costs are easy to miss. A ! shell command gets a reply from Claude, and "the response costs the same as sending a normal prompt." Set respondToBashCommands to false to keep only the output. And if you poll a long-running job with /loop, each tick re-sends your full context. The Monitor tool streams output lines back instead and "is often more token-efficient."
Resuming an old session is the last drain. The first request re-sends the whole conversation and reads from the cache only what is still within the TTL. Since v2.1.251 a SessionStart hook on resume receives context_tokens, prompt_cache_likely_expired, and estimated_cache_write_usd. That lets you print the lunch-break cost before you send the first message.
More agents means more context. The costs page says agent teams “use approximately 7x more tokens than standard sessions when teammates run in plan mode.” Each teammate is a separate Claude instance with its own window. The agent teams page now opens by telling you to “check whether a lighter option does the job” first: subagents, or separate sessions passing findings to each other.
The costs page gives four rules. Use Sonnet for teammates. Keep teams small. The agent teams page suggests starting with 3–5. Keep the prompt you start each teammate with short, because teammates already load CLAUDE.md, MCP, and skills. Shut teammates down when they finish.
Dynamic workflows (Claude fanning work out to many background agents) have the same shape. Claude Code shows a “Large workflow” warning past 25 agents or a projected 1.5 million tokens. The default size guideline is medium, now fewer than 10 agents (v2.1.271 lowered it from 15), and small, fewer than 5, on a Pro plan.
Two cache notes for anyone fanning out. Subagents, teammates, and workflow agents default to the five-minute TTL even on a subscription. subagentPromptCacheTtl: "1h" raises it. A fork (a copy of your session that branches off) inherits the parent's exact prefix, so its first request reads the parent's cache.
You cannot shrink what you cannot see. Anthropic gives you three places to look: /context, /usage, and the status line.
/context shows a live breakdown of what is in the window by category, with suggestions. /context all shows how many tokens each loaded MCP tool uses.
/usage shows tokens by model. On subscription plans it also attributes recent usage to skills, subagents, plugins, and MCP servers, lists your heaviest loops, and flags any behavior, such as long context or cache misses, that accounts for 10% or more of recent usage.
/usage also answers the cache question directly now. Since v2.1.251 it prints a Prompt cache (main) line. It shows the request count, the share of input tokens served from cache, and the number of misses. It also says whether the cache is warm right now and which TTL is in effect. Since v2.1.260 it names the likely cause of the last miss, such as tool definitions changing or idling past the TTL.
For a status line (the info bar at the bottom of your terminal), the same numbers arrive as a prompt_cache object on every response: warm, ttl, hit_ratio, misses, and last_miss_cause. Anthropic's rule of thumb still holds: "A high read-to-creation ratio means caching is working well. If creation stays high turn after turn, something is changing in your prefix." The counter-argument: when to let context grow
Everything above says “keep context small.” Anthropic’s own docs add the caveat: “Sometimes you should let context accumulate because you’re deep in one complex problem and the history is valuable.”
A long session is not a bug. A long session full of unrelated work is.
The bottom line
Every turn re-sends the conversation. The cache makes that cheap only while the prefix stays identical and the session stays warm. Every habit above either sends less or keeps one of those two things true. The first three do most of the work.
If you change one thing, run /usage after your next long session and read the Prompt cache (main) line. The share of input served from cache should be high, and the miss count low. When misses climb, the line now tells you why, and it will usually be one of the actions in habit 3. The first turn after lunch will re-read the morning. You cannot change that. How much morning it finds is up to you.
So here is the question to carry into your next session: how much of this morning will your afternoon actually need?
Claude Code Re-sends Your Whole Session Every Turn. Here Is Anthropic’s Playbook for Paying Less. was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.