Context
Understanding Claude's working memory
Prerequisites
- Basic Claude Code usage
What You'll Learn
- Understand what context is and why it matters
- Know what fills your context window
- Use /compact, /clear, /cost commands
- Optimize context for longer sessions
Understanding Token Usage
Tokens are the units Claude uses to measure text. Roughly 1 token ≈ 4 characters or ¾ of a word.
Small File
~100 lines of code
~2,000 tokens
Medium File
~500 lines of code
~10,000 tokens
Large File
~2000 lines of code
~40,000 tokens
What Fills Your Context
System Prompt & Tools
~15-20%Claude's base instructions and available tool definitions. This is always present.
Conversation History
~30-50%All your messages and Claude's responses in the current session.
Files & Search Results
~20-40%Contents of files you read, grep matches, and glob results.
Memory (CLAUDE.md)
~2-5%Project and directory-level instructions loaded at session start.
Context Management Commands
/compactSummarize the conversation to free up context space. Use when you get context warnings.
Tip: Auto-triggers when context gets very full
/clearClear all context and start completely fresh. Useful for unrelated tasks.
Tip: Warning: loses all conversation history
/costShow current token usage, costs, and context health.
Tip: Check periodically on long sessions
@filenameReference a specific file to add it to context. Works in your messages.
Tip: Example: "Fix the bug in @src/auth/login.ts"
⚠️ When Context Gets Full
As your conversation grows, Claude automatically manages context to keep you productive:
Auto-Summarization
Older messages are condensed into brief summaries, preserving key decisions and context while freeing up space.
Context Pruning
Less relevant information (like old search results) may be dropped to make room for new, more relevant content.
You'll see a warning when context is getting full. Use /compact proactively to maintain quality.
Context vs Memory
Context (Session)
- •Exists only during the current session
- •Includes everything Claude can see now
- •Limited by token window (~200K)
- •Disappears when session ends
Memory (CLAUDE.md)
- •Persists across all sessions
- •Contains project instructions and preferences
- •Stored in files on disk
- •Loaded into context at session start
Memory (CLAUDE.md) is loaded into context each session. It's a way to give every session the same starting knowledge.
💡 Pro Tips
- 1.Use
/costto check context usage before starting a large task—you might want to/compactfirst. - 2.Reference files with
@filenameinstead of pasting contents—Claude will read exactly what it needs. - 3.For unrelated tasks, use
/clearto start fresh rather than working with irrelevant context. - 4.Put persistent information in CLAUDE.md rather than repeating it—it's automatically included every session.
- 5.Long sessions benefit from periodic
/compacteven before warnings appear.
Master Claude Code faster
Get notified when new animated guides are released.
Subscribe to the newsletter