Context windows explained: Claude Code, Codex, memory, tokens and largest models

Check and clear context in Claude Code, full windows in Claude and Codex, largest models, memory, tokens, input and output, and why size matters.

On the mic
On the mic

Key takeaways

  • Run /context in Claude Code to see usage by category, and /clear or /compact to free space.
  • When the window fills, Claude Code and Codex compact earlier turns into a summary.
  • The context window covers input and output together, including thinking tokens during generation.
  • Memory persists outside the model and is loaded into context, while the window itself is temporary.
  • Bigger windows help, but retrieval and careful context management usually matter more.

A context window is the maximum amount of text, measured in tokens, that a language model can consider at once, including instructions, conversation history, files and its own reply. Coding agents such as Claude Code and Codex fill it quickly. I build RAG systems such as RAG.NextUpgrad that retrieve only relevant passages to stay within context, so this page covers checking and clearing context in Claude Code, what happens when it fills, the largest windows, memory, tokens, input and output, and why size matters.

How do you check the context window in Claude Code?

Run the /context command inside a Claude Code session. It shows how much of the context window is used and breaks usage down by category, such as the system prompt, tools, MCP tools, memory files and messages, plus remaining free space.

Also asked as: how to check context window in claude code

Claude Code also warns you as the conversation approaches the limit, showing the percentage left before automatic compaction, and a custom status line can display usage continuously. Checking /context helps you spot hidden costs: many connected MCP servers can consume a large share of context with tool definitions before you type anything, and large CLAUDE.md files load in every session. Disable unused MCP servers, trim memory files, and read files selectively rather than whole directories. The /cost command reports token usage for the session.

How does the context window work in Claude Code?

Every request Claude Code sends includes the system prompt, tool definitions, CLAUDE.md memory files and the whole conversation so far, including file contents and command outputs. All of it, plus Claude's reply, must fit within the model's context window.

Also asked as: how does context window work in claude code

As you work, tool results such as file reads, search results and test logs accumulate quickly, so long sessions fill the window. When usage nears the limit, Claude Code automatically compacts the conversation, summarising earlier turns to free space while keeping key decisions. Subagents run in their own separate context windows and return only summaries, which keeps the main session lean. Prompt caching reduces the cost of resending the stable prefix on every turn. The window size depends on the model, commonly 200,000 tokens, with larger options on some models.

How do you clear the context window in Claude Code?

Use /clear to wipe the conversation and start fresh in the same session, or /compact to replace the history with a summary while keeping important details. You can pass instructions to /compact, such as telling it what to keep.

Also asked as: how to clear context window in claude code

Clear context when you switch to an unrelated task, since leftover history wastes tokens and can confuse the model. Compact when you want to continue the same task but the window is filling. Before clearing, ask Claude to write important decisions or next steps into a file, such as a notes file or CLAUDE.md, so they survive the reset. Starting a new session in the terminal also gives a fresh context. Regular clearing keeps responses faster, cheaper and more focused, especially in long coding sessions with many file reads.

What happens when the context window is full in Claude?

In Claude Code, the conversation is automatically compacted into a summary so you can continue. On the API, a request whose input exceeds the window is rejected with an error, and output stops early if it runs out of room.

Also asked as: what happens when context window is full claude

In the Claude apps, very long conversations may be summarised automatically or you may be asked to start a new chat, depending on features and plan. Compaction keeps the gist but loses details, such as exact code snippets or early instructions, so restate critical requirements afterwards. Developers using the API can manage context themselves by trimming old turns, summarising history, using retrieval, or using context editing and compaction features where available. Starting fresh with a short summary often works better than pushing a degraded conversation forward.

What happens when the context window is full in Codex?

OpenAI's Codex CLI shows how much context remains and, as the limit approaches, compacts the conversation by summarising earlier turns. You can trigger this yourself with the /compact command, or start a fresh conversation with /new.

Also asked as: what happens when context window is full codex

Without compaction, requests would fail once the conversation exceeded the model's window. After compaction, details from early in the session may be lost, so keep important plans in files such as AGENTS.md, which Codex reads for project instructions. Long tool outputs, such as test logs and large file reads, fill context fastest, so ask for targeted reads and summaries. When switching tasks, start a new conversation rather than carrying irrelevant history. The same habits apply to Claude Code and other coding agents, since they all share the same underlying limit.

Which model has the largest context window?

Among widely available models, Meta's Llama 4 Scout advertises a window of up to 10 million tokens, while Google's Gemini models, OpenAI's GPT-4.1 and some Claude models offer around one million tokens. Limits change often, so check current documentation.

Advertised size is not the same as usable quality. Models often recall facts less reliably from the middle of long contexts, a pattern documented in the Lost in the Middle study by Liu and colleagues, and cost and latency grow with input length. Long contexts suit whole-codebase analysis, long documents and video, while retrieval remains cheaper and more precise for large knowledge bases. Test your own task at the lengths you need before relying on a huge window. For many applications, a well-built RAG pipeline with a smaller window beats stuffing everything into one prompt.

What is the difference between a context window and memory?

The context window is the text the model sees in a single request, and it is gone afterwards. Memory is information stored outside the model, such as saved facts, files or databases, and selectively loaded back into context when needed.

Also asked as: difference between context window and memory

Models have no persistent memory between requests on their own; every call starts from what is in the context window. Applications create the effect of memory by storing facts and inserting them into later prompts. ChatGPT's and Claude's memory features save preferences and past details, while Claude Code reads CLAUDE.md files at the start of each session. Retrieval systems act as long-term memory for documents. Memory is persistent but must be retrieved; context is immediate but limited and temporary. Good assistants combine both, loading only the memories relevant to the current task.

What is the difference between a context window and tokens?

Tokens are the units of text a model processes, roughly three quarters of an English word on average. The context window is the maximum number of tokens a model can handle in one request, covering prompt and response together.

Also asked as: difference between context window and tokens

So tokens measure amount, and the context window is the capacity. A 200,000 token window holds roughly a long book's worth of English text, though code, numbers and many non-English languages use more tokens per word. Providers bill per token, separately for input and output, so filling a large window costs more. Count tokens with each provider's tokenizer or token counting endpoint before sending large inputs, and remember that images, PDFs and tool definitions also consume tokens. Tracking token counts per request is the simplest way to understand both cost and context pressure.

Does the context window include input and output?

Yes. The context window covers the input, meaning system prompt, conversation, documents and tool definitions, plus the output the model generates. Input tokens and the maximum output you request must fit together within the window.

Also asked as: does context window include input and output

Models also have a separate maximum output limit, usually much smaller than the context window. For reasoning models, thinking tokens count as output and occupy the window during generation, although providers may strip earlier reasoning from later turns. If input is close to the limit, the model has little room to answer and may stop mid-response. Leave headroom by trimming inputs, retrieving only relevant passages and setting sensible maximum output values. Check each provider's documentation, since accounting rules for thinking, images and cached tokens differ between them.

Why is context window size important in LLMs?

Context size decides how much information a model can use at once: longer documents, bigger codebases, longer conversations and more examples. Too small a window forces truncation or retrieval; a larger one enables whole-document reasoning.

Size is not everything. Larger contexts cost more, add latency and can reduce accuracy when relevant facts are buried among irrelevant ones. Good systems use context deliberately: retrieve the most relevant passages, keep instructions clear and near the start or end, and remove stale history. RAG.NextUpgrad, for example, combines hybrid retrieval, reranking and a confidence gate so only strong evidence reaches the prompt. Evaluate quality at realistic lengths, since a model that handles long context well on benchmarks may still struggle with your specific data.

Sources

  1. Anthropic, Context windowsdocs.anthropic.com
  2. Anthropic, Claude Code slash commandsdocs.anthropic.com
  3. Anthropic, Claude Code memorydocs.anthropic.com
  4. OpenAI, Codex CLI repositorygithub.com
  5. Liu et al., Lost in the Middle: How Language Models Use Long Contextsarxiv.org
  6. Google AI for Developers, Long contextai.google.dev
Pranjul Rathour
Pranjul Rathour
GenAI Engineer · India

GenAI engineer and AI product builder with 2+ years shipping production-grade AI systems: RAG pipelines, fine-tuned LLMs, hybrid retrieval and multi-modal apps across vision, speech and OCR, architected end to end from ingestion to deployment. Leads engineering for SCULT INDIA's 14-member team, founded the 500+ member TechVerse Enclave community and has mentored 200+ students. Three hackathon first prizes: Changethon 2025 (IIT Roorkee), Product Genesis at Vividhotsava 2025 (CSJMU) and BYTEBATTLE (MeetKats).

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way. Email pranjulrathour41@gmail.com.

Keep reading

More on RAG & retrieval

All RAG & retrieval guides →
Campus talks · hackathon judging · mentoring

Want this as a live session at your college?

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way.

Pranjul Rathour, GenAI engineer in India