From session-learn
Queries four-layer storage—user configs (~/.claude/CLAUDE.md), project/submodule AGENTS.md/CLAUDE.md, and memory dirs—to recall historical knowledge and inject into Claude Code sessions via /recall or frustration detection.
How this skill is triggered — by the user, by Claude, or both
Slash command
/session-learn:knowledge-fetchThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
从四层存储查询历史知识,并注入当前会话上下文。
从四层存储查询历史知识,并注入当前会话上下文。
用户可能感到烦躁,因为:
处理方式: 先主动道歉,再展示召回结果。
用户只是想查询历史记录:
处理方式: 直接展示召回结果,不假设用户沮丧。
用户调用 /recall 无参数:
处理方式: 展示所有四层的简洁摘要。
与 auto-extract 存储层完全对应:
| 层级 | 核心问题 | 特性 |
|---|---|---|
| Layer 1: 用户配置 | "每个会话都需要知道什么?" | 跨项目、身份性、自动加载 |
| Layer 2: 项目根配置 | "这个项目整体需要知道什么?" | 项目级、版本控制 |
| Layer 3: 子模块配置 | "这个子模块需要知道什么?" | 子模块特定、就近原则 |
| Layer 4: 情境记忆 | "特定情境下需要召回什么?" | 情境性、按需查询 |
查询前必须先探测,不假设任何特定文件、工具或服务存在。
扫描用户级配置文件,检测是否存在:
~/.claude/CLAUDE.md检测到哪个查询哪个。不存在则跳过该层。
扫描项目根目录,检测以下文件是否存在:
{repo}/AGENTS.md{repo}/CLAUDE.md{repo}/.claude/CLAUDE.md所有检测到的文件均参与查询。
扫描项目中子目录里已存在的配置文件(AGENTS.md 或 CLAUDE.md)。
探测方式: 搜索 {repo}/**/AGENTS.md 和 {repo}/**/CLAUDE.md(排除根目录,排除 node_modules 等)。
如果有相关参数(如 /recall oc-tweaks 发布),优先查询语义最近的子模块配置。
按优先级探测可用的记忆后端:
{repo}/.opencode/memory/、{repo}/.memory/)或全局是否存在 memory 目录(含 *.md 文件)。有则用 Read 操作查询。.memory/ 目录: 使用项目内的 .memory/ 目录(如果存在)。原则: 探测到什么用什么。不要求用户安装任何额外依赖。
分析用户为什么调用 /recall:
如果用户提供了参数(如 /recall 代码风格),用它们作为主要关键词。
如果参数类似"我不知道/你看看/refresh",视为场景 3(主动刷新):四层都查,每层展示最相关的 2-3 条。
1. 读取探测到的用户级配置文件
2. 按 section 标题匹配关键词
3. 提取相关段落
1. 读取探测到的项目根配置文件(可能有多个)
2. 按 section 标题匹配关键词
3. 提取相关段落
1. 读取探测到的子模块配置文件
2. 优先查询与关键词语义最近的子模块
3. 提取相关段落
根据探测到的后端类型执行对应查询:
按层级分组展示结果:
## 召回结果
### L1 用户配置(来自 {探测到的文件名})
找到 X 条相关内容:
- **[Section 标题]**: [相关内容摘要]
### L2 项目根配置(来自 {探测到的文件名})
找到 X 条相关内容:
- **[Section 标题]**: [相关内容摘要]
### L3 子模块配置(来自 {探测到的文件名})
找到 X 条相关内容:
- **[Section 标题]**: [相关内容摘要]
### L4 情境记忆(来自 {探测到的后端描述})
找到 X 条相关记录:
- **[主题]**: [内容摘要]
---
**应用到当前情况**: 基于这些召回,我会...
如果同一主题在多层命中,视为存储不一致:必须显式标注来源并提醒清理。
根据触发场景调整响应:
| 场景 | 响应开头 |
|---|---|
| 沮丧 | "抱歉让你重复了。我回顾了之前的记录..." |
| 常规 | "我查询了历史记录,找到以下相关内容..." |
| 刷新 | "以下是当前相关的知识摘要..." |
如果用户提供了主题(如 /recall 代码风格):
如果没有提供主题:
如果某层已有足够相关内容:
我查询了四层数据源,但没有找到与 "[主题]" 相关的记录。
已搜索:
- L1 用户配置 - {文件名或"未检测到"} - 无匹配
- L2 项目根配置 - {文件名或"未检测到"} - 无匹配
- L3 子模块配置 - {文件名或"未检测到"} - 无匹配
- L4 情境记忆 - {后端描述或"无可用后端"} - 无匹配
可能原因:
- 这个话题还没有被学习过
- 尝试使用不同的关键词
你能告诉我具体是什么情况吗?
跳过该层并继续查询下一层,在结果中注明"未检测到"。
L4 情境记忆:无可用后端,仅查询了配置文件层。
跳过 Layer 3,不报错。在结果中注明"无子模块配置"。
| auto-extract 存储层 | knowledge-fetch 查询层 | 核心问题 |
|---|---|---|
| L1 用户配置 | L1 用户配置 | "每个会话都需要知道什么?" |
| L2 项目根配置 | L2 项目根配置 | "这个项目整体需要知道什么?" |
| L3 子模块配置 | L3 子模块配置 | "这个子模块需要知道什么?" |
| L4 情境记忆 | L4 情境记忆 | "特定情境下需要召回什么?" |
边界原则:
确保双向一致:学习时分类到哪层,召回时就从哪层查询。
Recall facts from past sessions via memoir. STORE PATH: ALWAYS compute first via `STORE=$(bash "$CLAUDE_PLUGIN_ROOT/scripts/derive-store-path.sh")` (or `$MEMOIR_STORE`). Pass `-s "$STORE"` on every call — never rely on memoir's connected default (frequently stale). PROCEDURE (single-shot default): ONE `summarize --depth 3 -n default` → pick at most 5–7 keys → batch `get`. Only escalate to drill (batched `--keys`) if the depth-3 response shows `total_memories > 1000` AND the query is broad. Never call `summarize --depth 1` separately — `--depth 3` already returns count + full key listing. EXCLUDE `metrics.*` unless args contain `--include-metrics`. NEVER shell out to `memoir recall` (legacy LLM-bundled, slow, requires OPENAI_API_KEY). First reply line MUST be a mode marker `[mode=get|fast|drill|flat|blame|diff]`. DEFAULT ON: invoke for any question or task that may depend on past preferences, decisions, conventions, or knowledge — questions touching prior state, meta/overview asks, design/implementation prompts where output may reflect prior style, SessionStart hints, or any moment you'd otherwise silently apply remembered facts. SKIP only for mechanical single-symbol lookups, throwaway scratch work, or explicit user opt-out. Defer to memoir-onboard for repo-structure questions (it owns `codebase:onboard`). Cost of an unused recall is low; cost of missing a remembered preference is high.
Searches and retrieves memories from Cortex persistent memory using WRRF retrieval. Use for past decisions, patterns, bugs, or architecture context.
Injects stored memory into responses when the user asks about project state, history, prior work, or codebase knowledge. Useful for maintaining context across sessions.
npx claudepluginhub cuipengfei/prompts --plugin session-learn