Claude Code context window full? Compact, clear or restart
When Claude Code or another coding agent runs low on context, choose between compacting, clearing and a new session, and keep decisions in a handoff.
When Claude Code’s context window is nearly full, it acts on its own: it clears older tool output first, then summarizes the conversation if needed. Early instructions can be lost, so choose first. If you’re still on the same task, run /compact with a note about what to keep. If you’re moving to unrelated work, run /clear. If the agent keeps forgetting decisions, write a short handoff and start a new session from it.
Other coding agents may use different commands, but the same choices apply. Mono can show how full the context is when the agent reports it, but the agent does the compacting and clearing.
1. Know what fills the context window
The context holds everything the agent works from: your messages and its replies, files it has read, command and test output, tool lists from connected MCP servers, and instruction files loaded at the start. One long test log can outweigh everything you’ve typed.
Signs that it’s filling up:
- The agent breaks a rule you gave it earlier.
- It asks a question you’ve already answered.
- A warning says the context is running low.
In Claude Code, /context shows what’s using space. Its overview of how it works explains what happens near the limit.
A made-up example: two hours into moving 30 files in “tidy-recipes” from an old date helper, oldDate(), to a new formatDate(), the agent asks again which library to use. /context shows the window nearly full.
2. Choose between compacting, clearing and a new session
Compacting replaces the conversation with a summary in the same session. Clearing or starting a new session drops the conversation, but instruction files load again. Each choice loses something:
| Situation | What to do | What you lose |
|---|---|---|
| Same task, going well | Compact with a focus note | Details the summary skips |
| Unrelated work next | Clear, or start a new session | The whole conversation |
| The agent forgets decisions | Write a handoff, start a new session | Whatever the handoff leaves out |
A focus note tells the summary what to keep: /compact Focus on date decisions and failing tests. Claude Code’s guide to managing costs shows this, and suggests /rename before /clear so you can reopen the session with /resume.
In the example, the agent has already forgotten one decision, so write a handoff.
3. Write a handoff before you reset
A handoff is a short note for the new session. Write it yourself or correct the agent’s draft:
Goal: Replace oldDate() with formatDate() in recipes/ (30 files).
Done: 18 files, on branch tidy-dates.
Decisions: formatDate() uses Intl.DateTimeFormat, so no new library.
Keep oldDate() for importing v1 files, which use the old format.
Open problem: The recipes/print.ts test has failed since the change.
Next step: Fix print.ts, then move the remaining 12 files.Give each decision its reason, or the next session may undo it. Save the note in the project or your notes, and export the conversation in case you need its details.
Then run /clear or start a new session in the same project, and paste only the handoff, not the transcript.
4. Move standing rules out of the chat
Some corrections matter beyond one task. If you keep repeating “use the project’s date helper” or “run tests with the project’s script”, put the rule in the project’s instruction file, such as AGENTS.md or Claude Code’s CLAUDE.md. New sessions read that file, so a reset doesn’t lose it.
Keep the file short, because it loads into every session. The costs guide suggests keeping CLAUDE.md under 200 lines. Progress such as “18 of 30 files” stays in the handoff. The AGENTS.md guide covers what to include.
The example’s v1 rule goes there too: it lasts as long as v1 files do.
5. Reduce what each turn adds
A smaller context lasts longer. Before each request:
- Name the file and function, not “fix the dates”.
- Paste the relevant error lines, not the whole log.
- Run only the tests you need, and show only failures.
- Disconnect MCP servers the project doesn’t use.
- Hand broad searches to a subagent where the agent supports it.
- Keep one task per session.
The costs guide covers most of these, including a hook that filters test output.
6. Check the agent after a reset
Before the new session edits anything, ask it to restate the goal, decisions and next step, and compare the answer with your handoff. In the example, it should name the v1 rule unprompted. If it misses something, correct it now. Then review its first diff, the print.ts fix, before it moves on. The code review guide has a checklist.
In Mono, when the agent reports usage, a small ring above the message box shows the context used. It turns from green to orange at half and to red at 80 percent, and pressing it shows “Context: used / total”. Typing “/” lists the slash commands the agent offers. Under the Agent Client Protocol, advertising them is optional. For a fresh start, save the old conversation with Export conversation, then choose New session on the project card (from your phone too, when the computer is connected). Mono isn’t available yet, but you can join the waitlist.
