Week 9 of 12 🧠

Memory & Context Management

หน่วยความจำและการจัดการบริบท

记忆与上下文管理

Memory & Context Management

1. Introduction / บทนำ / 简介

ระบบหน่วยความจำของ Claude Code ให้มันจดจำคำสั่งข้ามเซสชัน ไฟล์ CLAUDE.md ให้กฎทั่วโปรเจกต์ auto-memory บันทึกการเรียนรู้อัตโนมัติ และกฎเฉพาะพาธกำหนดเป้าหมายไฟล์บางประเภท ทำให้ Claude ฉลาดขึ้นเมื่อเวลาผ่านไป
Claude Code 的记忆系统让它能跨会话记住指令。CLAUDE.md 文件提供整个项目的规则,auto-memory 自动保存学到的经验,路径专属规则则针对特定类型的文件。它们一起让 Claude 随着时间越来越聪明。
Claude Code's memory system lets it remember instructions across sessions. CLAUDE.md files provide project-wide rules, auto-memory saves learnings automatically, and path-specific rules target certain file types. Together, they make Claude smarter over time.

Fun Facts / ข้อเท็จจริงที่น่าสนใจ / 趣味知识

  • CLAUDE.md works like a README but for Claude's behavior.
  • Auto-memory persists learnings without you doing anything.
  • Path-specific rules in .claude/rules/ apply only to matching files.
A person writing notes in a notebook next to a laptop
Notes that survive the session — CLAUDE.md is your project’s notebook. — Photo: Shixart1985, CC BY 2.0, via Wikimedia Commons

2. Vocabulary / คำศัพท์ / 词汇

Click a card to flip it. คลิกการ์ดเพื่อพลิก 点击卡片翻面。

memory
หน่วยความจำ
记忆
Stored information for future use
context
บริบท
上下文
The surrounding information that helps understanding
persist
คงอยู่
持久保存
To remain saved across sessions
scope
ขอบเขต
作用范围
Where something applies (user, project, local)
rule
กฎ
规则
An instruction Claude must follow
override
แทนที่
覆盖
To replace a default setting
instruction
คำสั่ง / คำแนะนำ
指令
A direction telling Claude what to do
import
นำเข้า
导入
To bring in data from another file
index
ดัชนี
索引
A list of pointers to memory files
stale
ล้าสมัย
过时
No longer current or accurate
truncate
ตัดทอน
截断
To shorten by removing the end
auto-memory
หน่วยความจำอัตโนมัติ
自动记忆
Automatically saved learnings across sessions

3. Grammar Focus / ไวยากรณ์ / 语法焦点

Present Perfect (has saved, have configured) / Present Perfect (has saved, have configured) / 现在完成时(has saved、have configured)

Thai:
Present Perfect (have/has + กริยาช่อง 3) เชื่อมการกระทำในอดีตกับปัจจุบัน ใช้ 'has' สำหรับ he/she/it, 'have' สำหรับ I/you/we/they ตัวอย่าง: 'Claude has saved the memory.' 'We have configured the rules.'
中文:
现在完成时(have/has + 过去分词)把过去的动作和现在联系起来。he/she/it 用 'has',I/you/we/they 用 'have'。例如:'Claude has saved the memory.'(Claude 已经保存了记忆。)'We have configured the rules.'(我们已经配置好了规则。)
English:
Present Perfect (have/has + past participle) connects past actions to the present. Use 'has' for he/she/it, 'have' for I/you/we/they. Example: 'Claude has saved the memory.' 'We have configured the rules.'
Claude จดจำความชอบของคุณแล้ว
Claude 已经记住了你的偏好。
Claude has remembered your preferences.
ฉันสร้างไฟล์ CLAUDE.md แล้ว
我已经创建了一个 CLAUDE.md 文件。
I have created a CLAUDE.md file.
บริบทถูกบีบอัดแล้ว
上下文已经被压缩了。
The context has been compacted.

Section Check 1

What does CLAUDE.md do?

CLAUDE.md ทำอะไร?

CLAUDE.md 有什么作用?

Section Check 2

Which is Present Perfect?

ข้อใดเป็น Present Perfect?

哪个句子是现在完成时?

Section Check 3

Where are path rules stored?

กฎเฉพาะพาธเก็บที่ไหน?

路径专属规则保存在哪里?

4. Tutorial Steps / ขั้นตอนการเรียนรู้ / 教程步骤

1
Create a CLAUDE.md file / สร้างไฟล์ CLAUDE.md / 创建一个 CLAUDE.md 文件
Run /init or create CLAUDE.md in your project root with coding standards and project rules.

How to do it

  • Run /init — Claude scans the project and drafts a CLAUDE.md for you.
  • Or create the file yourself in the project root.
  • Keep rules short and testable: "Use 2-space indent" beats "write nice code".
2
Enable auto-memory / เปิดใช้ auto-memory / 启用 auto-memory
Type /memory and toggle auto-memory on. Claude will save learnings automatically.

How to do it

  • Type /memory and switch auto-memory on.
  • From now on Claude saves what it learns (your preferences, project facts) between sessions.
  • Memories are plain files on your disk — you can read and edit them.
3
Create path-specific rules / สร้างกฎเฉพาะพาธ / 创建路径专属规则
Create .claude/rules/backend.md with frontmatter paths: ['src/**/*.ts'] for TypeScript-specific rules.

How to do it

  • Create .claude/rules/backend.md with frontmatter like paths: ['src/**/*.ts'].
  • Those rules load only when Claude touches matching files.
  • This keeps frontend rules out of backend work and vice versa.
4
Check memory entries / ตรวจสอบรายการหน่วยความจำ / 查看记忆条目
Type /memory to view saved auto-memory entries and CLAUDE.md contents.

How to do it

  • Type /memory again any time to see what is stored.
  • You can open, edit, or delete any entry — you are in control of the memory.
  • Wrong memory? Delete it — Claude will not miss it.
5
Use @imports / ใช้ @imports / 使用 @imports
In CLAUDE.md, write @path/to/file to import additional instruction files.

How to do it

  • Inside CLAUDE.md, write a line like @docs/style-guide.md.
  • That file is pulled into every session along with CLAUDE.md.
  • Use it to share one style guide across several projects.

5. Hands-On Activity / กิจกรรมลงมือทำ / 动手练习

แบบฝึกหัด: สร้าง CLAUDE.md พร้อมกฎ 3 ข้อสำหรับโปรเจกต์ (เช่น 'ใช้การเยื้อง 2 ช่อง', 'เขียนเทสต์สำหรับทุกฟังก์ชัน') จากนั้นเปิดใช้ auto-memory
练习:为你的项目创建一个包含 3 条规则的 CLAUDE.md(例如"使用 2 个空格缩进""为所有函数编写测试")。然后启用 auto-memory。
Practice: Create a CLAUDE.md with 3 rules for your project (e.g., 'Use 2-space indentation', 'Write tests for all functions'). Then enable auto-memory.

Step by step

  1. Run /init (or ask Claude to create CLAUDE.md).
  2. Add 3 short rules, e.g. Use 2-space indentation, Write tests for all functions, Answer in simple English.
  3. Type /memory and turn auto-memory on.
  4. Start a fresh session (/clear) and ask: What are this project's rules?

✓ You did it right if: Claude lists your 3 rules without you pasting them again.

📜 A complete working CLAUDE.md / ตัวอย่างคำตอบ / 示例答案
# CLAUDE.md   (save in your project root)

## Rules for this project
- Use 2-space indentation in all files.
- Write a test for every new function.
- Answer in simple English (A2 level).

## About this project
A small website for my school club. Plain HTML and CSS, no frameworks.

# ---- Verify it works: start a NEW session and ask ----
> What are this project's rules?
* Your CLAUDE.md sets three rules: 2-space indentation,
  a test for every new function, and simple English answers.

6. Reference Table / ตารางอ้างอิง / 参考表

Command / ToolEnglishภาษาไทย中文
CLAUDE.mdProject instructions fileไฟล์คำสั่งโปรเจกต์项目指令文件
~/.claude/CLAUDE.mdGlobal instructionsคำสั่งส่วนตัว全局指令
.claude/rules/Path-specific rulesกฎเฉพาะพาธ路径专属规则
/memoryManage memory settingsจัดการการตั้งค่าหน่วยความจำ管理记忆设置
/initInitialize CLAUDE.mdสร้าง CLAUDE.md เริ่มต้น初始化 CLAUDE.md

7. Interactive Lab / ห้องทดลอง / 互动实验室

See exactly which rules load, and test what survives a restart. / ดูว่ากฎไหนถูกโหลด และอะไรรอดข้ามเซสชัน / 看哪些规则被加载、什么能在重启后留下

Which rules load? Toggle rule files, then switch the file you are working on.



Working on:

8. Summary / สรุป / 总结

CLAUDE.md ให้คำสั่งที่คงอยู่ Auto-memory บันทึกการเรียนรู้ กฎพาธกำหนดเป้าหมายไฟล์เฉพาะ Present Perfect (has/have + กริยาช่อง 3) อธิบายการกระทำที่เสร็จสิ้นที่เกี่ยวข้องกับปัจจุบัน
CLAUDE.md 提供持久的指令。Auto-memory 保存学到的经验。路径规则针对特定文件。现在完成时(has/have + 过去分词)描述与现在相关的已完成动作。
CLAUDE.md provides persistent instructions. Auto-memory saves learnings. Path rules target specific files. Present Perfect (has/have + past participle) describes completed actions with present relevance.

Homework / การบ้าน / 作业

1. สร้าง CLAUDE.md พร้อมกฎโปรเจกต์ 5 ข้อ
2. เปิดใช้ auto-memory และสนทนา
3. เขียน 5 ประโยค Present Perfect เกี่ยวกับโปรเจกต์ของคุณ
1. 创建一个包含 5 条项目规则的 CLAUDE.md。
2. 启用 auto-memory 并进行一次对话。
3. 写 5 个关于你的项目的现在完成时句子。
1. Create a CLAUDE.md with 5 project rules.
2. Enable auto-memory and have a conversation.
3. Write 5 Present Perfect sentences about your project.