Claude Code Context Window Full? Fix It Without Losing Work
What to do when Claude Code's context window is full: how auto-compact works, /compact with instructions vs /clear, and a handoff note for a fresh session.

When Claude Code reports that the context window is full, or shows it getting close, you have three real options. Let auto-compact summarize the conversation and keep going. Run /compact yourself with an instruction about what to keep. Or run /clear and start fresh, ideally with a short handoff note so the new session knows where you were.
Which one fits depends on a single question: are you continuing the same task or starting a new one? Same task and the details still matter: /compact with a focus instruction. New task, or a conversation that has drifted so far a summary wouldn't help: /clear, which costs nothing. Multi-session work on one feature: write the handoff note first, then clear. The rest of this page covers each option, the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE setting people ask about, and the mistakes that waste the most tokens.
What a full context window means in Claude Code#
Claude Code sends your full conversation with every request. Every file Claude read, every tool result, every message you typed is in the prompt for the next turn. The Claude Code costs page spells this out: a one-line question in a session that has been open all day still carries the whole conversation, even though prompt caching means most of it is re-read at the cached rate.
The window itself is a property of the model. As of October 18, 2026, the models overview lists a 1M-token context window for Claude Fable 5.1, Opus 5.5, Sonnet 5.5, and Haiku 5.5. That's a lot of room, and a long agentic session will still fill it. Big file reads, verbose test output, and dozens of tool calls add up far faster than the chat text does.
To see what's actually in there, run /context. It shows what is filling the window, which tells you whether the fix is a compaction or a change in how you're working, such as a tool that dumps enormous output on every call.
What auto-compact does#
Compaction is Claude Code's way of freeing space without ending the session. It summarizes the conversation so far and continues from that summary instead of the full history. The manual version is /compact, which the commands reference describes as summarizing the conversation to free space. Auto-compact is the same operation, run for you when the window is close to full.
Two things to understand about it:
- It is a large request. The costs page notes that
/compactreads the conversation it summarizes, so compacting a large context is itself a large request. Auto-compact on a nearly full window is about the most expensive single turn a session produces. - Detail doesn't survive by default. The summary keeps what the model judged important. Exact error text, the line number you were staring at, a decision from 40 turns ago: any of those can collapse into a sentence or vanish. You keep continuity and lose precision.
Auto-compact is fine for long tasks where the recent work is what matters. It's a poor fit when you're deep in a debugging thread and the details are the whole point, which is why the manual version with instructions exists.
Idle compaction, where Claude Code compacts while you're away from the keyboard, is a separate behavior with its own confirmed and unconfirmed details; see what's confirmed about Claude Code idle compaction rather than re-reading it here.
When to use /compact with instructions#
Text that follows a command name becomes its arguments, per the commands reference. So /compact accepts a sentence telling Claude what to preserve:
/compact Keep the failing test output from test_auth.py, the three files I edited under src/auth/, and the decision to use short-lived tokens. Drop the billing module exploration.
Run this yourself before auto-compact gets the chance, and you control what the summary carries forward. That's the main reason to compact manually: you know which parts of the last hour matter and the model doesn't.
For projects where the answer is always the same, the costs page shows a standing instruction you can keep in CLAUDE.md:
# Compact instructions
When you are using compact, please focus on test output and code changes
Claude Code's settings documentation points to CLAUDE.md as the place for standing instructions, and this block applies every time compaction runs, including the automatic kind.
A few practical notes:
- If you type
/compactwhile Claude is mid-response, Claude Code queues it and runs it after the current turn finishes. You don't need to interrupt. - If only one stretch of the conversation is noise,
/rewindcan summarize part of the conversation instead of all of it, or roll code and conversation back to a checkpoint. - Compacting repeatedly on the same huge session multiplies the cost. If you're on your second or third compaction and the summary is getting fuzzy, that's the signal to switch to a handoff note and
/clear.
When /clear is the right call#
/clear starts fresh on a new task while keeping project memory. Your CLAUDE.md files stay in effect, your settings stay in effect, and the conversation history goes away. The costs page makes the key point: when you want a fresh start instead of continuity, /clear costs nothing. There's no summarization request at all.
Use it when:
- The task is done and the next thing is unrelated. There's nothing to carry over except what belongs in
CLAUDE.mdanyway. - The conversation has gone sideways. Claude got stuck on a wrong approach, or the window is full of dead ends. A summary of a confused session is a confused summary.
- You've already written a handoff note, so the fresh session has what it needs.
Typing /new highlights /clear in the command menu through its alias, if that's the name your fingers remember. And if you clear and then realize you needed the old thread, /resume returns to an earlier conversation.
Here is the decision in one table:
| Situation | Use | Why |
|---|---|---|
| Same task, details still matter | /compact with an instruction |
Keeps continuity; you pick what survives |
| Same task, only one noisy stretch | /rewind |
Summarizes part of the conversation or rolls back |
| Side question you don't want in history | /btw |
Answers without adding to the conversation |
| New task, or a session that went sideways | /clear |
Free; CLAUDE.md memory stays |
| Multi-session feature work | Handoff note, then /clear |
You choose what the next session knows |
| Not sure what's eating the window | /context |
Shows what's filling it |
The handoff note pattern#
The weakness of any summary is that something else decided what mattered. A handoff note flips that. Before the window fills, you ask Claude to write a short file describing the state of the work, you check it, you /clear, and the next session reads the file. Nothing is lost that you didn't choose to lose, and the fresh session starts small.
Step one, while there's still room in the window, send a prompt like this:
Write a handoff note to HANDOFF.md for a fresh session. Include: the goal, what's done (with file paths), what's in progress, decisions made and why, open questions, how to run the tests, and the exact next step. Keep it short. Don't repeat anything already in CLAUDE.md.
Step two, read the file. Fix anything wrong. This is the one moment where a short review saves a whole session of confusion.
Step three, run /clear, then:
Read HANDOFF.md and continue from "Next step". Don't redo anything listed under "Done". Update HANDOFF.md when you finish a step.
The structure matters more than the prose. This script prints a skeleton with the sections that tend to matter; swap in your own task:
# Print a handoff note skeleton for a fresh Claude Code session.
sections = {
"Goal": "Add refresh-token rotation to the auth service.",
"Done": [
"src/auth/tokens.py: issue short-lived access tokens",
"tests/test_tokens.py: 6 tests passing",
],
"In progress": ["src/auth/refresh.py: rotation on use, not yet wired to the router"],
"Decisions": ["Short-lived tokens over long sessions: simpler revocation."],
"Open questions": ["Reuse detection: revoke the whole family or just the pair?"],
"How to test": ["python -m pytest tests/ -q"],
"Next step": ["Wire refresh.py into src/auth/router.py and add a test for reuse."],
}
lines = ["# Handoff", ""]
for title, body in sections.items():
lines.append(f"## {title}")
if isinstance(body, str):
lines.append(body)
else:
lines.extend(f"- {item}" for item in body)
lines.append("")
note = "\n".join(lines)
print(note)
print(f"({len(note.split())} words)")
Keep durable facts, such as how to run tests or which directories are off limits, in CLAUDE.md instead of the handoff note. /memory edits it from inside a session. The handoff note is for the state of this piece of work; CLAUDE.md is for the project.
What the docs say about CLAUDE_AUTOCOMPACT_PCT_OVERRIDE#
The setting people search for is CLAUDE_AUTOCOMPACT_PCT_OVERRIDE, an environment variable. Judging by the name, it overrides the percentage of the window at which auto-compact kicks in, so you'd use it to compact earlier, for more headroom at the price of more frequent summaries, or later. Like any environment variable, it goes in the shell you launch claude from, and the settings documentation confirms you can change a setting for a single session from the command line that way.
As of October 18, 2026, the commands, settings, and costs pages don't document this variable's default value, its accepted range, or exactly what happens at the threshold. Check the environment variables reference for the current entry, and try it in a throwaway session before you rely on it.
I'd also question the goal before setting it. If you're reaching for it because auto-compact keeps dropping details you need, a /compact instruction or a CLAUDE.md compact-instructions block addresses the actual problem. Compacting earlier just means more summaries of the same work.
Keeping the window from filling so fast#
The cheapest compaction is the one you never need. Why Claude Code uses so many tokens covers the full picture; these are the pieces that bear directly on a full window:
- Side questions go through
/btw. It answers without adding to the conversation history, so a quick "what does this flag do" doesn't ride along in every later request. - Delegate exploration to subagents. Each subagent sends its own requests, separate from the main conversation's. A subagent that reads 30 files and reports back in a paragraph keeps those 30 files out of your window. See how to create Claude Code subagents.
- Install code intelligence plugins for typed languages. The costs page says a single go-to-definition call replaces a grep followed by reading several candidate files, which is exactly the kind of bulk that fills a window.
- One task per session. Starting unrelated work in the same session means the new task carries the old task's history on every turn until compaction.
/clearbetween tasks is free. - Expect a cache miss after a break. Not a window-size problem, but it's why a long session feels expensive when you come back to it. As of October 18, 2026, the costs page lists the cache lifetime as an hour on a subscription, dropping to five minutes once you're drawing on usage credits, and five minutes by default on an API key. Your first message after a longer break reprocesses the full context. Checking Claude Code usage from the terminal shows how to see what's actually being spent.
This script illustrates the full-conversation-per-request effect with made-up turn sizes. Watch the last column: the total sent over a session grows much faster than the conversation itself.
// Illustrative only: what happens when the whole conversation rides along on every turn.
// Each entry is the tokens a turn adds (your message, Claude's reply, tool results).
const turnSizes = [3000, 12000, 8000, 25000, 4000, 30000, 6000, 15000];
let conversation = 0;
let totalSent = 0;
console.log("turn added context_now sent_so_far");
turnSizes.forEach((added, i) => {
conversation += added;
totalSent += conversation; // this turn's request carries the entire history
console.log(
String(i + 1).padStart(4),
String(added).padStart(8),
String(conversation).padStart(12),
String(totalSent).padStart(12)
);
});
console.log("");
console.log(`Conversation is ${conversation} tokens, but ${totalSent} tokens were sent in total.`);
console.log(`A one-line follow-up now carries ${conversation} tokens of history.`);
Common mistakes#
- Letting auto-compact decide for you in the middle of a debugging thread. If the window is almost full and the details matter, run
/compactwith an instruction now. Once the automatic summary runs, the exact error text may be gone. - Compacting when you meant to start over.
/compacton a session you're about to abandon pays for a summary you won't use./clearis free. - Compacting three times instead of handing off once. Each pass is a large request, and each summary of a summary gets vaguer. Write the handoff note and clear.
- Writing the handoff note after the window is full. By then the details may already be compressed away. Write it at a natural checkpoint, such as tests passing, not when Claude Code forces the issue.
- Putting project facts in the handoff note. How to run tests, conventions, directories to avoid: those belong in
CLAUDE.md, where every session gets them. The handoff note should only describe this task's state. - Treating
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEas the fix. It changes when compaction happens, not what the summary keeps. - Guessing what filled the window. Run
/contextbefore changing anything. The answer is often a single tool or file pattern, and that's a workflow fix rather than a compaction question.
Quick reference#
- Run
/contextto see what's filling the window. - Same task, details matter:
/compactplus a one-sentence focus instruction. - Only one noisy stretch:
/rewindto summarize part of the conversation. - New task or dead end:
/clear. It's free and keepsCLAUDE.md. - Multi-session work: have Claude write
HANDOFF.md, review it,/clear, then "Read HANDOFF.md and continue". - Standing rule: a
# Compact instructionsblock inCLAUDE.md. - Side questions:
/btw, so they never enter the history. - Before setting
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE, check the environment variables reference; the default and range aren't on the commands, settings, or costs pages as of October 18, 2026. - On Pro, Max, Team, or Enterprise plans,
/usageflags behaviors that account for 10% or more of recent usage, such as long context, each with a tip.
Quick answers
What should I do when Claude Code says the context window is full?
If you're continuing the same task, run /compact with a sentence about what to keep, such as the failing test output and the files you changed. If you're switching tasks or the session has gone sideways, run /clear, which costs nothing and keeps your CLAUDE.md memory.
My Claude Code context window is almost full. Should I act before auto-compact runs?
Yes, if the details matter. Auto-compact summarizes on its own terms, while /compact with an instruction, or a handoff note written to a file before /clear, lets you choose what survives.
Does /clear delete my CLAUDE.md or settings?
No. The commands reference describes /clear as starting fresh on a new task while keeping project memory, so CLAUDE.md and your settings stay in effect. Only the conversation history goes away, and /resume can return to an earlier conversation if you need it.
Is /compact free?
No. The costs page says /compact reads the conversation it summarizes, so compacting a large context is itself a large request. /clear is the option that costs nothing.
What does CLAUDE_AUTOCOMPACT_PCT_OVERRIDE do?
By its name, it overrides the percentage of the window at which auto-compact triggers. As of October 18, 2026, the commands, settings, and costs pages don't list its default or accepted range, so check the environment variables reference and test it in a throwaway session first.
Did this solve it?
One tap. No account.
Sorry about that. What was missing?
from 0 readers
Saved you an hour? Send a tip.
USDC or ETH on Base, Ethereum, Arbitrum and more. Keeps the notes free and the examples running.
Network
0xc783bc5c3fa14cEC3f09A22284bC91C5AF0d59e1
On a computer? Scan the code with your phone wallet, or copy the address.
Pick the network your wallet or exchange uses. USDC works on all six; ETH on Base, Ethereum, Arbitrum and Optimism. Don't send on Tron or Solana: this address doesn't exist there. Tips are optional and unlock nothing; every guide stays free.
Discussion
Start the discussion
Next note