Manage Claude Code Tokens and Context
Monitor context usage, compact conversations effectively, and prevent runaway token costs during long development sessions.
~8 min read
One of the most noticeable differences between using Claude in a browser and using Claude Code in a terminal is conversation duration. In a terminal, a single session might span four hours of continuous coding, thirty test runs, twelve file edits, and several deep refactors.
Every file read, terminal command output, error traceback, and assistant response stays in the context window. As that transcript grows, two things happen: your token burn rate increases on every turn, and the model's attention begins to diffuse across thousands of lines of historical clutter.
Understanding how to manage your context window is not just about saving money: it is about maintaining high reasoning quality throughout an entire workday.
The economics of context window bloat
Modern frontier models support 200,000 tokens of context, and prompt caching significantly reduces repeated input costs. But prompt caching is not free, and context size directly impacts latency.
When your session holds 120,000 tokens of history, every subsequent prompt requires Claude Code to process that entire context. If that history contains 80,000 tokens of failed build logs and discarded code snippets from three hours ago, you are paying the model to read obsolete information that no longer matters to your current task.
How /compact actually works
Claude Code provides the `/compact` command to distill long conversations without losing current progress. When you run `/compact`, Claude Code generates a structured summary of the session history, discards the raw turn-by-turn logs, and resets the active context with only the distilled summary.
Notice the technique in the terminal session above: passing an instruction directly to `/compact`. If you simply type `/compact`, Claude summarizes the entire transcript generically. By adding a specific focus ("focusing on the auth refactor..."), you tell the summarizer exactly which decisions and active threads must be preserved.
Choosing between /compact, /clear, and /rewind
Experienced operators navigate between three distinct memory management commands depending on what their workflow demands:
- /compact: Shrinks transcript volume while preserving active task context, architectural decisions, and current goals. Use this when you are halfway through a complex task and context exceeds 50 percent.
- /clear: Completely wipes the conversation history clean. Your working directory files remain untouched, but Claude forgets everything said earlier. Use this when shifting to an entirely unrelated feature or bugfix in the same repo.
- /rewind: Steps backward in conversation history, discarding turns that went down an unproductive path. Use this when an approach failed and you want to branch from an earlier point without retaining the error logs.
Surgical reads vs whole-directory dumps
The single fastest way to blow through your context budget is asking Claude to read whole directories. Asking "look through src/ and find where users are created" can load forty files into context in one turn.
Monitoring token thresholds throughout the day
Make checking `/context` a routine habit. When context crosses 60 percent, run a focused `/compact`. If you finish a task, commit your changes and run `/clear`. Treating context window space as an active resource keeps Claude fast, accurate, and cost-effective.
Get new guides in your inbox
One task, one guide, done fast. Practical Claude Code skills, zero noise.


