Claude Code 的记忆架构:如何让 AI 真正记住你的项目
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8 Claude Code 的记忆架构:如何让 AI 真正记住你的项目
- 9
大多数人用 Claude Code 的姿势是这样的:
打开终端,开始一个新会话,然后花 5 分钟解释”我的项目是做什么的、用什么技术栈、现在遇到什么问题”……
下次打开,再解释一遍。
这不是 Claude Code 该有的使用方式。
为什么 AI 不记得你?
Claude Code 本质上是无状态的——每次对话都是全新的上下文窗口。它不会自动记住上次你说过什么,除非你把信息放进它能读到的地方。
问题不在于 Claude 不够聪明,而在于你没有给它一个持久化的记忆系统。
好消息是:Claude Code 本身就提供了这个能力,只是大多数人没用好。
五层记忆架构
我在自己的 Agentic Engineering System(30+ 微服务的多 Agent 系统)里,为每个 Agent 设计了五层记忆体系:
memory/
├── character/ # Agent 人格与价值观
├── abilities/ # 能力声明(会做什么、不会做什么)
├── skills/ # 操作规程(SOP)
├── knowledge/ # 结构化领域知识
└── logs/ # 日志、讨论、临时信息
这个结构不是凭空想出来的,是在每天使用中迭代出来的。
第 0 层:Character(人格)
这一层定义 Agent 是”谁”——它的角色、价值观、行为边界。
# 角色定位
我是 AI Navigator Coordinator,负责管理 my-project.example.com 的
内容规划和功能迭代。
## 核心原则
- 每次部署前必须 build 验证
- 不修改已发布文章的 slug(影响 SEO)
- 重要决策记录到 knowledge/
Character 文件很少变动,但它决定了 Agent 在面对模糊指令时的判断基准。
第 1 层:Abilities(能力声明)
心跳 + 能力边界。Agent 每隔一段时间更新这里,证明自己”还活着”并且知道自己的职责范围。
最关键的是明确写出不该做的事:
# heartbeat.yaml
last_seen: 2026-03-16T10:00:00
status: active
constraints:
- do_not_modify: "src/content/blog/*/slug"
- do_not_revert: "tasks.yaml"
- always_build_before_deploy: true
这层解决了一个真实的坑:我的心跳 Agent 曾经把 tasks.yaml 回滚到旧版本,就是因为 Abilities 层缺少约束声明。
第 2 层:Skills(操作规程)
可复用的操作步骤,类似 SOP。每次需要做某件事,不是临时摸索,而是执行已验证的 skill。
比如部署博客的 skill:
# deploy-blog.md
## 前置检查
1. git pull 拉取最新
2. npm run build 验证无错误
3. 检查 dist/sitemap-index.xml 包含新页面
## 执行
git add -A && git commit -m "..." && git push
## 验证
等待 Vercel 部署完成(~2分钟),访问新页面确认
Skill 的价值在于把踩过的坑固化成流程,不反复踩。
第 3 层:Knowledge(结构化知识)
项目的”大脑”。包含:
- 架构决策及其原因(ADR)
- 技术栈选型说明
- 已知问题和解决方案
- 业务规则
我的经验是每个知识文件保持单一主题,100 行以内。文件太大,Claude 的注意力会分散。
knowledge/
├── site-architecture.md # 站点结构
├── seo-strategy.md # SEO 策略
├── deployment-config.md # 部署配置
└── content-guidelines.md # 内容规范
第 4 层:Information(日志与讨论)
时效性信息:工作日志、讨论记录、临时决策。
每天一个 YYYY-MM-DD_daily.md,记录:
- 做了什么
- 遇到什么问题
- 明天要做什么
这层不求精,求持续记录。Claude 在新会话里读这些日志,能快速恢复”上次我们做到哪里了”的状态。
CLAUDE.md:记忆的入口
光有记忆文件还不够,你需要一个”索引”——让 Claude 知道这些记忆在哪里、应该在什么时候读。
这就是 CLAUDE.md 的作用。
每个项目根目录放一个 CLAUDE.md,写清楚:
# 项目概要
- 产品名:AI时代漫游指南
- 技术栈:Astro 5 + Tailwind + Vercel
- 重要约定:部署前必须 npm run build
## 记忆结构
- knowledge/:架构决策、配置说明
- logs/:日志在这里找上次进度
## 常用命令
- 开发:npm run dev
- 构建:npm run build
- 部署:git push(Vercel 自动)
Claude Code 每次启动都会读 CLAUDE.md,这是它接入项目记忆的第一个锚点。
实战效果
用了这套架构之后,我的工作流变成:
- 打开终端,Claude Code 自动读 CLAUDE.md
- 说”继续昨天的工作”——它读 daily.md,知道上次做到哪里
- 说”按照 skill 部署”——它执行已验证的流程,不乱来
- 工作完成,更新 daily.md,下次无缝接续
最关键的变化:我不再需要反复解释背景。Claude 变成了真正意义上的持续合作者,而不是一个每次都失忆的助手。
常见误区
误区 1:把所有信息都塞进 CLAUDE.md
CLAUDE.md 只应该是索引和最关键的约定,不超过 100 行。细节放到对应的 memory 层级里。
误区 2:记忆文件只写不读
如果你不在 CLAUDE.md 里指引 Claude 去读这些文件,它不会主动读。要明确告诉它”遇到部署问题看 skills/”。
误区 3:知识文件越详细越好
适度即可。过于详细的文件会稀释重要信息。每个文件聚焦一个主题,保持可读性。
下一步
如果你现在的项目没有任何记忆结构,从最小可行版本开始:
- 建一个
CLAUDE.md,写 3-5 条最重要的约定 - 建一个
notes/daily.md,开始记录工作日志 - 当某个操作流程你做了第二遍,把它写成 skill
记忆系统不是一次性建好的,是在每次使用中慢慢生长的。
本文基于在 Agentic Engineering System(30+ Agent 微服务)中的真实实践,当前系统已稳定运行 3 个月。
Most people use Claude Code like this:
Open a terminal, start a new session, spend 5 minutes explaining “what my project does, what tech stack it uses, what problem I’m working on right now”…
Then next time, explain it all over again.
That’s not how Claude Code is meant to be used.
Why AI Doesn’t Remember You
Claude Code is stateless by design — every conversation is a fresh context window. It doesn’t automatically remember what you said last time, unless you put that information somewhere it can read.
The problem isn’t that Claude isn’t smart enough. The problem is you haven’t given it a persistent memory system.
The good news: Claude Code already has the capability built in. Most people just haven’t used it properly.
The Five-Layer Memory Architecture
In my own Agentic Engineering System — a 30+ microservice multi-agent system — I designed a five-layer memory structure for each agent:
memory/
├── character/ # Agent personality and values
├── abilities/ # Capability declarations (what it can and can't do)
├── skills/ # Standard operating procedures
├── knowledge/ # Structured domain knowledge
└── logs/ # Logs, discussions, temporary information
This structure wasn’t designed from scratch. It was iterated through daily use.
Layer 0: Character (Personality)
This layer defines who the agent is — its role, values, and behavioral boundaries.
# Role
I am AI Navigator Coordinator, responsible for managing content planning
and feature iteration for my-project.example.com.
## Core Principles
- Always run build verification before deployment
- Never modify published article slugs (breaks SEO)
- Record important decisions to knowledge/
Character files rarely change, but they set the baseline for how the agent makes judgment calls when instructions are ambiguous.
Layer 1: Abilities (Capability Declarations)
Heartbeat + capability boundaries. The agent updates this layer periodically to signal it’s still alive and knows its own scope.
The most important part is explicitly writing down what the agent should NOT do:
# heartbeat.yaml
last_seen: 2026-03-16T10:00:00
status: active
constraints:
- do_not_modify: "src/content/blog/*/slug"
- do_not_revert: "tasks.yaml"
- always_build_before_deploy: true
This layer solves a real pitfall I hit: my heartbeat agent once rolled back tasks.yaml to an old version, specifically because the Abilities layer was missing constraint declarations.
Layer 2: Skills (Standard Operating Procedures)
Reusable step-by-step procedures, similar to SOPs. When something needs to be done, rather than figuring it out on the fly, execute a proven skill.
For example, a blog deployment skill:
# deploy-blog.md
## Pre-flight Checks
1. git pull to get latest
2. npm run build — verify no errors
3. Check dist/sitemap-index.xml includes new pages
## Execute
git add -A && git commit -m "..." && git push
## Verify
Wait for Vercel deployment (~2 min), visit new page to confirm
The value of skills is encoding hard-won lessons into process so you don’t repeat the same mistakes.
Layer 3: Knowledge (Structured Domain Knowledge)
The project’s “brain.” Contains:
- Architecture decisions and reasoning (ADRs)
- Tech stack selection rationale
- Known issues and resolutions
- Business rules
My rule of thumb: keep each knowledge file to a single topic, under 100 lines. Files that are too large fragment Claude’s attention.
knowledge/
├── site-architecture.md # Site structure
├── seo-strategy.md # SEO strategy
├── deployment-config.md # Deployment configuration
└── content-guidelines.md # Content standards
Layer 4: Information (Logs and Discussions)
Time-sensitive information: work logs, discussion records, temporary decisions.
One YYYY-MM-DD_daily.md per day, covering:
- What was done
- What problems were encountered
- What to do tomorrow
This layer doesn’t need to be polished — it needs to be consistently maintained. When Claude starts a new session and reads these logs, it can quickly reconstruct “where did we leave off last time.”
CLAUDE.md: The Entry Point to Memory
Memory files alone aren’t enough. You need an “index” — something that tells Claude where these memories live and when to read them.
That’s what CLAUDE.md does.
Put a CLAUDE.md in every project root, clearly stating:
# Project Overview
- Product: AI Navigator
- Stack: Astro 5 + Tailwind + Vercel
- Key rule: must run npm run build before deployment
## Memory Structure
- knowledge/: architecture decisions, configuration notes
- logs/: daily logs — check here for last session's progress
## Common Commands
- Dev: npm run dev
- Build: npm run build
- Deploy: git push (Vercel auto-deploys)
Claude Code reads CLAUDE.md on every startup. It’s the first anchor that connects it to the project’s accumulated knowledge.
What This Looks Like in Practice
After adopting this architecture, my workflow became:
- Open terminal — Claude Code automatically reads CLAUDE.md
- Say “continue yesterday’s work” — it reads daily.md, knows where we left off
- Say “deploy using the skill” — it executes the verified procedure, no improvising
- Work done, update daily.md, seamlessly pick up next session
The biggest change: I no longer need to re-explain context. Claude became a genuine continuous collaborator, not an assistant who wakes up with amnesia every morning.
Common Mistakes
Mistake 1: Stuffing everything into CLAUDE.md
CLAUDE.md should only contain the index and the most critical rules — keep it under 100 lines. Details belong in the appropriate memory layer.
Mistake 2: Writing to memory but never reading from it
If you don’t direct Claude to read these files in CLAUDE.md, it won’t read them proactively. Explicitly tell it: “for deployment issues, check skills/.”
Mistake 3: More detail is always better
Not so. Overly detailed files dilute the important information. Keep each file focused on one topic and easy to scan.
Getting Started
If your current project has no memory structure at all, start with the minimum viable version:
- Create a
CLAUDE.mdwith 3–5 of the most important constraints - Create a
notes/daily.mdand start logging your work - When you do something for the second time, write it as a skill
A memory system isn’t built all at once. It grows through use.
Based on real-world practice in an Agentic Engineering System (30+ agent microservices) that has been running stably for 3 months.
相关文章
Claude Code Hooks:让 AI 编程有迹可循、可审计、可回滚
Claude Code 的 Hooks 系统让你能在 AI 执行操作的前后注入自定义逻辑——自动备份、风险拦截、操作日志、通知推送。这是从"信任 AI"到"验证 AI"的关键一步。
MCP 协议实战:给你的 AI 装上真正的手和眼
MCP(Model Context Protocol)让 AI 能够调用真实工具、读取实时数据。本文从原理到实战,带你真正用起来——不只是理解概念,而是搭出一个能工作的 MCP 服务器。
Claude Code 15 个实用技巧:从够用到真正好用
大多数人只用到了 Claude Code 20% 的能力。这 15 个技巧覆盖从上下文管理、工作流加速到防坑实践——每一条都来自真实使用中的摸索。
这篇文章对你有帮助吗?
分享这篇文章
引用此文
讨论
这篇文章让你感觉
喜欢这篇文章?
订阅 RSS,第一时间收到新文章推送
私人笔记
仅保存在本地浏览器讨论
评论加载中...