Context Management
Window optimization
Context is Claude's "working memory". Everything Claude knows about the task must fit in context (~200K tokens for Claude Sonnet).
Claude Code instructions
Project instructions
Previous messages
Read files, searches
Your request and context
When context fills up (~80%), Claude automatically compresses history:
⚠️ Auto-compaction may lose details. Use /compact manually for control.
Use /compact for manual context compression:
✓ Context compressed: 85% → 35%
Preserved: current task, important files
Removed: intermediate search results
💡 Use /cost to see current context usage
Each sub-agent works in isolated context, which helps:
Main agent
Preserves overall task context
Sub-agent
Receives only necessary information
Sub-agent: only search instruction
Returns: brief result
Use /compact regularly
Compresses history while preserving important info
Break large tasks
Each subtask — separate session
Avoid unnecessary files
Read only necessary code parts
Use sub-agents
Isolated context for subtasks
When to Start New Session
- •Task completed — start new session for clean context
- •Topic changes — don't drag old context
- •Context overflow — better to start fresh
- •Claude got confused — reset helps
This lesson is part of a structured LLM course.
My Learning Path