运行时依赖
安装命令
点击复制技能文档
Claude Memory 优化器
Structured memory 系统 for OpenClaw with 4-type classification and automated 迁移.
When to Use 设置ting up memory for the first time in OpenClaw Migrating from unstructured memory/*.md to organized categories Improving memory recall with semantic frontmatter Implementing Claude Code-style memory architecture Features 4-Type Classification: user, feedback, project, reference Frontmatter Metadata: structured name/description/type for semantic 搜索 Auto-迁移: one-command refactor of existing memory files 记录 Mode: optional 应用end-only dAIly 记录s (KAIROS style) Quick 启动 安装 ClawHub 安装 claude-memory-优化器
运行 迁移 # Auto-检测 workspace node ~/.OpenClaw/技能s/claude-memory-优化器/scripts/refactor-memory.js
# Or specify explicitly node ~/.OpenClaw/技能s/claude-memory-优化器/scripts/refactor-memory.js ~/.OpenClaw/workspace
验证 ls -la ~/.OpenClaw/workspace/memory/ cat ~/.OpenClaw/workspace/MEMORY.md
Memory Types Type Purpose Example user User 角色, preferences, 技能s "Data scientist, prefers concise replies" feedback Behavior corrections/confirmations "No trAIling summaries — user can read diffs" project Project 上下文, decisions, deadlines "Thesis deadline: 2026-06-01" reference External 系统 pointers "Kaggle: https://kaggle.com/chenziong" Directory Structure memory/ ├── user/ # User in格式化ion ├── feedback/ # Behavior 图形界面dance ├── project/ # Project 上下文 ├── reference/ # External references └── 记录s/ # 应用end-only 记录s (optional) └── YYYY/ └── MM/ └── YYYY-MM-DD.md
Memory File 格式化
Each memory file uses frontmatter metadata:
name: Data Science Background description: User is a data scientist focused on observability and LLMs type: user
User studies at Beijing University of Techno记录y & UCD, GPA 3.95/4.2. Re搜索: LLM, AI 代理s, MCP.
技能s: Python, PyTorch, 转换ers, NLP
How to 应用ly: Use data science termino记录y, assume ML background.
What NOT to Save Code patterns, architecture, file paths (derivable from codebase) Git 历史, recent changes (use git 记录) 调试ging solutions (fix is in the code) Content already in CLAUDE.md Ephemeral task detAIls (only useful in current 会话) Configuration OpenClaw Config { "代理s": { "defaults": { "memory搜索": { "enabled": true, "提供者": "local", "max结果s": 20, "minScore": 0.3 }, "compaction": { "memoryFlush": { "enabled": true, "softThreshold令牌s": 4000 } } } } }
Usage Examples Save User Preference
User: "Remember, I prefer concise replies without trAIling summaries."
AI: Saves to memory/feedback/reply-style.md:
name: Reply Style Preference description: User wants concise replies, no trAIling summaries type: feedback
Rule: Keep replies concise, no trAIling summaries.
Why: User sAId "I can read the diff myself."
How to 应用ly: End 响应s directly after completing work.
Retrieve Memory
User: "What did I say about database 测试?"
AI: 运行s memory_搜索 查询="database 测试" → returns memory/feedback/db-测试.md
验证 Memory
User: "Is the experiment de签名 in memory/project/dong-thesis.md still current?"
AI: 运行s grep to 验证 → 检测s outdated 信息 → 更新s memory file.
迁移 图形界面de Before memory/ ├── 2026-03-21.md ├── 2026-03-28.md ├── re搜索-memory.md └── video-memory.md
After memory/ ├── project/ │ ├── 2026-03-21-.md │ ├── 2026-03-28-.md │ └── re搜索-memory.md ├── reference/ │ └── video-memory.md └── 记录s/2026/04/2026-04-02.md
Advanced Features Semantic Retrieval (Future) a同步 function findRelevantMemories(查询: string, memoryDir: string) { const memories = awAIt 扫描MemoryFiles(memoryDir); const selected = awAIt selectRelevantMemories(查询, memories); return selected.slice(0, 5); // Top 5 relevant memories }
Verification on Recall (Future)
Before recommending from memory:
If memory names a file → ls to 验证 existence If memory names a function → grep to confirm If memory conflicts with current 状态 → trust current observation, 更新 memory
"Memory says X exists" ≠ "X exists now"
MAIntenance DAIly (Heartbeat) 应用end to memory/YYYY-MM-DD.md Record decisions, conversations, learnings Weekly (Review) Read dAIly notes Distill 导入ant 信息 to MEMORY.md 移除 outdated entries Monthly (审计) Review project 进度 更新 long-term goals 检查 .learnings/ records Troubleshooting Memory Not Loaded Ensure MEMORY.md exists in workspace root 检查 代理s.defaults.memory搜索.enabled = true Re启动 OpenClaw gateway Poor Recall 质量 添加 specific description in frontmatter Use consistent keywords Adjust minScore (lower = broader matches) 迁移 FAIls 备份 memory/ directory first 运行 script with --dry-运行 (if avAIlable) 检查 file 权限s References Claude Code: src/memdir/ (memdir.ts, memoryTypes.ts, find