What Is the Context Window in Claude Code?
The context window in Claude Code is what the model sees on each turn: your messages, its responses, files it read, command and tool outputs, CLAUDE.md, and tool definitions. It has a fixed maximum size. As it fills, cost per turn rises and focus can slip, so Claude Code lets you clear or compact it.
What goes into the context
On each turn the model receives a single context containing the system instructions, CLAUDE.md content, definitions of available tools including MCP servers, the conversation so far, and the results of every tool call in the session: files read, search results, command output, and test logs. Large files and verbose command output fill it quickly.
The window has a maximum size set by the model. Claude Code shows how much is in use and offers commands to inspect what is taking up space.
What happens as it fills
Each turn sends the whole context again, so cost grows with session length, although prompt caching reduces the cost of the repeated portion. Attention also spreads across more material: details from early in the session, stale assumptions, and outdated file contents compete with what matters now. Near the limit, Claude Code compacts the conversation automatically, summarising earlier turns to make room.
Compacting and clearing
Compaction replaces the detailed history with a summary, keeping the gist of decisions and progress while freeing space. It can be triggered manually, optionally with guidance about what to keep. Summaries lose detail, so important decisions are better captured in files or commits than left to compaction.
Clearing starts a fresh conversation. It is the right move when switching to an unrelated task, or when a session has drifted. With a good CLAUDE.md and retrieval, a fresh session recovers context quickly.
Signs the context is hurting you
Watch for the agent forgetting a decision made earlier in the session, repeating approaches that already failed, referring to old versions of files you have since changed, or giving vaguer answers than at the start. Rising cost per turn is another signal. When these appear, compact with guidance about what matters, or capture key decisions in a file and start a fresh session that reads it.
Context and project memory work together
A fresh session is only cheap if the agent can rebuild its understanding quickly. A concise CLAUDE.md with commands and constraints, decision records in the repository, and retrieval over documentation and code make that possible. With those in place, clearing context costs little and keeps sessions sharp. Without them, every reset means re-explaining the project, which pushes people to keep bloated sessions alive.
Large files and generated output
A single large file, a lockfile, a minified bundle, or a long log can consume a large share of the window in one read. Keep generated and vendored directories out of the agent's searches where your setup allows, ask for specific sections of large files, and pipe verbose command output through filters that keep only errors or summaries. These small habits often make more difference to session quality than any setting.
Keeping context lean
- Keep CLAUDE.md short; it is present on every turn.
- Remove MCP servers you do not use; their tool definitions take space too.
- Ask for targeted reads, such as specific functions or line ranges, rather than whole large files.
- Limit noisy command output, for example by running only the relevant tests.
- Use subagents for broad searches, so exploration happens in a separate context and only results return.
- Use retrieval over docs and code so the agent pulls relevant passages instead of reading everything.
Frequently asked questions
- How big is Claude Code's context window?
- It depends on the model in use, and sizes change as models are updated. Claude Code reports how much of the window is in use during a session. Rather than relying on a fixed number, watch usage and compact or clear when sessions grow large or start to lose focus.
- What does compact do in Claude Code?
- Compaction summarises the earlier conversation and replaces the detailed history with that summary, freeing space in the context window while keeping the main decisions and progress. It happens automatically near the limit and can be run manually. Details can be lost, so record important decisions in files.
- Should I clear the context or keep going?
- Clear when switching to an unrelated task, or when the agent repeats mistakes, forgets recent decisions, or seems distracted by old material. Keep going when you are mid-task and the context is still relevant. Fresh sessions are cheap when project memory and retrieval are set up well.
- Do MCP servers use context window space?
- Yes. The definitions of tools from each connected MCP server are included so the model knows what it can call, and tool results add more as they are used. Connecting many servers consumes space on every turn, which is a reason to keep only the servers you actually use.
- Does a larger context window make Claude Code better?
- It allows longer sessions and larger inputs, but more context is not automatically better. Cost per turn grows with context size, and relevant details can be diluted among irrelevant ones. A lean context with the right information usually outperforms a large one filled with everything the session has touched.
- Does clearing the context lose my work?
- No. Clearing resets the conversation, not the files. Edits, commits, and documents remain on disk. What is lost is the conversational history and anything only discussed, so write important decisions into files or commit messages before clearing. A fresh session can then read them back as needed.