TipsMake

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.

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 có lỗi] /add [các file liên quan có thể liên quan] > Đây là lỗi: [thông báo lỗi] > Tìm và sửa lỗi.

Minimal context, focus only on what's necessary to understand and troubleshoot the problem.

Feature development

/clear /add src/similar-feature/* # Mẫu cần tuân theo /add src/types/*.ts # Định nghĩa kiểu /add tests/similar-feature.test.js # Các mẫu test > Tạo một tính năng mới thực hiện X. Tuân theo các mẫu hiện có.

Context tells Claude which patterns to follow.

Check the code

/add $(git diff --name-only HEAD~1) # Chỉ các file đã thay đổi > Xem lại các thay đổi này để tìm lỗi, vấn đề về kiểu và những vấn đề tiềm ẩn.

Focus on what has actually changed.

Restructuring

/add [tất cả các file liên quan đến việc tái cấu trúc] > Tái cấu trúc [thành phần] để sử dụng [mẫu mới]. > Cập nhật tất cả các cách sử dụng trên những file này.

 

All affected files are checked beforehand to coordinate the changes.

Understanding unfamiliar code

/add src/mystery-module/* > Giải thích cách mô-đun này hoạt động. Điểm vào chính là gì? Các phần kết nối với nhau như thế nào?

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/**/* # Tất cả mọi thứ - quá nhiều > Tái cấu trúc toàn bộ mã nguồn để sử dụng TypeScript

Please do the following:

# Phiên 1 /add src/utils/* > Chuyển đổi utils sang TypeScript. Đây là tsconfig của chúng ta. # Phiên 2 /clear /add src/models/* > Chuyển đổi models sang TypeScript. Đối chiếu các mẫu từ utils. # Phiên 3 /clear /add src/services/* > Chuyển đổi services sang TypeScript.

Each session has a specific context. The work is done step by step.

Practice exercises

Try this context management exercise:

  1. Open Claude Code in a project.
  2. Adding too many files: /add **/*.js
  3. Ask a specific question about a function.
  4. Note how the answer may reference unrelated code.
  5. Now, use it /clearand just add the relevant files.
  6. Ask the same question
  7. 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.

-- / --

Discover more

Claude Claude Code
Jessica Tanner

Share by

Jessica Tanner
Update 16 April 2026