📝 What context is
O context is everything the model knows at the moment: your message, the previous conversation, the files the agent has read, and the tool results. It’s the session’s active “working memory” — and it has a limit.
📝 What goes into the context
- •System prompt: Claude Code internal instructions (~2K tokens, fixed)
- •CLAUDE.md: your custom project instructions (you control them)
- •History: the entire conversation since the start of the session
- •Tool results: the contents of each file read, the output of each Bash command
🔢 What Tokens Are
Tokens are the smallest units of text that language models process. They aren’t exactly words or letters—they’re text fragments that the tokenizer splits based on frequency in the language.
📊 Token reference
- 1 English word ≈ 1.3 tokens
- 1 word in pt-BR ≈ 1.5-2 tokens
- 100 lines of code ≈ 800-1,200 tokens
- 1 page of text (A4) ≈ 500-700 tokens
- 1KB file ≈ 250-400 tokens
- 10KB file ≈ 2,500-4,000 tokens
- 100KB file ≈ 25,000-40,000 tokens
- Typical CLAUDE.md ≈ 500-2,000 tokens
✓ Efficient token use
- ✓Code in English/symbols
- ✓Concise, direct text
- ✓Code without long comments
- ✓JSON without extra spaces
✗ Uses too many tokens
- ✗Copying entire files into the message
- ✗Text in languages with long words
- ✗Repeating the same content several times
- ✗Verbose agent responses
🪟 Context window
A context window is the maximum number of tokens the model can process at once. It's like a computer's RAM — fast, but finite. Claude 3 Sonnet has 200K tokens.
🪟 200,000 tokens in perspective
It seems like a lot. It is—but it fills up quickly during long sessions with lots of code reading.
- •≈ 500 pages of dense text
- •≈ 20,000 lines of code
- •≈ 40-60 medium-sized code files
With a long session, you can use this in:
- ⚠️1 500KB file read = 125K tokens
- ⚠️10 50KB files = the same thing
- ⚠️A 2-hour session with lots of debugging = full
💡 Tip: When the context is full
Signs the context window is nearly full: the agent starts to "forget" instructions from the beginning, does things you already said not to do, or the answers become more generic. Use /compact or /clear.
📈 Why the context fills up
The window doesn't fill up randomly. There are common culprits that consume tokens disproportionately—and identifying them lets you act before losing critical context.
Large files read in full
A 500KB file uses ~125K tokens — more than half the context window. The agent reads more than it needs when there are no specific instructions.
Long conversation history
Every message stays in the context. A 2-hour session with many exchanges can easily accumulate 30-50K tokens just in the history.
Many tool calls with long output
Each Bash(npm install) with long output goes straight into the context. Logs with 10K lines are common.
Verbose agent responses
Does the agent explain every step in detail? That also fills up the context. Configure this in CLAUDE.md: "keep your responses concise".
🗜️ Context Compaction
Claude Code has mechanisms for handling full contexts: the command /compact (manual) and automatic compaction that happens when the window is almost full.
✓ /compact — when to use it
- ✓After completing a feature
- ✓When the history gets too long
- ✓Before starting a new subtask
- ✓When you notice a decline in quality
✗ Be careful with /compact
- ✗Details of previous errors may be lost
- ✗Don't use in the middle of a critical task
- ✗The summary may lose important nuances
- ✗Some contexts are better kept intact
⌨️ Context management commands
💡 Context best practices
Managing context well is one of the skills that most distinguishes advanced users from beginners. A few simple rules have a huge impact on session quality and cost.
📋 The 5 golden rules of context
- 1.Short, focused sessions: one session per feature/bug, not per day
- 2.CLAUDE.md for fixed context: stack, coding rules, project conventions
- 3.Don't paste code into messages: say "edit file X" instead of copying the content
- 4./compact proactively: use before starting a new task, not when the window is already full
- 5.Ask for concision: include in the CLAUDE.md "be direct and concise in your responses"
💡 The perfect CLAUDE.md for saving context
A good CLAUDE.md has 3 sections: (1) Project context — technologies, structure, architecture; (2) Code rules — style, conventions, standards; (3) Session instructions — "be concise," "ask before creating files."
This eliminates the need to repeat the context in every session, and the agent starts being productive immediately.
✅ Module 1.3 Summary
Next Module:
1.4 — Terminal and CLI for beginners: go from zero to using the terminal in 40 minutes, including the commands Claude Code uses most.