
Table of Contents
What this lesson is about
Every Claude Code session has a limit on how much information it can hold at one time. This limit is called the context window. Understanding how it works — and how to manage it — prevents a problem that most new users never see coming: Claude quietly getting worse as a session gets longer, without you realising why.
What is the context window?
Think of the context window as Claude’s desk. When you start a session, the desk is empty. As the session progresses, things pile up on it — your messages, Claude’s responses, files it has read, results from tools it has run. The desk has a fixed size. When it gets full, older items fall off the edge to make room for new ones.
The moment things start falling off the desk, Claude loses access to them. It can no longer see that file it read an hour ago, or the instruction you gave at the start of the session. It is not being careless — it literally cannot see those things anymore. This is why output quality can quietly degrade in a long session. Claude is not getting worse. It is working with less information.
The context window is measured in tokens. A token is roughly three-quarters of a word — so 1 000 tokens is approximately 750 words. Different Claude models have different context window sizes, but all of them have a limit.
What fills up the context window?
Four things consume tokens in a session.
1. Your messages
Every question or instruction you type is added to the context. A short message costs very little. A long, detailed prompt costs more.
2. Claude’s responses
Every response Claude gives is also added to the context. Long responses cost more tokens than short ones.
3. Files Claude reads
When you ask Claude to read a file, the entire contents of that file are loaded into the context. A 500-line file is a significant token cost. Reading ten files in one session can fill the context very quickly.
4. Tool outputs
When Claude runs a bash command, does a web search, or uses any tool, the output of that tool is added to the context. A web search that returns a long article consumes many tokens.
How to check your token usage
At any point during a session, type /cost and press Enter. This shows you how many tokens have been used so far, how many remain, and what the session has cost in money.
A good habit: run /cost at the start of every session, after reading large files, and before asking Claude to do something complex.
What happens when the context fills up
You will not see an error. Claude will not stop working. What happens is more subtle — and more dangerous.
As the context fills up, the oldest content is removed to make room for the newest. If you loaded a file at the start of the session and the context is now full, Claude can no longer see that file. If your CLAUDE.md contained an important instruction, Claude may have lost access to it.
The result is responses that seem slightly off, or instructions that Claude appears to be ignoring. It is not ignoring them — it simply cannot see them anymore.
Two commands that fix this
/compact
/compact summarises the conversation history and compresses it into a shorter version. Think of it like filing the papers on your desk into a folder — the detailed content is gone, but a summary of what happened remains. The desk now has more space.
Use /compact when you want to keep working on the same task but the session is getting long. You preserve continuity without burning through tokens.
/clear
/clear wipes the conversation history completely and starts fresh. The desk is empty again. Claude remembers nothing from the previous conversation — only what is in your CLAUDE.md files.
Use /clear when you are finished with one task and moving to a completely different one. There is no point carrying the context of a previous task into a new one.
When to use each one
| Situation | Command |
|---|---|
| Same task, session getting long | /compact |
| Moving to a completely different task | /clear |
| Output quality is degrading noticeably | /compact first, then /clear if needed |
| Starting a fresh day | /clear |
| Middle of a complex multi-step task | /compact |
Practical tips for keeping context lean
Only read files Claude actually needs. If you ask Claude to read ten files but it only needs three, you have filled the desk with clutter. Be specific about what you ask Claude to load.
Keep your CLAUDE.md files focused. Every word in those files is loaded into the context at the start of every session. A 2 000-word global CLAUDE.md costs tokens before you have typed your first message.
Break long projects into separate sessions. Use shorter, focused sessions. Start each one with a brief context summary rather than relying on session history.
Use /compact before loading large files. If your session already has history, compact it first to free up space before asking Claude to read a large document.
Practical Exercise
a. Start a Claude session and immediately run /cost — note the token count on an empty session
b. Ask Claude to read a large file from your computer and run /cost again — notice how much the file consumed
c. Have a back-and-forth conversation of ten messages and run /cost — see how conversation history adds up
d. Run /compact and observe the summary Claude produces of the conversation
e. Run /cost again after compacting — confirm the token count has dropped
f. Run /clear and run /cost one final time — confirm the context is back to zero
Common problems and how to fix them
Claude seems to be ignoring instructions I gave earlier
The context window has likely filled up and those instructions have been pushed out. Run /compact to free space, then restate the key instructions so they are back in the current context.
Responses are getting shorter and less detailed as the session goes on
This is a sign the context is filling up. Claude is allocating less space to its response because the context is crowded. Run /compact immediately.
I ran /clear by mistake and lost my context
/clear cannot be undone. This is why keeping a project summary in your CLAUDE.md matters — you can always re-establish context quickly in a new session without relying on conversation history.
My sessions always run out of context on large projects
Break the project into smaller focused sessions. At the end of each session, ask Claude to write a short summary of what was done and what comes next, then save it to a file. Start the next session by asking Claude to read that file first.
What you have learned in this lesson
- The context window is Claude’s working memory — it has a fixed size and fills up during a session
- Tokens are the unit of measurement — every message, response, file, and tool output costs tokens
/costshows how much context you have used and how much remains- When the context fills up, older content is quietly removed — this degrades output quality without any warning
/compactsummarises the conversation to free up space while keeping continuity/clearwipes everything and starts fresh — use it when moving to a new task- Short, focused sessions produce better results than one endless session