Lesson 10: The Context Window
Day 10 of 50 · ~7 min read · Phase 2: Core Workflows
The Opening Question
Imagine Claude is helping you refactor a 50,000-line codebase. It opens files, reads code, understands the architecture, starts making changes.
Then suddenly: it stops. It says, "I've run out of room in my working memory. I can't see the rest."
Here's the question: What does it mean for an AI to "run out of room"? And if you can only show Claude so much, how do you make sure it sees the right things?
This isn't a problem you can solve by hoping Claude is smarter. It's a design problem. And you're the architect of the solution.
Discovery
Let's build intuition for this.
Question 1: What actually is a context window?
You've been using Claude Code for a while now. Every time you start a conversation, Claude can see your messages, the files you're working with, and the results of the commands it runs.
But think about this: is there a limit to how much Claude can "remember" in a single conversation?
Yes. Claude has a context window — a maximum amount of information (measured in "tokens") that it can hold in working memory at once.
For Claude 3.5 Sonnet (the model behind Claude Code), the context window is 200,000 tokens. A token is roughly 4 characters. So that's about 800,000 characters.
That sounds like a lot, right? Let's test that intuition.
Pause and think: How many medium-sized source files could you fit in 800,000 characters?
A typical Python file is 300–500 lines. Each line averages 50 characters. That's 15,000–25,000 characters per file. So 800,000 characters could hold about 40 medium files.
But here's the catch: Claude's context window also holds the conversation history. Every message you send, every file Claude reads, every error message it sees — that all counts toward the limit.
Question 2: Why does the context window matter when Claude is an agent?
When you're chatting with Claude.ai, the context window is mostly invisible. You paste a question, get an answer, maybe follow up. A dozen messages, and you're done.
But Claude Code is different. It's trying to autonomously solve a task that might involve:
- Reading 5 different files to understand the problem
- Running a test suite that produces 200 lines of error output
- Finding the bug, editing 3 files to fix it
- Running tests again to verify
- All in one conversation
Every single step consumes context window tokens. The bigger the task, the more information Claude needs to hold in memory.
Pause and think: If Claude keeps loading files and building up context, what happens near the end of a long task? What gets squeezed out?
The conversation history gets compressed or forgotten. Older information drops out of Claude's memory. This can make Claude less effective at catching mistakes or understanding the full picture.
Question 3: What gets loaded into the context window?
Claude Code doesn't just load random files. There's a deliberate hierarchy of what gets included.
When you ask Claude to help you, several things immediately load:
- Your conversation. Every message you've sent and every response Claude gave.
- The files you reference. If you say "Look at
auth.jsand fix the bug," Claude readsauth.js. - Results of commands. If Claude runs
npm testorgit log, the output goes into context. - Files Claude decides to read. Using the Read, Glob, and Grep tools, Claude searches and opens files it thinks are relevant.
The files Claude chooses to read are crucial. If Claude reads the wrong files, it might miss important context. If it reads too many, it burns through the context window.
Pause and think: If you're asking Claude to fix a bug and there are 100 files in the project, how would Claude decide which files to read?
Question 4: How does Claude manage a full context window?
This is where the skill comes in. Claude Code has strategies for working within the context limit.
Strategy 1: Targeted searching. Instead of reading entire files, Claude uses Grep and Glob to find exactly what it needs. If you ask "where is the login function defined?", Claude searches for login rather than opening every file.
Strategy 2: Splitting large files. If a file is too big to read all at once, Claude reads it in sections or asks you: "Should I focus on this part or that part?"
Strategy 3: Working in phases. For large projects, Claude breaks work into phases: "Let me first understand the architecture, then I'll tackle the bug." Each phase narrows scope.
Strategy 4: Picking the right abstraction level. Claude doesn't always need to read full code. Sometimes, a high-level description is enough. For example: "The User model has an authenticate method that..." instead of reading the entire User class.
Strategy 5: Asking you to focus. If the task is too big, Claude will ask: "Should I focus on the authentication module first, or the payment processing?" This narrows the scope and saves tokens.
The Insight
Here's the core idea about context windows:
A context window is Claude's working memory — it's not infinite, and it gets consumed by conversation, file contents, and command output. An agent can only stay sharp and precise if it's seeing the right information, not just more information. Your job is to help Claude focus on what matters.
The mental model: Think of context window like a desk. You can only fit so much paper on it. A smart worker doesn't load the entire filing cabinet onto the desk. They read the file they need, finish the task, put it away, and pull out the next file. Claude Code works the same way. The goal isn't to load everything — it's to load just enough to do the job well.
Try It
You're going to experience context window limits and strategies in a real project.
-
Find a project with at least 10 source files (or create a simple one with multiple files).
-
Start a conversation:
claude -
Ask Claude to do something that requires reading multiple files:
- "Explain the architecture of this project to me"
- "Show me all the places where we're making HTTP requests"
- "Find every reference to the database connection and list them"
-
Watch Claude work. Notice:
- Which files does Claude choose to read first?
- Does it use Glob or Grep to search, or does it open files one by one?
- Does it read the entire files, or does it ask for specific sections?
-
Follow up with a bigger task:
- "Refactor all those HTTP requests to use a central HTTP client"
- "Add error handling to every database call"
-
Observe how Claude manages context. Does it keep referring back to earlier files? Does it ask clarifying questions to narrow scope? Does it suggest breaking the work into phases?
This will show you how an experienced agent navigates the trade-off between breadth (seeing the whole project) and depth (understanding details).
Key Concepts Introduced
| Concept | Definition |
|---|---|
| Context window | The maximum amount of information Claude can hold in working memory during a conversation, measured in tokens |
| Token | A unit of text, roughly 4 characters; Claude's context window is 200,000 tokens (~800k characters) |
| Context consumption | How file reads, command outputs, and conversation history all use up the context window budget |
| Targeted searching | Using Grep and Glob to find specific information rather than reading entire files blindly |
| Abstraction level | Choosing the right detail level when describing code (summary vs. full implementation) |
Bridge to Lesson 11
You now understand that Claude's working memory is finite, and you're responsible for helping it focus. But there's a skill that matters even more than managing context: how you ask.
The same context window can produce brilliant work or garbage output depending on how precisely you frame the problem.
Next lesson's question: Why do some prompts produce magic and others produce garbage?
We'll explore prompting strategies that work specifically with Claude Code's agent architecture — how to be clear without being overbearing, how to give Claude freedom while keeping it on track, and how to iterate when the first attempt misses the mark.