> **Phase 3**: Hook 正式接入 · Slash Command · Plugin 打包
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-code-memory-skill:claudecodememoryskillThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> **Phase 3**: Hook 正式接入 · Slash Command · Plugin 打包
Phase 3: Hook 正式接入 · Slash Command · Plugin 打包
当用户在 Claude Code 中进行多轮项目开发、Bug 修复、需求分析或测试复盘时,本 Skill 负责将对话沉淀为可检索的结构化 Markdown 记忆库,并在新会话中根据用户输入自动检索并注入相关历史上下文。
Phase 3 新增:Hook 自动化触发、Slash Command 手动调用、Plugin 一键安装。
当用户出现以下意图时,应优先使用本 Skill:
本 Skill 在 .claude-plugin/plugin.json Manifest 中声明了以下 Slash Command(CLI 映射模式):
| 命令 | CLI 映射 | 用途 |
|---|---|---|
/memory save <主题> | scripts/summarize_session.py | 保存当前对话为结构化 Markdown 记忆 |
/memory retrieve <查询> | scripts/retrieve_memory.py | 检索相关历史记忆,注入上下文 |
/memory rebuild | scripts/update_index.py | 从 Markdown 文件重建 index.json 索引 |
实现说明:Slash Command 通过 .claude-plugin/plugin.json 声明,命令定义文件位于 commands/ 目录,实际逻辑在 scripts/ 中实现。Claude Code 解析到命令后,调用对应的 Python CLI 入口。
/memory save Claude Code 记忆系统架构
/memory retrieve 登录超时 Bug 修复
/memory rebuild
在以下时机自动或手动触发:
UserPromptSubmit Hook 调用 auto_save.shStop 触发 → 调用 post_conversation.sh/memory save <主题> 命令自动保存间隔可通过以下方式配置(优先级从高到低):
MEMORY_AUTO_SAVE_INTERVAL(例如 export MEMORY_AUTO_SAVE_INTERVAL=5)config.json 中的 auto_save_interval 字段在以下时机自动或手动触发:
PrePrompt 触发 → 调用 pre_prompt.sh/memory retrieve <查询> 命令每条记忆包含结构化字段:
# 主题名称
> 更新时间:YYYY-MM-DD HH:MM:SS
## 摘要
结构化摘要(规则抽取,不超过 500 字)
## 关键词
关键词1, 关键词2, 关键词3
## 关键决策
- 决策1
- 决策2
(无决策时显示"无明确关键决策。")
## 待办事项
- 待办1
- 待办2
(无待办时显示"无明确待办事项。")
## 原始对话摘录
对话原文(低优先级补充)
将检索结果注入 Claude Code 上下文时,遵循严格优先级:
| 异常情况 | 处理方式 |
|---|---|
index.json 损坏 | load_index() 返回空字典,不崩溃 |
| 检索无匹配 | 返回"未检索到相关历史记忆。",正常回答 |
| Markdown 文件被删除 | 跳过,用 update_index.py 重建 |
| jieba 未安装 | 自动回退到正则规则法 |
| Python 脚本失败 | 不阻塞 Claude Code 正常响应,静默降级 |
| Hook 未配置 | Skill 仍可通过 /memory 命令和 CLI 手动使用 |
| 决策/待办为空 | 显示占位文本,不虚构内容 |
memory/ 目录,不会上传index.json 使用原子写入防止损坏README.md 当成记忆文件Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub junhaozhang-127/claudecodememoryskill --plugin claude-code-memory-skill