Save Tokens in Claude Code: 4 Context Smart Tricks
This guide shows you four practical ways to reduce token usage in Claude Code by managing context more intelligently. You’ll learn how to keep conversations shorter, avoid re-sending large files, and focus the model on what matters — saving tokens without losing accuracy.
What You’ll Need
- An active Claude Code session (CLI tool)
- Basic familiarity with slash commands and file editing
- Access to your project’s file structure
Step-by-Step
Trick 1: Use /clear to Reset Context Strategically
- When a task is complete and you’re starting a new, unrelated task, type
/clearat the prompt. - Confirm that you want to clear the conversation. This wipes the entire history, freeing up the context window.
- Start fresh with a concise, self-contained prompt that includes any necessary background (e.g., “Refactor the error handling in src/utils.js to use async/await”).
- If you need to keep some context, copy the key details (file names, decisions) into your new prompt manually, rather than letting the old conversation linger.
Trick 2: Use /compact to Summarize Instead of Wiping
- When a conversation is getting long but you still need the thread, type
/compact. - Claude Code will generate a summary of the conversation so far and replace the full history with that summary.
- Review the summary to ensure it captures all critical decisions and open questions.
- Continue working. The summary consumes far fewer tokens than the original transcript.
- Use /compact repeatedly as the conversation grows, rather than waiting until you hit the limit.
Trick 3: Reference Files with @ Instead of Pasting Content
- Instead of copying and pasting a file’s content into your prompt, type
@followed by the file path (e.g.,@src/config.js). - Claude Code will read the file and include only the relevant parts in the context, not the entire file if it’s large — it uses a smart selection mechanism.
- For large files, specify the exact lines you need (e.g.,
@src/utils.js:45-80) to further reduce token usage. - When asking about a specific function, mention the function name and the file reference, so the model can locate it without loading the whole file.
Trick 4: Use /rewind to Remove Unnecessary Turns
- If you notice that a few recent exchanges were off-track or irrelevant, type
/rewind. - Choose the point in the conversation history to which you want to revert. This removes all subsequent turns from the context.
- Confirm the rewind. The conversation is now shorter, and the context window frees up tokens.
- Reissue the last useful prompt, possibly rephrased to be more precise.
Common Mistakes
- Clearing too often: Using /clear at the first sign of a long conversation can lose important context. Only clear when the current task is truly done.
- Not using @ for files: Pasting entire file contents manually wastes tokens and can be error-prone if the file changes.
- Ignoring /compact: Letting conversations run until they hit the token limit forces a less controlled summarization. Compact proactively.
- Keeping irrelevant history: Leaving old, unrelated tasks in the context makes the model less focused and uses tokens on noise.
Tips
- Start each new task with a fresh /clear unless you genuinely need the previous context.
- When you reference a file, be specific about what you want to know. Instead of “Explain this file,” ask “What does the parseConfig function do?”
- Use /compact before asking a complex question that requires deep reasoning, so the model has more room to think.
- If you find yourself repeating instructions, consider creating a CLAUDE.md file with project-specific guidelines — this is loaded once and reused efficiently.
- Monitor the token usage indicator (if available) to see the effect of each trick.
Troubleshooting
Issue: /compact produces a summary that misses important details.
Solution: Before compacting, manually note down any critical facts (file names, exact numbers, decisions) in a separate file or in your next prompt. After compacting, check the summary and re-add anything missing.
Issue: @ file reference loads the entire file anyway.
Solution: For very large files, use line ranges (e.g., @src/app.js:100-150) or ask the model to focus on a specific function. If the file is still too large, consider splitting it or using a more targeted query.
Issue: /clear accidentally wipes context you needed.
Solution: If you realize this immediately, you can sometimes recover by re-issuing the previous prompt with the necessary background. To avoid this, use /compact instead of /clear when you’re unsure.
Issue: The conversation is still using too many tokens even after compacting.
Solution: Check if you have large outputs (like long code blocks) in the history. You can manually delete or rewrite those turns using /rewind. Also, consider breaking the task into smaller, separate sessions.
Frequently Asked Questions
Does /clear permanently delete the conversation?
Yes, /clear resets the session entirely. You can’t undo it, so use it only when you’re done with the current thread.
How often should I use /compact?
Whenever the conversation feels long or you notice the model starting to lose track of earlier details. A good rule of thumb is every 10-15 exchanges or when you switch subtasks.
Will using @ with a large file use fewer tokens than pasting it?
Yes, because Claude Code’s file reference mechanism typically includes only the relevant portions, not the entire file. But for very large files, you may still need to specify line ranges.
Can I combine /compact and /rewind?
Absolutely. For example, you can /rewind to remove a few useless turns, then /compact to summarize the remaining useful history.
Does CLAUDE.md help save tokens?
Yes, because it provides persistent instructions without needing to repeat them in every prompt. It’s loaded once and reused, so it’s more efficient than typing the same context each time.
Is there a way to see how many tokens I’m using?
Claude Code may show token usage in the interface. If not, you can estimate by the length of the conversation and the size of file references. The tricks here will reduce that usage.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.