Context window is the amount of information Claude can consider at once. It includes system prompt, conversation history, file contents, and tool results. Managing context effectively helps Claude work better.
Context window là lượng thông tin Claude có thể xem xét cùng lúc. Nó bao gồm system prompt, conversation history, file contents, và tool results. Quản lý context hiệu quả giúp Claude làm việc tốt hơn.
- System prompt: CLAUDE.md and fixed instructions.
System prompt: CLAUDE.md và các hướng dẫn cố định.
- Conversation history: Messages exchanged between you and Claude.
Conversation history: Các tin nhắn qua lại giữa bạn và Claude.
- File contents: Contents of files Claude has read.
File contents: Nội dung các file Claude đã đọc.
- Tool results: Results from tools like Grep, Bash, etc.
Tool results: Kết quả từ các tool như Grep, Bash, etc.
When context approaches limits, Claude Code automatically compresses old messages. This retains important information and discards unnecessary details.
Khi context gần đạt giới hạn, Claude Code tự động nén các tin nhắn cũ. Điều này giữ lại thông tin quan trọng và loại bỏ chi tiết không cần thiết.
1# Context compression happens automatically2# You might see messages like:3"[Earlier context compressed: discussed auth module,4decided to use JWT tokens]"56# To manually clear context:7/clearInformation that exists within the current session. Lost when session ends.
Thông tin tồn tại trong phiên làm việc hiện tại. Bị mất khi session kết thúc.
CLAUDE.md and files in .claude/ are read each time a new session starts in the project.
CLAUDE.md và các file trong .claude/ được đọc mỗi khi bắt đầu session mới trong project.
1# Project memory locations:2project/3├── CLAUDE.md # Always loaded4├── .claude/5│ ├── CLAUDE.md # Additional instructions6│ ├── settings.json # Project settings7│ └── agents/ # Custom agentsMemory stored in ~/.claude/ applies to all your projects.
Memory được lưu trong ~/.claude/ áp dụng cho tất cả projects của bạn.
1# User memory locations:2~/.claude/3├── CLAUDE.md # Global instructions4├── settings.json # User preferences5└── projects/ # Per-project memory6 └── <project-hash>/7 └── memory/ # Auto-saved memoriesInstead of pasting entire codebase, only provide what's relevant to the current task.
Thay vì paste toàn bộ codebase, chỉ cung cấp những gì liên quan đến task hiện tại.
1# Too much context (bad)2"Here's my entire codebase of 100 files..."34# Focused context (good)5"I'm working on UserService.ts (attached).6It depends on types from user.types.ts (attached).7The bug is in the login function at line 45."If conversation becomes cluttered with tangents, clear and restart with fresh context.
Nếu conversation trở nên lộn xộn với nhiều tangent, hãy clear và bắt đầu lại với context sạch.
1# Signs you should clear:2# - Claude referencing outdated information3# - Confusion about current task4# - "Earlier we discussed..." becomes irrelevant56/clear78# Then restart with focused context:9"Now working on: add pagination to user list API.10Relevant file: UserController.ts"1# Ask Claude to remember something2"remember: we decided to use Prisma for ORM"34# This gets saved to project memory5# Available in future sessions67# To forget8"forget: the Prisma decision"910# Check what's remembered11"what have I asked you to remember?"Sử dụng remember cho các quyết định quan trọng ảnh hưởng đến nhiều sessions. Đừng spam với chi tiết nhỏ.
Key Takeaways
Điểm Chính
- Context includes system prompt, history, files, and tool resultsContext bao gồm system prompt, history, files và tool results
- Old context is automatically compressed when limits approachContext cũ tự động được nén khi gần đạt giới hạn
- CLAUDE.md provides persistent project memoryCLAUDE.md cung cấp project memory lâu dài
- Use /clear when context becomes clutteredDùng /clear khi context trở nên lộn xộn
Practice
Test your understanding of this chapter
What happens when context window approaches its limit?
Điều gì xảy ra khi context window gần đạt giới hạn?
CLAUDE.md is only read once when you first create it.
CLAUDE.md chỉ được đọc một lần khi bạn tạo nó.
Complete the command to clear conversation history
Hoàn thành lệnh để xóa lịch sử hội thoại
/What is the best practice for providing context?
Best practice để cung cấp context là gì?