Context
Understand how Claude Code gathers context — reading files, searching code, using the context window efficiently, and techniques to provide better context.
How Claude Code Gathers Context
When you give Claude Code a task, it doesn't just blindly generate code. It actively explores your codebase to understand the full picture before making changes. This context-gathering phase is what separates a good AI coding tool from a basic autocomplete.
Automatic Context Sources
Claude Code automatically reads from several sources when it starts a session:
- CLAUDE.md files — Your project instructions (covered in Episode 2)
- Directory structure — It lists your files and folders to understand project layout
- Open conversation — Everything you've said in the current session stays in context
How Claude Reads Your Code
When you ask Claude to work on something, it uses tools to actively read relevant files:
# You ask:
> Fix the login form validation
# Claude's internal process:
# 1. Searches for login-related files
# 2. Reads the login component
# 3. Reads the validation logic
# 4. Checks the API route it submits to
# 5. Reads any shared form utilities
# 6. THEN proposes changes
You can see this happening in real-time — Claude shows each file it reads and each command it runs.
The Context Window
Claude Code has a finite context window — the amount of information it can hold in memory at once. As your conversation grows longer, older messages may fall out of context. Understanding this helps you work more effectively:
- Long sessions — After extensive back-and-forth, Claude may forget details from the beginning of the conversation
- Large files — Reading many large files fills the context window faster
- Compact context — The
/compactcommand summarizes the conversation to free up space
The /compact Command
When your context window gets full, use the compact command to summarize and compress the conversation:
> /compact
Claude condenses all previous messages into a brief summary, freeing up tokens while retaining the essential context. This lets you continue working in the same session without losing track of what you've done.
Providing Better Context
You can help Claude perform better by providing targeted context:
1. Point to Specific Files
# Instead of:
> Fix the API bug
# Be specific:
> Fix the 500 error in src/api/users/route.ts when fetching user profiles
2. Reference Existing Patterns
> Add a DELETE endpoint to the products API, following the same pattern as src/api/users/route.ts
3. Paste Error Messages
> I'm getting this error when running npm run build:
> TypeError: Cannot read properties of undefined (reading 'map')
> at UserList (src/components/UserList.tsx:24:18)
4. Use Images
Claude Code can read images — paste screenshots of errors, UI issues, or design mockups directly into the terminal.
Context Best Practices
- Start fresh sessions for new tasks — Don't reuse a long session for unrelated work
- Use /compact periodically — Especially during long refactoring sessions
- Be specific in your prompts — Mention file paths, function names, and error messages
- Let Claude explore — Don't rush it; context gathering leads to better code
What's Next
In the next episode, we'll learn about Tools & Permissions — the different tools Claude Code has access to and how the permission system keeps you in control.