compound-learnings

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Compound Learnings

整合学习成果

Transform ephemeral session learnings into permanent, compounding capabilities.
将临时的会话学习成果转化为可不断积累的永久能力。

When to Use

适用场景

  • "What should I learn from recent sessions?"
  • "Improve my setup based on recent work"
  • "Turn learnings into skills/rules"
  • "What patterns should become permanent?"
  • "Compound my learnings"
  • “我应该从近期会话中学到什么?”
  • “根据近期工作改进我的设置”
  • “将学习成果转化为Skills/规则”
  • “哪些模式应该固化为永久规范?”
  • “整合我的学习成果”

Process

操作流程

Step 1: Gather Learnings

步骤1:收集学习成果

bash
undefined
bash
undefined

List learnings (most recent first)

列出学习成果(按时间倒序)

ls -t $CLAUDE_PROJECT_DIR/.claude/cache/learnings/*.md | head -20
ls -t $CLAUDE_PROJECT_DIR/.claude/cache/learnings/*.md | head -20

Count total

统计总数

ls $CLAUDE_PROJECT_DIR/.claude/cache/learnings/*.md | wc -l

Read the most recent 5-10 files (or specify a date range).
ls $CLAUDE_PROJECT_DIR/.claude/cache/learnings/*.md | wc -l

读取最近的5-10个文件(或指定日期范围)。

Step 2: Extract Patterns (Structured)

步骤2:提取结构化模式

For each learnings file, extract entries from these specific sections:
Section HeaderWhat to Extract
## Patterns
or
Reusable techniques
Direct candidates for rules
**Takeaway:**
or
**Actionable takeaway:**
Decision heuristics
## What Worked
Success patterns
## What Failed
Anti-patterns (invert to rules)
## Key Decisions
Design principles
Build a frequency table as you go:
markdown
| Pattern | Sessions | Category |
|---------|----------|----------|
| "Check artifacts before editing" | abc, def, ghi | debugging |
| "Pass IDs explicitly" | abc, def, ghi, jkl | reliability |
针对每个学习成果文件,从以下特定章节提取内容:
章节标题提取内容
## Patterns
Reusable techniques
可直接转化为规则的候选内容
**Takeaway:**
**Actionable takeaway:**
决策启发式规则
## What Worked
成功模式
## What Failed
反模式(可转化为规则)
## Key Decisions
设计原则
在提取过程中构建频率表:
markdown
| 模式 | 会话ID | 分类 |
|---------|----------|----------|
| “编辑前检查产物” | abc, def, ghi | 调试 |
| “显式传递ID” | abc, def, ghi, jkl | 可靠性 |

Step 2b: Consolidate Similar Patterns

步骤2b:合并相似模式

Before counting, merge patterns that express the same principle:
Example consolidation:
  • "Artifact-first debugging"
  • "Verify hook output by inspecting files"
  • "Filesystem-first debugging" → All express: "Observe outputs before editing code"
Use the most general formulation. Update the frequency table.
统计前,合并表达相同原则的模式:
合并示例:
  • “以产物为核心的调试”
  • “通过检查文件验证Hook输出”
  • “以文件系统为核心的调试” → 统一为:“编辑代码前先观察输出结果”
使用最通用的表述,并更新频率表。

Step 3: Detect Meta-Patterns

步骤3:识别元模式

Critical step: Look at what the learnings cluster around.
If >50% of patterns relate to one topic (e.g., "hooks", "tracing", "async"): → That topic may need a dedicated skill rather than multiple rules → One skill compounds better than five rules
Ask yourself: "Is there a skill that would make all these rules unnecessary?"
关键步骤: 分析学习成果的聚类方向。
如果超过50%的模式围绕同一主题(如“Hooks”“追踪”“异步”): → 该主题可能需要一个专属Skill,而非多条规则 → 一个Skill的积累效果优于五条规则
自问:“是否存在某个Skill可以替代所有这些规则?”

Step 4: Categorize (Decision Tree)

步骤4:分类(决策树)

For each pattern, determine artifact type:
Is it a sequence of commands/steps?
  → YES → SKILL (executable > declarative)
  → NO ↓

Should it run automatically on an event (SessionEnd, PostToolUse, etc.)?
  → YES → HOOK (automatic > manual)
  → NO ↓

Is it "when X, do Y" or "never do X"?
  → YES → RULE
  → NO ↓

Does it enhance an existing agent workflow?
  → YES → AGENT UPDATE
  → NO → Skip (not worth capturing)
Artifact Type Examples:
PatternTypeWhy
"Run linting before commit"Hook (PreToolUse)Automatic gate
"Extract learnings on session end"Hook (SessionEnd)Automatic trigger
"Debug hooks step by step"SkillManual sequence
"Always pass IDs explicitly"RuleHeuristic
针对每个模式,确定其产物类型:
它是一系列命令/步骤吗?
  → 是 → SKILL(可执行优于声明式)
  → 否 ↓

它是否应在特定事件(SessionEnd、PostToolUse等)触发时自动运行?
  → 是 → HOOK(自动优于手动)
  → 否 ↓

它属于“当X发生时执行Y”或“永远不要执行X”的类型吗?
  → 是 → RULE
  → 否 ↓

它是否能增强现有Agent的工作流?
  → 是 → AGENT 更新
  → 否 → 跳过(不值得固化)
产物类型示例:
模式类型原因
“提交前运行代码检查”Hook(PreToolUse)自动校验关卡
“会话结束时提取学习成果”Hook(SessionEnd)自动触发
“逐步调试Hooks”Skill手动执行流程
“始终显式传递ID”Rule启发式规则

Step 5: Apply Signal Thresholds

步骤5:应用信号阈值

OccurrencesAction
1Note but skip (unless critical failure)
2Consider - present to user
3+Strong signal - recommend creation
4+Definitely create
出现次数操作
1次记录但跳过(除非是严重故障)
2次纳入考虑 - 提交给用户确认
3次及以上强信号 - 建议创建
4次及以上务必创建

Step 6: Propose Artifacts

步骤6:提交产物提案

Present each proposal in this format:
markdown
---
按照以下格式提交每个提案:
markdown
---

Pattern: [Generalized Name]

模式:[通用名称]

Signal: [N] sessions ([list session IDs])
Category: [debugging / reliability / workflow / etc.]
Artifact Type: Rule / Skill / Agent Update
Rationale: [Why this artifact type, why worth creating]
Draft Content: ```markdown [Actual content that would be written to file] ```
File:
.claude/rules/[name].md
or
.claude/skills/[name]/SKILL.md


Use `AskUserQuestion` to get approval for each artifact (or batch approval).
信号强度: [N] 次会话([会话ID列表])
分类: [调试 / 可靠性 / 工作流 / 其他]
产物类型: Rule / Skill / Agent 更新
理由: [选择该产物类型的原因,以及值得创建的依据]
草案内容: ```markdown [将写入文件的实际内容] ```
文件路径:
.claude/rules/[name].md
.claude/skills/[name]/SKILL.md


使用`AskUserQuestion`获取用户对每个产物的批准(或批量批准)。

Step 7: Create Approved Artifacts

步骤7:创建已批准的产物

For Rules:

针对Rules:

bash
undefined
bash
undefined

Write to rules directory

写入rules目录

cat > $CLAUDE_PROJECT_DIR/.claude/rules/<name>.md << 'EOF'
cat > $CLAUDE_PROJECT_DIR/.claude/rules/<name>.md << 'EOF'

Rule Name

规则名称

[Context: why this rule exists, based on N sessions]
[背景:基于N次会话,该规则的存在原因]

Pattern

模式

[The reusable principle]
[可复用的原则]

DO

应执行

  • [Concrete action]
  • [具体操作]

DON'T

禁止执行

  • [Anti-pattern]
  • [反模式]

Source Sessions

来源会话

  • [session-id-1]: [what happened]
  • [session-id-2]: [what happened] EOF
undefined
  • EOF
undefined

For Skills:

针对Skills:

Create
.claude/skills/<name>/SKILL.md
with:
  • Frontmatter (name, description, allowed-tools)
  • When to Use
  • Step-by-step instructions (executable)
  • Examples from the learnings
Add triggers to
skill-rules.json
if appropriate.
创建
.claude/skills/<name>/SKILL.md
文件,包含:
  • 前置信息(名称、描述、允许使用的工具)
  • 适用场景
  • 分步操作说明(可执行)
  • 来自学习成果的示例
如需,在
skill-rules.json
中添加触发条件。

For Hooks:

针对Hooks:

Create shell wrapper + TypeScript handler:
bash
undefined
创建Shell包装器 + TypeScript处理器:
bash
undefined

Shell wrapper

Shell包装器

cat > $CLAUDE_PROJECT_DIR/.claude/hooks/<name>.sh << 'EOF' #!/bin/bash set -e cd "$CLAUDE_PROJECT_DIR/.claude/hooks" cat | node dist/<name>.mjs EOF chmod +x $CLAUDE_PROJECT_DIR/.claude/hooks/<name>.sh

Then create `src/<name>.ts`, build with esbuild, and register in `settings.json`:

```json
{
  "hooks": {
    "EventName": [{
      "hooks": [{
        "type": "command",
        "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/<name>.sh"
      }]
    }]
  }
}
cat > $CLAUDE_PROJECT_DIR/.claude/hooks/<name>.sh << 'EOF' #!/bin/bash set -e cd "$CLAUDE_PROJECT_DIR/.claude/hooks" cat | node dist/<name>.mjs EOF chmod +x $CLAUDE_PROJECT_DIR/.claude/hooks/<name>.sh

然后创建`src/<name>.ts`,使用esbuild构建,并在`settings.json`中注册:

```json
{
  "hooks": {
    "EventName": [{
      "hooks": [{
        "type": "command",
        "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/<name>.sh"
      }]
    }]
  }
}

For Agent Updates:

针对Agent更新:

Edit existing agent in
.claude/agents/<name>.md
to add the learned capability.
编辑
.claude/agents/<name>.md
中的现有Agent,添加新习得的能力。

Step 8: Summary Report

步骤8:总结报告

markdown
undefined
markdown
undefined

Compounding Complete

整合完成

Learnings Analyzed: [N] sessions Patterns Found: [M] Artifacts Created: [K]
分析的学习成果: [N] 次会话 发现的模式: [M] 个 创建的产物: [K] 个

Created:

已创建:

  • Rule:
    explicit-identity.md
    - Pass IDs explicitly across boundaries
  • Skill:
    debug-hooks
    - Hook debugging workflow
  • Rule:
    explicit-identity.md
    - 跨边界显式传递ID
  • Skill:
    debug-hooks
    - Hook调试工作流

Skipped (insufficient signal):

已跳过(信号不足):

  • "Pattern X" (1 occurrence)
Your setup is now permanently improved.
undefined
  • “模式X”(出现1次)
你的设置现已得到永久改进。
undefined

Quality Checks

质量检查

Before creating any artifact:
  1. Is it general enough? Would it apply in other projects?
  2. Is it specific enough? Does it give concrete guidance?
  3. Does it already exist? Check
    .claude/rules/
    and
    .claude/skills/
    first
  4. Is it the right type? Sequences → skills, heuristics → rules
创建任何产物前,请检查:
  1. 通用性足够吗? 能否应用于其他项目?
  2. 具体性足够吗? 是否提供了明确的指导?
  3. 是否已存在? 先检查
    .claude/rules/
    .claude/skills/
    目录
  4. 类型是否正确? 步骤序列→Skills,启发式规则→Rules

Files Reference

文件参考

  • Learnings:
    .claude/cache/learnings/*.md
  • Skills:
    .claude/skills/<name>/SKILL.md
  • Rules:
    .claude/rules/<name>.md
  • Hooks:
    .claude/hooks/<name>.sh
    +
    src/<name>.ts
    +
    dist/<name>.mjs
  • Agents:
    .claude/agents/<name>.md
  • Skill triggers:
    .claude/skills/skill-rules.json
  • Hook registration:
    .claude/settings.json
    hooks
    section
  • 学习成果:
    .claude/cache/learnings/*.md
  • Skills:
    .claude/skills/<name>/SKILL.md
  • 规则:
    .claude/rules/<name>.md
  • Hooks:
    .claude/hooks/<name>.sh
    +
    src/<name>.ts
    +
    dist/<name>.mjs
  • Agents:
    .claude/agents/<name>.md
  • Skill触发条件:
    .claude/skills/skill-rules.json
  • Hook注册:
    .claude/settings.json
    hooks
    章节