Skip to content
DocsUse AIadvancedContext Management
Chapter 14 of 15·advanced·11 min read

Context Management

Quản Lý Context

Managing context, memory, and conversation state

Hover or tap any paragraph to see Vietnamese translation

What is Context Window?

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 Components

  • System prompt: CLAUDE.md and fixed instructions.
  • Conversation history: Messages exchanged between you and Claude.
  • File contents: Contents of files Claude has read.
  • Tool results: Results from tools like Grep, Bash, etc.
Context Window Composition
Tool Results
Grep, Bash output
File Contents
Code Claude has read
Conversation History
Messages exchanged
CLAUDE.md
Project guidelines
System Prompt
Fixed instructions

Context Compression

When context approaches limits, Claude Code automatically compresses old messages. This retains important information and discards unnecessary details.

Context Compression
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/clear
Typical Context Budget Allocation
System Prompt5 %
CLAUDE.md10 %
Conversation25 %
File Contents40 %
Available20 %

Memory Systems

Session Memory

Information that exists within the current session. Lost when session ends.

Project Memory

CLAUDE.md and files in .claude/ are read each time a new session starts in the project.

Project Memory
1# Project memory locations:2project/3├── CLAUDE.md           # Always loaded4├── .claude/5│   ├── CLAUDE.md       # Additional instructions6│   ├── settings.json   # Project settings7│   └── agents/         # Custom agents

User Memory

Memory stored in ~/.claude/ applies to all your projects.

User Memory
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 memories

Effective Context Management

Focused Context

Instead of pasting entire codebase, only provide what's relevant to the current task.

Focused Context
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."

Clear When Needed

If conversation becomes cluttered with tangents, clear and restart with fresh context.

When to Clear
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"

Remember and Forget

Remember/Forget
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?"
Tip
Use remember for important decisions that affect multiple sessions. Don't spam with minor details.

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

Quiz

What happens when context window approaches its limit?

Điều gì xảy ra khi context window gần đạt giới hạn?

True or False

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ó.

Code Challenge

Complete the command to clear conversation history

Hoàn thành lệnh để xóa lịch sử hội thoại

/
Quiz

What is the best practice for providing context?

Best practice để cung cấp context là gì?

← → to navigate chapters
Built: 4/8/2026, 12:01:11 PM