Context Management
Claude has a context window limit. Learning to manage it is essential for working with large codebases.
Understanding Context
Claude's context window is like its "working memory":
- Claude 3.5 Sonnet: 200K tokens (~150K words)
- Everything counts: Your messages, Claude's responses, file contents
When context fills up, you need to manage it.
Context Commands
/clear
Clears all context and starts fresh:
> /clear
Starting new session...
Use when:
- Switching to unrelated tasks
- Context is cluttered with old info
- Claude seems confused
/compact
Summarizes current context to free space:
> /compact
Compacting context...
Retained: Key files, recent changes
Freed: 45K tokens
Use when:
- Getting "context limit" warnings
- Mid-session and need more space
- Want to continue current work
/resume
Continues from a previous session:
claude --resumeUse when:
- Continuing yesterday's work
- Picking up after a break
- Need previous context
Strategies for Large Projects
1. Scope Your Requests
# Too broad
> Review the codebase
# Better
> Review the authentication module in src/auth/
2. Use Directory CLAUDE.md
Create CLAUDE.md files in subdirectories:
/src/auth/CLAUDE.md
/src/payments/CLAUDE.md
/src/notifications/CLAUDE.md
3. Reference Don't Include
# Instead of pasting code
> The function in src/utils/validation.ts has a bug
# Claude will read just that file
4. Summarize Before Clearing
> Summarize what we've done so far before I clear context
Then after clearing:
> We just completed: [paste summary]
> Now let's continue with...
Context Usage Patterns
| Task Type | Context Strategy |
|---|---|
| Quick fix | Fresh context, focused scope |
| Feature development | Keep context, /compact as needed |
| Refactoring | /compact frequently, reference files |
| Code review | Fresh context per PR |
Monitoring Context
Ask Claude about usage:
> How much context have we used?
Or check the status indicator in your terminal.
Next Steps
In the next module, you'll learn advanced techniques: sub-agents, MCPs, and hooks.