Claude Memory
A structured, layered memory architecture for OpenClaw agents. Uses a 4-type classification (user/feedback/project/reference) for organized memory, combined with semantic search and progressive disclosure for token-efficient retrieval.
Architecture
CODEBLOCK0
4-Type Classification
| Type | Purpose | Examples |
|---|
| user | Human's personal info, preferences, relationships | IDs, timezone, family, privacy rules |
| feedback |
Corrections AND confirmations from human | "Check docs first", "That approach was right" |
|
project | Work items, tasks, known issues | Active bugs, cron jobs, cleanup history |
|
reference | Technical resources, environment | Runtime config, connected services, security events |
Setup
Run the init script to create the directory structure and template files:
CODEBLOCK1
This creates:
- -
MEMORY.md with empty section templates - INLINECODE1 with format guide
- INLINECODE2 directory
- Instructions to update AGENTS.md memory rules
After running, edit MEMORY.md sections with actual content and update AGENTS.md to include the memory rules from references/agents-rules.md.
Write Rules
- 1. Feedback immediately — When human corrects you, write to
memory/feedback.md NOW. Not later, not "I'll remember", NOW. - Record confirmations too — When human validates a non-obvious approach ("yes exactly", "keep doing that"), record it. If you only save corrections, you'll avoid past mistakes but drift away from approaches the human has already approved, becoming overly cautious.
- MEMORY.md ≤ 10KB — Hybrid format: inline high-frequency info for direct readability, pointers to
topics/ for depth. If it exceeds 10KB, move lower-frequency content to topics/ — the content is preserved, just relocated. - Read before answer — When MEMORY.md says "see topics/X.md", read that file first. Never answer from a one-line summary.
- Absolute dates only — Convert relative dates ("yesterday", "last week") to absolute dates (e.g., "2026-04-01") when writing. Memories should remain interpretable months later.
- Don't memorize what tools can look up — File paths, git history, code structure, current weather, live data.
- Don't memorize ephemeral state — In-progress work, temporary conversation context, things that resolve themselves.
What NOT to Save
- - Information tools can look up in real-time (weather, time, current stock prices)
- Code patterns, architecture, file paths, project structure — derivable by reading the project
- Git history, recent changes, who-changed-what —
git log is authoritative - Debugging solutions or fix recipes — the fix is in the code; the commit has the context
- Ephemeral task details: in-progress work, temporary state, current conversation context
- Anything already documented in CLAUDE.md or equivalent project files
Verification Rules
Memories are long-term assets, not consumables. They don't expire. But some memories need verification before use:
- - Personal preferences, relationships, history events — Generally stable. No verification needed.
- Technical state (service configs, bug status, installed versions) — Verify before acting on them. The world changes.
- Before recommending based on memory — If the memory names a specific file, check it exists. If it names a function or flag, grep for it. "The memory says X exists" is not the same as "X exists now."
Feedback Format
Each feedback entry follows this structure. Two types: correction (don't do X) and confirmation (keep doing X).
CODEBLOCK2
Heartbeat Maintenance
Memory is an asset, not a consumable. Memories should not be deleted because they're old.
⚠️ Setup requirement: This 4-phase routine MUST be written into HEARTBEAT.md, NOT AGENTS.md. HEARTBEAT.md is injected only during heartbeat polls (token-efficient), while AGENTS.md is loaded every session (wastes token on every message). Write memory write rules in AGENTS.md, write this maintenance routine in HEARTBEAT.md.
During heartbeat polls, follow this 4-phase care routine:
Phase 1 — Catch-up (补漏)
- - Did the human correct or confirm something this session that isn't recorded in
memory/feedback.md? - Are there significant events from this conversation not yet in daily notes?
Phase 2 — Consolidate (整合)
- - Review recent daily notes (last 1-3 days) for insights worth elevating to
MEMORY.md or topics/. - Merge new signal into existing topic files rather than creating near-duplicates.
- Daily notes that have been fully consolidated can be left in place as historical records — do NOT delete them.
Phase 3 — Verify (校验)
- - Pick 1-2 entries from
MEMORY.md and spot-check if they're still accurate. - Focus on technical state entries (service configs, bug status, versions). Personal info and historical events don't need verification.
- If a memory conflicts with current reality, update it — don't delete it, correct it.
Phase 4 — Tidy (整理)
- - If
MEMORY.md exceeds 10KB, relocate lower-frequency content to topics/. The content is preserved, just moved to a more appropriate home. - Ensure topic files have a timestamp annotation: INLINECODE21
- Add pointers in MEMORY.md for any newly created topic files.
Design Decisions
- - MEMORY.md as hybrid (content + pointers) — High-frequency info is directly readable for warmth and efficiency. Deep details live in
topics/. Not a pure index — an agent's memory should feel like a person's, not a database. - Memories don't expire — Unlike a coding agent where project state changes fast, a daily assistant's memories are long-term assets. Old memories get relocated (to topics/) if MEMORY.md needs space, never deleted.
- Feedback includes confirmations — Recording only corrections makes the agent overly cautious. Validated approaches ("yes, keep doing that") are just as important to remember.
- Verification is selective — Personal preferences and history are stable facts. Only technical state (configs, versions, bug status) needs re-verification.
- Feedback as separate file — Highest-priority memory. Must never be buried under daily notes.
- Topics for depth — Low-frequency but detailed content lives in
topics/ to keep MEMORY.md lean. - No auto-extraction — Requires OpenClaw runtime support. Currently manual via rules.
Advanced
For detailed AGENTS.md rules, see references/agents-rules.md.
For troubleshooting, see references/encoding-notes.md.
Claude Memory
为OpenClaw代理设计的一种结构化、分层记忆架构。采用4类分类法(用户/反馈/项目/参考)实现有序记忆,结合语义搜索和渐进式披露实现高效令牌检索。
架构
MEMORY.md (≤10KB,每轮通过系统提示注入)
├── 可直接读取的高频信息(内联)
├── 指向topics/中详细内容的指针
└── 4个部分:user | feedback → feedback.md | project | reference
memory/
├── feedback.md # 来自人类的纠正和确认(最重要)
├── YYYY-MM-DD.md # 每日原始笔记
└── topics/ # 低频大容量内容
├── agent-ids.md
├── known-issues.md
└── ...(领域特定)
4类分类法
| 类型 | 用途 | 示例 |
|---|
| user | 用户的个人信息、偏好、关系 | ID、时区、家庭、隐私规则 |
| feedback |
来自人类的纠正和确认 | 先查文档、那个方法是对的 |
|
project | 工作项、任务、已知问题 | 活跃的bug、定时任务、清理历史 |
|
reference | 技术资源、环境 | 运行时配置、已连接服务、安全事件 |
设置
运行初始化脚本以创建目录结构和模板文件:
bash
python scripts/init_memory.py <工作空间路径>
这将创建:
- - 包含空章节模板的MEMORY.md
- 包含格式指南的memory/feedback.md
- memory/topics/目录
- 更新AGENTS.md记忆规则的说明
运行后,用实际内容编辑MEMORY.md的各部分,并更新AGENTS.md以包含来自references/agents-rules.md的记忆规则。
写入规则
- 1. 立即记录反馈 — 当人类纠正你时,立即写入memory/feedback.md。不要稍后,不要我会记住,立即。
- 也记录确认 — 当人类验证一个非显而易见的方法时(是的,没错、继续这样做),记录下来。如果你只保存纠正,你会避免过去的错误,但会偏离人类已经批准的方法,变得过于谨慎。
- MEMORY.md ≤ 10KB — 混合格式:内联高频信息便于直接读取,指向topics/的指针用于深度内容。如果超过10KB,将低频内容移至topics/ — 内容被保留,只是重新定位。
- 先读再答 — 当MEMORY.md说见topics/X.md时,先读取该文件。永远不要根据一行摘要来回答。
- 仅使用绝对日期 — 写入时将相对日期(昨天、上周)转换为绝对日期(例如2026-04-01)。记忆应在数月后仍可解读。
- 不记忆工具可查询的内容 — 文件路径、git历史、代码结构、当前天气、实时数据。
- 不记忆临时状态 — 进行中的工作、临时对话上下文、会自行解决的事情。
不应保存的内容
- - 工具可以实时查询的信息(天气、时间、当前股票价格)
- 代码模式、架构、文件路径、项目结构 — 可通过阅读项目推导
- Git历史、最近更改、谁改了什么 — git log是权威来源
- 调试解决方案或修复方法 — 修复在代码中;提交记录有上下文
- 临时任务细节:进行中的工作、临时状态、当前对话上下文
- 任何已在CLAUDE.md或等效项目文件中记录的内容
验证规则
记忆是长期资产,而非消耗品。它们不会过期。但某些记忆在使用前需要验证:
- - 个人偏好、关系、历史事件 — 通常稳定。无需验证。
- 技术状态(服务配置、bug状态、已安装版本) — 在据此行动前先验证。世界在变化。
- 在基于记忆推荐之前 — 如果记忆提到了特定文件,检查它是否存在。如果提到了函数或标志,用grep搜索它。记忆说X存在不等于X现在存在。
反馈格式
每条反馈条目遵循以下结构。两种类型:纠正(不要做X)和确认(继续做X)。
markdown
F###: 规则描述(日期)
F###: 已确认的方法描述(确认 日期)
- - 上下文: 当时正在处理什么
- 原因: 是什么让这个方法值得注意或得到验证
心跳维护
记忆是资产,而非消耗品。不应因为记忆陈旧就删除它们。
⚠️ 设置要求:这个4阶段例程必须写入HEARTBEAT.md,而非AGENTS.md。HEARTBEAT.md仅在心跳轮询时注入(令牌高效),而AGENTS.md每次会话都会加载(每条消息浪费令牌)。在AGENTS.md中写入记忆写入规则,在HEARTBEAT.md中写入此维护例程。
在心跳轮询期间,遵循以下4阶段维护例程:
阶段1 — 补漏
- - 人类是否在本会话中纠正或确认了尚未记录在memory/feedback.md中的内容?
- 本次对话中是否有尚未记入每日笔记的重要事件?
阶段2 — 整合
- - 审查最近的每日笔记(最近1-3天),寻找值得提升到MEMORY.md或topics/的见解。
- 将新信号合并到现有主题文件中,而不是创建近乎重复的文件。
- 已完全整合的每日笔记可以保留在原位作为历史记录 — 不要删除它们。
阶段3 — 校验
- - 从MEMORY.md中选择1-2条条目,抽查它们是否仍然准确。
- 重点关注技术状态条目(服务配置、bug状态、版本)。个人信息和历史事件无需验证。
- 如果记忆与当前现实冲突,更新它 — 不要删除,要纠正。
阶段4 — 整理
- - 如果MEMORY.md超过10KB,将低频内容重新定位到topics/。内容被保留,只是移动到更合适的位置。
- 确保主题文件有时间戳注释:> 创建日期:YYYY-MM-DD | 更新日期:YYYY-MM-DD
- 为任何新创建的主题文件在MEMORY.md中添加指针。
设计决策
- - MEMORY.md作为混合体(内容+指针) — 高频信息可直接读取,实现温暖和效率。深层细节存在于topics/中。不是纯索引 — 代理的记忆应该像人的记忆,而不是数据库。
- 记忆不会过期 — 与编码代理项目状态变化快不同,日常助手的记忆是长期资产。如果MEMORY.md需要空间,旧记忆会被重新定位(到topics/),永远不会被删除。
- 反馈包含确认 — 只记录纠正会使代理过于谨慎。已验证的方法(是的,继续这样做)同样重要需要记住。
- 验证是有选择性的 — 个人偏好和历史是稳定的事实。只有技术状态(配置、版本、bug状态)需要重新验证。
- 反馈作为单独文件 — 最高优先级的记忆。绝不能埋没在每日笔记之下。
- 主题用于深度内容 — 低频但详细的内容存在于topics/中,以保持MEMORY.md精简。
- 无自动提取 — 需要OpenClaw运行时支持。目前通过规则手动操作。
高级
关于详细的AGENTS.md规则,请参见references/agents-rules.md。
关于故障排除,请参见references/encoding-notes.md。