Last updated: July 2026
To reduce Claude Code's context window, run /compact to summarize and shrink history, use /clear between unrelated tasks, keep your CLAUDE.md lean, tell Claude which specific files to read instead of the whole repo, and delegate research to subagents so their output never lands in your main thread.
Claude Code's context window is the total pool of tokens the model sees on every request. It is not just the message you type. Four things pour into it, and most of them grow silently as you work:
Read, Grep, or glob result gets dropped into context in full. Ask it to "read the whole repo" and you can inject tens of thousands of tokens in one move.Bash, test runs, build logs, and searches all land in context. A single noisy npm install or a long stack trace can eat thousands of tokens.That last point is what surprises most developers. Nothing leaves the context on its own. Everything you and Claude add early in a session keeps riding along, turn after turn, quietly inflating the payload. Understanding that token optimization is really about managing this accumulating payload is the key to everything below.
A full context window hurts you in two distinct ways: your wallet and your output quality.
Because history re-sends every turn, a token you add on turn 1 gets billed again on every subsequent turn. Over a 40-turn session, a 5,000-token file read that stays in context can be transmitted dozens of times. Bigger context also means slower responses — the model has more to process before it can answer. This is why context size is one of the biggest levers on your Claude Code pricing and overall AI coding agent costs. If you want to see how the numbers move, the token calculator makes the compounding effect concrete.
The subtler cost is quality. As the window fills, answers get worse — a phenomenon commonly called context rot. When the context is crowded with stale file contents, old tool output, and history from tasks you finished an hour ago, the model spends attention on irrelevant tokens and is more likely to lose the thread of your actual instructions. A lean context is not just cheaper; it is measurably sharper. Reducing the window is therefore a quality strategy as much as a cost one.
Here are the practical moves, roughly in order of impact. Most take seconds and pay off immediately.
When a session gets long but you still need continuity, run /compact. It replaces the bulky conversation history with a concise AI-generated summary, preserving what matters while reclaiming a large share of the window. You can steer it — /compact focus on the auth refactor we just did — to keep the summary tight around the work that still matters. Compact when you feel responses slowing down or the context indicator climbing past two-thirds.
When you switch to something genuinely new — a different feature, a different bug — do not keep the old conversation around. Run /clear to wipe the context and start fresh. Carrying the debugging session for feature A into your work on feature B gives you all the cost and none of the benefit. As a rule: new task, new context.
Because CLAUDE.md is injected on every turn, every line you cut saves tokens across the entire session. Trim it to durable, high-signal facts: build commands, architecture notes, hard rules. Move rarely-needed detail into separate docs that Claude reads only on demand. A tight 40-line CLAUDE.md beats a sprawling 400-line one that repeats things the model can infer from the code.
"Read the whole repo and figure it out" is the single most expensive instruction you can give. Instead, point Claude at the exact files or directories that matter: "Read src/auth/session.rs and its test." Specific reads keep the window small and, as a bonus, focus the model on the code that actually matters — a double win against context rot.
When you need broad exploration — "find everywhere we validate tokens" — delegate it to a subagent. The subagent burns through files in its own context window and returns only a short conclusion to your main thread. All those file reads and dead-end searches never pollute your primary session. This is the cleanest way to do heavy research without paying for it on every subsequent turn.
If a file is already in context, do not ask Claude to read it again — the content is right there. Re-reading duplicates the entire payload and pushes you toward context rot faster. The same applies to re-running an identical search or command: each duplicate tool result is injected fresh and then re-sent every turn afterward. Duplicate tool calls are pure waste.
Ask for surgical edits rather than having Claude reprint whole files. A targeted diff adds a handful of tokens; regenerating a 300-line file adds all 300 to the output and the history. Precise edits keep both the response and the growing context small.
When you finish a unit of work, commit it and then /clear. The commit is your durable record; you no longer need the whole conversation that produced it living in context. Starting each feature from a clean window is the most reliable way to keep sessions fast and sharp over a long day.
Terse for Claude Code attacks the context problem from two light-touch angles. First, it compresses the prompts you type before they ever enter the conversation — stripping filler, hedging, and padding on-device in under a millisecond, so the tokens you contribute stay minimal and, because history re-sends, stay minimal across every turn.
Second, Terse watches your Claude Code sessions and flags redundant work: duplicate tool calls and repeated file reads that quietly inflate your context. When Claude reads the same file twice or re-runs a search it already ran, Terse surfaces it so you can catch the waste. It is a nudge, not a takeover — the goal is to make the invisible growth of your context window visible.
Terse compresses the prompts you type and flags duplicate tool calls and file reads in your Claude Code sessions. On-device, zero latency, no API calls.
Terse for Claude CodeClaude Code's context window fills with your CLAUDE.md, every file it reads, tool output, and a conversation history that re-sends on every turn. A bloated window costs you twice — real dollars from re-billed tokens, and degraded answers from context rot. The fixes are simple and habitual:
Do these consistently and you will spend less, get faster responses, and keep Claude sharp deep into a working session. For the cost side of the picture, dig into Claude Code pricing and the broader AI coding agent costs breakdown.