Anthropic Warns Developers to Avoid Wasting Tokens in Claude Code Sessions

icon MarsBit
Share
AI summary iconSummary
Anthropic has issued a warning to developers using Claude Code to minimize token waste and prevent rising costs. The company recommends ending sessions after completing tasks, pre-setting model parameters, and using file references instead of manually entering paths. Output tokens are costly, and effective cache management is critical for controlling expenses. Avoid actions such as switching models or compacting sessions, which trigger cache invalidation. Poor practices can lead to cost spikes due to repeated context uploads. As news around token launches continues to influence the market, developers should take these steps seriously to maintain efficiency.

Claude Code

Just now, Anthropic published a blog post.

The key message is: Guys, stop wasting your tokens—we can't watch it anymore!

Claude Code

To this end, the official has carefully listed six money-saving tips, presented here for your reference:

1. Clear the conversation once the task is done. After fixing a bug, clear the current chat to prevent files and command outputs from the previous task from carrying over and unnecessarily consuming context.

2. Set the model and inference effort level at the start. Switching mid-conversation will invalidate all previously accumulated prompt caches, and the entire conversation history must be recalculated at full cost.

3. Use @ to reference files instead of typing paths manually. Attach files directly to your message using @, so Claude doesn’t need to make an additional tool call to read them. If you only type the filename, Claude may search through multiple files to find the right one, and all these operations will be saved in the conversation history, carrying over to every subsequent turn.

4. Add a quiet flag to commands that produce excessive output. In CLAUDE.md, include a configuration similar to --reporter=dot to limit test output to a few summary lines instead of hundreds of detailed lines. Shorter output consumes less context.

5. Run /compact before taking a break. Compressing while the conversation is still in cache costs only one-tenth of the normal price. If you wait until after your break and the cache has expired, you’ll need to reread everything at full cost and compress again.

6. Delegate large output tasks to the sub-Agent. The sub-Agent runs within its own independent context window and returns only the conclusion; any files it reads or commands it executes during the process will not enter your main conversation.

Claude Code

The Life and Times of a Token

Use Claude Code for work, with API usage billed per request; subscription plans range from $20 to $200 per month in three tiers.

According to official estimates, developers spend an average of $13 in tokens per day, totaling between $150 and $250 per month.

This is just an average. Fixing the same bug can cost several times more depending on how the question is asked.

Moreover, each conversation round resends all previous content, making longer conversations increasingly expensive.

To understand where this money is spent, we need to start with the token's pricing logic.

Claude Code

Every time you enter a command in Claude Code, two things happen behind the scenes.

The first step is called prefill, where the model reads your entire request at once—including the system prompt, CLAUDE.md, your message, and everything accumulated from previous conversations. All of these are input tokens.

The second is decoding, which is the process by which the model generates text one token at a time, including its reasoning, tool usage, and the final text you see—all of these are output tokens.

The key difference is here.

Prefilling is performed in parallel, processing all input tokens through the GPU at once. Decoding is sequential, requiring a separate model inference for each generated token. A 200-token response thus involves 200 independent computations.

It’s therefore not hard to understand why output tokens cost five times more than input tokens.

Claude Code

On this basis, the final bill depends on two factors.

First is the model, which determines the price per token.

Opus 5, input $5 per million tokens, output $25.

Sonnet 5, deposit $2, receive $10.

Haiku 4.5, input $1, output $5.

Second is reasoning strength, which determines the number of tokens.

In a single session, most of the output tokens are reasoning tokens, and the reasoning intensity controls this quantity. Higher reasoning intensity causes the model to think longer, generating more reasoning tokens—the difference between max and low can be several-fold.

Use Sonnet for simple tasks; reserve Opus for tough challenges. Spending money on a sledgehammer to crack a nut is the worst waste.

Claude Code

The tip cache is the biggest money-saving tool.

Another major variable in token pricing is caching.

Each request from Claude Code begins with the same prefix: the system prompt, tool definitions, CLAUDE.md, and the conversation history.

If the prefix of this request is identical byte-for-byte to the previous one, the server skips recalculation and directly loads the previous result.

Cache reads require only 10% of the normal input price, saving 90% directly.

Writing to cache costs up to 2x more, but writing occurs only once, and each subsequent round benefits from 0.1x reading costs.

For example.

If your conversation history is 50,000 tokens, without caching, each round would require paying full price just to reread those 50,000 tokens. But if the cache is hit, the same 50,000 tokens cost only one-tenth as much.

A single conversation lasting twenty to thirty rounds can accumulate discounts from cache hits that amount to astronomical sums.

This is your largest opportunity to maximize your gains.

Claude Code

However, caching has a critical weakness: it must match continuously from the first byte of the request; any change in between invalidates everything from that point onward.

Specifically, there are six scenarios:

1. /model switch model: Each model has independent caching. Switching from Sonnet to Opus will repopulate the entire conversation history at Opus’s pricing rate, with no discount.

2. /effort switch reasoning strength: Reasoning strength is also part of the cache key; after switching, the entire conversation history must be recalculated.

3. Toggle Fast mode: The effect is the same as the previous two—cache is immediately invalidated.

4. /compact Compress conversation: The conversation is rewritten as a summary, and the original content no longer matches; the old cache is discarded.

5. Expiration: Cached data for subscribed users is kept alive for 1 hour; API users default to 5 minutes. After expiration, a full recalculation is triggered in the next cycle.

6. Restore old session: The cache has long been cleared due to the extended time elapsed, so a full-price recalculation is almost 100% necessary.

The bad news is that landing just one means the entire conversation history resets to 0.1x.

The good news is that when you know what causes cache invalidation, you’ll know how to preserve it.

For example, lock the model and inference intensity at the start of the session and maintain it throughout. Avoid performing /compact while the cache is still hot; instead, run it when you're preparing to take a break.

Here, there's also a hidden trap.

In OpusPlan mode, the model is switched every time you enter or exit a plan. Entering invalidates the cache once; exiting invalidates it again. Each toggle back and forth results in a full-price prefill.

Your session is quietly gaining weight.

Caching reduces the cost of sending duplicate historical data to one-tenth.

But there is one thing it cannot help with: your history itself is expanding round after round.

Each time Claude reads a file, the file content is appended to the conversation. Each time Claude runs a command, the output is also appended. From the point of appending onward, all subsequent rounds include this content.

The 40th conversation is resending all accumulated content from conversations 1 to 39.

This growth is approximately quadratic, O(n²).

Claude Code

Claude Code has a fallback mechanism.

If the command output exceeds 30,000 characters, it will not be included in the conversation but instead written to a temporary file, with only a summary sentence displayed in the conversation. Outputs under 30,000 characters are handled normally.

For example, after a test framework completes, it prints 400 lines of pass records, each with dozens of characters, totaling less than 30,000—this does not reach the threshold.

Thus, these 400 lines remained unchanged in the conversation history and were resent again in every subsequent round.

For this, the Anthropic blog offers several practical methods for slimming down.

1. @Reference file.

Do not manually enter paths—let Claude find them on its own. Using @ to reference a file attaches it directly to the message, eliminating the need for an additional read operation.

If you only mention the filename, Claude might first run a grep search, open several files to find the right one, and all these attempts will be added to the conversation history, unnecessarily increasing costs.

Claude Code

2. Add the quiet flag to the noisy command.

In CLAUDE.md, add a line: "run tests with npx vitest run --reporter=dot" to output only a few dot results instead of hundreds of lines of details every time you run tests. One minute of setup saves hundreds of lines of context in each session.

3. Isolate large output tasks by subagent.

The subagent runs in its own isolated context window, returning only the final answer—any files read or command outputs during the process are discarded. Ideal for tasks like “check the logs for anomalies” or “review this large file”—you only need the conclusion, not the process.

Claude Code

And most importantly, one more thing.

4. /clear task.

After fixing a bug, use /clear to start the next task. Files, command outputs, and intermediate explorations from the previous bug are unrelated to the next task, but if not cleared, they continue to occupy space and consume tokens in every subsequent round.

If you don't want to clear everything, /compact can compress the conversation into a summary, reducing 10,000 to 20,000 tokens down to 1,000 to 3,000.

Claude Code

In addition, the blog mentioned a lesser-known but free command: /rewind.

If the last few rounds went off track, /rewind will simply cut those rounds without affecting any of the earlier cache.

Claude Code

Managing tokens is also a developer's responsibility.

After breaking down these operations, you'll notice a pattern: the people writing code are developing a new set of skills.

It has nothing to do with frameworks or languages, but rather knowing which model to choose, how to manage context, how to preserve cache, and what level of inference intensity is appropriate.

These capabilities didn't exist a year ago. But now they determine whether you spend $3 or $30 on the same task.

Anthropic itself is the best example.

They wrote 80% of their code with AI, increased their code merge volume eightfold in a year, and achieved a 52x speedup in benchmark tests. At this level of AI usage, if no one manages the token, the inference costs alone could exhaust the entire budget.

From this perspective, this blog is less about money-saving tips and more about a new instinct that coders need to develop in the age of AI—

Know what each of your actions consumes, and learn how to get more done with the same budget.

Those who understand it don't just gain a few dollars' worth of tokens.

Reference materials:

https://claude.com/blog/maximizing-the-value-of-your-claude-code-sessions

Edited by Moses

This article is from the WeChat public account "New Intelligence Yuan," authored by ASI Revelation.

Disclaimer: The information on this page may have been obtained from third parties and does not necessarily reflect the views or opinions of KuCoin. This content is provided for general informational purposes only, without any representation or warranty of any kind, nor shall it be construed as financial or investment advice. KuCoin shall not be liable for any errors or omissions, or for any outcomes resulting from the use of this information. Investments in digital assets can be risky. Please carefully evaluate the risks of a product and your risk tolerance based on your own financial circumstances. For more information, please refer to our Terms of Use and Risk Disclosure.