Better context management to avoid wasting tokens
Anthropic explains how /clear, /compact, prompt caching, @-mentions, and subagents can reduce token usage in Claude Code.
Two Claude Code sessions that produce exactly the same result can consume very different amounts of tokens. Anthropic breaks down the mechanisms behind those differences and recommends limiting accumulated context, preserving the prompt cache, and avoiding carrying information that is no longer useful from one task to the next.
Each request sends the model all of the context already present in the session: the system prompt, `CLAUDE.md` instructions, files that have been read, tool results, command outputs, and conversation history. Previously seen elements can be retrieved from the prompt cache, but they are still sent and continue to take up space in the context. Anthropic says reading from the cache costs about 0.1 times the price of a regular input token, while writing to the cache can cost up to twice as much.
The choice of model and effort level also affects cost. Output tokens, which include reasoning and tool calls, are described as costing roughly five times more than input tokens. Changing `/model` or `/effort` in the middle of a conversation can also invalidate the prompt cache and trigger a full reprocessing of the context. Anthropic therefore recommends setting these parameters at the beginning of a session or immediately after a `/clear`.
The `/clear` command is one of the main ways to separate tasks. Once a piece of work is finished, starting with an empty session prevents previous files, logs, and searches from carrying over into subsequent requests. For a single long-running task, `/compact` replaces the conversation history with a summarized version to reduce context. Anthropic specifically recommends using it before a long break, since the prompt cache expires after one hour on a subscription. With an API key, the default is five minutes, with an option to extend that duration.
How files are provided can also eliminate intermediate steps. With an @-mention, Claude Code attaches the file directly to the first message, avoiding a `Read` call or a search to locate it. Repeating the same @-mention later is unnecessary, however, because the file is already in the context and may end up being attached a second time.
Command outputs are another source of context buildup. Tests, builds, or Git logs are added to the conversation and remain there for subsequent turns. Anthropic recommends using options that reduce output whenever possible, or handing particularly noisy operations off to a subagent. The subagent works in a separate context and returns only its final result to the main session, preventing all of its file reads and command outputs from remaining in the primary context.
The `/context` command can also be used to inspect what is loaded at the start of a session, including `CLAUDE.md` and MCP tool definitions. Anthropic recommends keeping those instructions limited to what is actually needed, moving workflow-specific guidance into skills that load only when required, and disabling MCP servers that are not useful for the current task.
Anthropic also distinguishes `/rewind` from `/compact`. When only the most recent exchanges have become unnecessary, rewinding to an earlier point preserves the previous portion of the cache, whereas compacting rewrites the conversation and creates a new context. The goal is therefore not simply to generate fewer tokens, but to reduce how many tokens remain present across many turns and to reserve the most expensive models or reasoning levels for tasks that genuinely require them.