Table of Contents
Claude Code's responses are only good when you provide the right context. Give it the right files, and it will give excellent answers.
Context Is Everything
In the previous lesson, we learned about core commands. Now, let's build on that foundation. Claude Code's responses are only good when you provide the right context. Give it the right files, and it will give excellent answers. Give it irrelevant, messy stuff, and it will give confusing responses.
Context management isn't simply about adding files. It's about strategically selecting what Claude sees to get the results you need.
How Context Works
Imagine Claude's context as a desk. Surface area is limited. Everything on the desk is competing for attention.
- A small, organized workspace: You can find everything you need and work efficiently.
- A large, cluttered desk: Everything is buried. You lose focus.
Similarly with Claude. A few relevant files are better than dozens of indirectly related files.
The Principle of Minimum Feasible Context
Before adding anything, ask yourself: "Does Claude need this for the current mission?"
Yes, please add:
- The files you are asking about or editing
- The interface definition files are being used.
- The files contain the template you want to follow.
- The test files demonstrate the expected behavior.
No, skip this:
- The entire "just in case" folder
- Files indirectly related to the topic
- The large configuration files that Claude won't need to change.
- Documents that Claude doesn't need to reference.
When in doubt: Start without context, then add more if Claude seems to be missing information.
Context Classification Strategy
Build context layer by layer, from general to specific.
Level 1: Understanding the Project
/add README.md package.json
High-level project information. What is this? Which stack?
Level 2: Architectural Context
/add src/index.js src/routes.js
Access points and structure. How is this organized?
Layer 3: Feature Context
/add src/auth/*.js
The specific area where you are working.
Level 4: Task Context
/add src/auth/login.js src/auth/types.ts
The correct files for your current task.
You don't always need all the classes. For a simple error, skip straight to class 4.
Reading Contextual Signals
Claude lets you know when the context is wrong:
"I can't see it." Claude is missing a file. Please add it.
Claude is just guessing at the virtual code reference because it doesn't have actual code. Please add the source files.
The style or pattern is inconsistent. Claude hasn't seen your existing code yet. Please add examples of the patterns you want.
The response is very slow. The context might be too large. Try /compact.
The response refers to outdated work and is confusing with obsolete information. Please review /clearand revise it.
Task-based Context Strategy
Fix the Error
/clear /add [file co loi] /add [cac file lien quan co the lien quan] > ay la loi: [thong bao loi] >English example text
Minimal context, focus only on what's necessary to understand and troubleshoot the problem.
Feature Development
/clear /add src/similar-feature/* # Mau can tuan theo /add src/types/*.ts # inh nghia kieu /add tests/similar-feature.test.js # Cac mau test >English example text
Context tells Claude which patterns to follow.
Check the Code
/add $(git diff --name-only HEAD~1) # Chi cac file a thay oi >English example text
Focus on what has actually changed.
Restructuring
/add [tat ca cac file lien quan en viec tai cau truc] > Tai cau truc [thanh phan] e su dung [mau moi]. >English example text
All affected files are checked beforehand to coordinate the changes.
Understanding Unfamiliar Code
/add src/mystery-module/* >English example text
Let Claude explore and explain before you begin.
Break Down the Context for Larger Tasks
Some tasks require more context than are appropriate. Solution: Break down the work.
Instead of:
/add src/**/* # Tat ca moi thu - qua nhieu >English example text
Please do the following:
# Phien 1 /add src/utils/* > Chuyen oi utils sang TypeScript. ay la tsconfig cua chung ta. # Phien 2 /clear /add src/models/* > Chuyen oi models sang TypeScript. oi chieu cac mau tu utils. # Phien 3 /clear /add src/services/* >English example text
Each session has a specific context. The work is done step by step.
Practice Exercises
Try this context management exercise:
- Open Claude Code in a project.
- Adding too many files:
/add **/*.js - Ask a specific question about a function.
- Note how the answer may reference unrelated code.
- Now, use it
/clearand just add the relevant files. - Ask the same question
- Compare the quality of the answers.
Specific context often provides a significant advantage.
Context Management Checklist
Before starting a task:
- []
/clearor/compactif the preceding context is irrelevant - [] Determine the minimum number of files required
- [] Add files in a logical order (template first, then target file)
- [] Verify by
/lschecking if the context is correct.
While performing the task:
- [] Add files as needed if Claude seems to be missing information
- [] Use
/compactif response slows down - [] Do not add the "just in case" file
Complete a task:
- [] Consider using this
/compactbefore performing the next task if the context will overlap. - []
/clearif switching to an unrelated job
Key Points to Remember
- The quality of context is more important than the quantity of context.
- Minimum feasible context: Only what is necessary for the current task.
- Context classification ranges from general to specific based on task complexity.
- Monitor for signals that indicate the context needs adjustment.
- Break down large tasks into smaller, focused sessions.
-
Question 1:
When should you add test files to the context?
EXPLAIN:
Test files show Claude the expected test patterns and structures. Adding them when writing new code helps ensure consistency.
-
Question 2:
What is the principle of 'least feasible context'?
EXPLAIN:
Only add what is necessary for the current task. Relevant context is better than the broader overall context.
-
Question 3:
What happens when the context is too large?
EXPLAIN:
The large context slows down processing and can confuse the model. Claude has limited attention span for all that information, resulting in a less focused response.
Training Results
You have completed 0 questions.
-- / --
FAQ
What is the main point of context management in claude code?
Claude Code's responses are only good when you provide the right context. Give it the right files, and it will give excellent answers.
Why is this development important?
Key takeaway: Claude Code's responses are only good when you provide the right context.
What are the key takeaways?
In the previous lesson, we learned about core commands.
Reader Comments 0
Sign in with email or Google to join the discussion.