Claude Code Tokens: Where They Go & Why Output Was Cut
In this article
This article explains where Claude Code tokens are spent and why your output may have been cut short. You'll learn how token accounting works, what consumes tokens behind the scenes, and the practical steps to reduce waste and avoid truncation.
How Token Accounting Works in Claude Code
Claude Code, like other AI coding assistants, charges for tokens rather than characters or words. A token is roughly four characters of English text, but the exact count depends on the model's tokenizer. For example, the word "Claude" is one token, while "tokenization" might be three. Every request you make sends your entire conversation history to the model—every previous message, every code snippet, every tool result—and each of those is counted as input tokens. The model's response is counted as output tokens. Both consume your context window and your billing quota.
When you see a message like "Output was cut off because the maximum token limit was reached," it means the combined input and output tokens for that request exceeded the model's maximum context length. This is not a bug; it's a hard limit set by the model architecture. For example, Claude 3.5 Sonnet has a 200,000-token context window. If your conversation history plus the current response would exceed that, the response is truncated.
Where Tokens Actually Go
Tokens are consumed in several places you might not expect. The largest consumer is usually the conversation history. Every time you ask Claude Code to make a change, it re-reads the entire prior conversation, including all previous code diffs, error messages, and your comments. A long debugging session can easily eat 50,000 tokens just in history. Tool calls also consume tokens: each time Claude Code runs a command, reads a file, or searches a directory, the tool's output is added to the conversation. A single grep that returns 500 lines can be 2,000 tokens. System prompts and instructions, including the built-in system prompt and any custom instructions you've added, are counted as input tokens on every request. Even the code you paste into the chat is tokenized.
Output tokens are also spent on formatting. Claude Code often includes markdown, code fences, and explanatory text around the actual code changes. That verbose commentary is useful, but it counts toward your output limit. If you ask for a complete file rewrite, the entire file is output, which can be thousands of tokens.
Why Output Gets Cut Off
Truncation happens when the total tokens in a single request exceed the model's maximum context length. The model generates tokens one by one, and if it reaches the limit mid-sentence, it stops. This is more likely to happen with:
- Long conversations with many back-and-forth exchanges.
- Large files that are read entirely into context.
- Requests that ask for very long outputs (e.g., "rewrite the whole file").
- Complex tasks that require many tool calls, each adding to the history.
Another cause is the output token limit, which is often set lower than the context maximum. For example, a model might have a 200k context window but a 4,096-token output limit. Even if the total context isn't full, the response can be cut off if it exceeds the output limit. In Claude Code, you can adjust this with the --max-tokens flag or the ANTHROPIC_MAX_TOKENS environment variable.
How to Reduce Token Waste
You can significantly reduce token usage with a few habits:
- Start a new session for a new task instead of continuing a long conversation.
- Use the
/clearcommand to reset the conversation history when you're done with a topic. - Ask Claude Code to focus on specific functions rather than entire files.
- Use the
--no-verboseflag to reduce the amount of explanatory text in outputs. - Keep your custom instructions short and to the point.
You can also monitor token usage with the --debug flag, which shows token counts for each request. This helps you see exactly where tokens are going.
Common Misconceptions
Many users think that the token count shown in the CLI is the only thing that matters. In reality, the token count is per request, not cumulative across a session. Each request includes the entire history, so a long session can have many requests, each costing a large number of tokens. Another misconception is that cutting off output is a bug. It's a deliberate safeguard to prevent the model from generating nonsense beyond its limits. Also, some believe that reducing the output token limit will save money—it does, but it also increases the chance of truncation, so you need to balance cost and completeness.
Practical Tips for Long Outputs
If you need a long output, such as a full file rewrite, break it into smaller parts. Ask Claude Code to write the first half, then the second half. Alternatively, use the --output-format flag to get a more compact response. You can also increase the output token limit if your model supports it, but be aware that this may increase cost. For very large files, consider using a script to apply changes rather than asking Claude Code to output the entire file.
Frequently Asked Questions
Why does my output stop mid-sentence?
This happens when the model reaches the maximum token limit for the response. The limit is either the model's context window or the output token limit you've set. Check your --max-tokens setting and the size of your conversation history.
Does the token count include my entire conversation?
Yes, every request sends the full conversation history as input tokens. This is why long sessions use more tokens than you might expect. To reduce this, use /clear to start fresh.
Can I see how many tokens I'm using?
Yes, run Claude Code with the --debug flag. It will display token counts for each request, including input and output tokens.
Is there a way to increase the output limit?
You can set the --max-tokens flag to a higher value, or set the ANTHROPIC_MAX_TOKENS environment variable. However, the model has a hard maximum context length that you cannot exceed.
Why does Claude Code re-read files I already showed it?
Claude Code does not have memory between requests. It only knows what's in the current conversation context. If you want it to remember a file's content, it must be included in the context. To save tokens, avoid pasting large files unless necessary.
Conclusion
Understanding token usage is key to getting the most out of Claude Code. By managing your conversation history, using flags wisely, and breaking up large tasks, you can minimize truncation and control costs. Always monitor your usage with --debug to see where tokens are going.