Apply Learnings Skill
Analyze Claude Code session history to extract learnings that would have been helpful if provided earlier, then persist them for future sessions.
Overview
This skill performs comprehensive analysis of session transcripts to identify:
- 1. Code Pattern Learnings - Framework conventions, idioms, and best practices discovered during the session
- Architectural Preferences - Where validation/logic should live, layer responsibilities
- Tool Usage Patterns - Failed tool calls, user corrections, successful retries
- Missing Context - Information the user had to provide that could be documented upfront
Usage
Analyze Current Session
CODEBLOCK0
Analyze All Historical Sessions
CODEBLOCK1
Analyze Specific Project
CODEBLOCK2
Workflow
When the user invokes this skill:
Step 1: Ask User for Scope
Ask which scope to analyze:
- - Current session - Only the current conversation
- Current project - All sessions for the current working directory
- All sessions - Complete history across all projects
Step 2: Run Analysis
Execute the analysis script:
CODEBLOCK3
Step 3: Present Findings
Present findings organized by category:
Code Pattern Learnings
Conventions and idioms specific to the codebase/framework:
- - Dependency injection patterns (e.g., "use glue logger from context, not DI")
- Error handling conventions
- Naming patterns
- Testing patterns
Architectural Preferences
Where different concerns should be handled:
- - Validation location (e.g., "validate at handler/mapper, not in controllers")
- Error transformation boundaries
- Layer responsibilities
Tool Usage Improvements
From the original tool-self-improver:
- - Failed tool calls and corrections
- Common error patterns
- Successful retry patterns
Missing Context
Information that would have helped earlier:
- - Project-specific conventions not in CLAUDE.md
- Framework quirks
- Team preferences
Step 4: Classify Destination for Each Learning
For each learning, determine the best destination. Do NOT put everything in CLAUDE.md — route to the most specific location:
| Destination | When to Use | Example |
|---|
| ~/.claude/MEMORY.md | Cross-machine context: SRE tools, key people, tool conventions — anything useful on both Mac AND devpods | SRE MCP session protocol, .env default paths, key people/Slack IDs |
| ~/.claude/CLAUDE.md |
Cross-project behavioral rules, hard constraints, coding preferences | "Always use double quotes for SSH commands" |
|
Existing skill reference | Learning directly relates to a specific skill's domain | Glue logger pattern →
/verification references; rebase tips →
/arh-pr-workflow |
|
Project CLAUDE.md | Learning is specific to one project/repo | "This repo uses custom test helpers in
pkg/testutil" |
|
New skill | Learning represents a reusable workflow or substantial domain knowledge not covered by existing skills | A complete debugging workflow for a specific system |
Classification rules:
- 1. Cross-machine tool/people context →
~/.claude/MEMORY.md (synced via TerraBlob to all machines) - Check
~/.claude/skills/ — if a learning fits an existing skill, add it as a reference file or append to existing references - If it's project-specific, target the project's
CLAUDE.md (at repo root or ~/.claude/projects/) - If it's a substantial, reusable workflow (3+ related learnings on one topic), propose a new skill
- Only put truly global behavioral rules in INLINECODE8
- When in doubt, prefer the more specific destination
Step 5: Present Routed Proposals
Present findings grouped by destination using AskUserQuestion:
CODEBLOCK4
Then ask user per destination group:
- - Apply as proposed — write to the suggested destination
- Redirect — user specifies a different destination
- Edit first — user wants to modify the content before applying
- Skip — don't apply this group
Step 6: Apply Approved Changes
For each approved group:
- - CLAUDE.md additions: Append under appropriate existing section, or create new section if none fits. Deduplicate against existing content.
- Existing skill references: Create or append to a
references/learnings.md file in that skill's directory. Use ## Auto-learned (YYYY-MM-DD) header. - Project CLAUDE.md: Append under appropriate section in the project's CLAUDE.md.
- New skill: Create
~/.claude/skills/<name>/SKILL.md with proper structure (description, when to use, the learned workflow/knowledge).
What Gets Detected
Code Pattern Signals
- - User corrections mentioning "use X instead of Y"
- Explanations of framework conventions
- References to existing patterns in codebase
- "We prefer..." or "The convention is..." statements
Architectural Signals
- - Discussion of layer responsibilities
- "This should be in X, not Y" corrections
- Validation/error handling location guidance
- Separation of concerns discussions
Tool Failure Signals
- - Tool calls with INLINECODE12
- User rejections of tool calls
- Interrupted requests
- Successful retries after user guidance
Missing Context Signals
- - User providing information that wasn't asked for
- Corrections about project-specific conventions
- "Actually, in this codebase we..." statements
- References to undocumented team practices
Example Learnings
Glue Framework Patterns
CODEBLOCK5
Validation Architecture
CODEBLOCK6
Go Monorepo Patterns
CODEBLOCK7
Notes
- - Analysis is read-only; no sessions are modified
- All changes require explicit user approval per destination group
- Learnings are routed to the most specific destination, NOT all dumped into CLAUDE.md
- Destinations: global CLAUDE.md, existing skill references, project CLAUDE.md, or new skills
- Focus on actionable, specific guidance — avoid overly generic advice
- Deduplicate against existing content before writing
应用学习技能
分析Claude Code会话历史,提取如果提前提供会有所帮助的经验教训,并将其持久化以供未来会话使用。
概述
本技能对会话记录进行全面分析,以识别:
- 1. 代码模式经验 - 会话中发现的框架约定、惯用模式和最佳实践
- 架构偏好 - 验证/逻辑应放置的位置、各层职责
- 工具使用模式 - 失败的工具调用、用户纠正、成功重试
- 缺失上下文 - 用户必须提供但可以预先记录的信息
使用方法
分析当前会话
bash
python3 ~/.claude/skills/apply-learnings/scripts/analyze_session.py --scope current
分析所有历史会话
bash
python3 ~/.claude/skills/apply-learnings/scripts/analyze_session.py --scope all
分析特定项目
bash
python3 ~/.claude/skills/apply-learnings/scripts/analyze_session.py --project /path/to/project
工作流程
当用户调用此技能时:
步骤1:询问用户分析范围
询问要分析的范围:
- - 当前会话 - 仅当前对话
- 当前项目 - 当前工作目录的所有会话
- 所有会话 - 所有项目的完整历史
步骤2:运行分析
执行分析脚本:
bash
python3 ~/.claude/skills/apply-learnings/scripts/analyze_session.py --scope
步骤3:展示发现
按类别展示发现:
代码模式经验
特定于代码库/框架的约定和惯用模式:
- - 依赖注入模式(例如使用上下文中的glue日志器,而非依赖注入)
- 错误处理约定
- 命名模式
- 测试模式
架构偏好
不同关注点应如何处理:
- - 验证位置(例如在处理器/映射器中验证,而非控制器)
- 错误转换边界
- 各层职责
工具使用改进
来自原始工具自我改进器:
缺失上下文
本应提前提供的信息:
- - 未在CLAUDE.md中的项目特定约定
- 框架特性
- 团队偏好
步骤4:为每条经验分类目标位置
为每条经验确定最佳目标位置。不要将所有内容放入CLAUDE.md——路由到最具体的位置:
| 目标位置 | 使用时机 | 示例 |
|---|
| ~/.claude/MEMORY.md | 跨机器上下文:SRE工具、关键人员、工具约定——在Mac和开发容器上都有用的任何内容 | SRE MCP会话协议、.env默认路径、关键人员/Slack ID |
| ~/.claude/CLAUDE.md |
跨项目行为规则、硬约束、编码偏好 | SSH命令始终使用双引号 |
|
现有技能引用 | 经验直接与特定技能领域相关 | Glue日志器模式→/verification引用;变基技巧→/arh-pr-workflow |
|
项目CLAUDE.md | 经验特定于一个项目/仓库 | 此仓库在pkg/testutil中使用自定义测试辅助工具 |
|
新技能 | 经验代表可重用工作流或现有技能未涵盖的重要领域知识 | 针对特定系统的完整调试工作流 |
分类规则:
- 1. 跨机器工具/人员上下文 → ~/.claude/MEMORY.md(通过TerraBlob同步到所有机器)
- 检查~/.claude/skills/——如果经验适合现有技能,添加为引用文件或追加到现有引用
- 如果是项目特定的,定位到项目的CLAUDE.md(在仓库根目录或~/.claude/projects/)
- 如果是重要的可重用工作流(同一主题3条以上相关经验),建议创建新技能
- 仅将真正的全局行为规则放入~/.claude/CLAUDE.md
- 如有疑问,优先选择更具体的目标位置
步骤5:展示路由建议
使用AskUserQuestion按目标位置分组展示发现:
我已识别出以下经验及其应放置的位置:
→ ~/.claude/CLAUDE.md(全局)
→ ~/.claude/skills/verification/references/(现有技能)
→ ~/.claude/skills/arh-pr-workflow/references/(现有技能)
→ ./CLAUDE.md(仅此项目)
→ 新技能:debug-m3(建议)
然后按目标位置组询问用户:
- - 按建议应用 — 写入建议的目标位置
- 重定向 — 用户指定不同的目标位置
- 先编辑 — 用户希望在应用前修改内容
- 跳过 — 不应用此组
步骤6:应用批准的更改
对于每个批准的组:
- - CLAUDE.md添加:追加到适当的现有部分下,如果没有合适的部分则创建新部分。与现有内容去重。
- 现有技能引用:在该技能目录中创建或追加到references/learnings.md文件。使用## 自动学习(YYYY-MM-DD)标题。
- 项目CLAUDE.md:追加到项目CLAUDE.md的适当部分下。
- 新技能:创建~/.claude/skills/<名称>/SKILL.md,包含适当结构(描述、使用时机、学习到的工作流/知识)。
检测内容
代码模式信号
- - 用户纠正提及使用X而非Y
- 框架约定的解释
- 对代码库中现有模式的引用
- 我们偏好...或约定是...的陈述
架构信号
- - 关于各层职责的讨论
- 这应该在X中,而非Y的纠正
- 验证/错误处理位置指导
- 关注点分离的讨论
工具失败信号
- - 带有is_error: true的工具调用
- 用户拒绝工具调用
- 中断的请求
- 用户指导后的成功重试
缺失上下文信号
- - 用户提供未被询问的信息
- 关于项目特定约定的纠正
- 实际上,在此代码库中我们...的陈述
- 对未记录团队实践的引用
示例经验
Glue框架模式
markdown
日志器使用:
- - 使用来自glue上下文的ctx.Logger(),而非通过依赖注入注入日志器
- 上下文日志器自动包含请求追踪
映射器约定:
- - 映射器应仅进行类型转换,不包含业务逻辑
- 对无效转换返回错误,而非验证错误
验证架构
markdown
边缘验证:
- - 在处理层(映射器或验证包)验证请求负载
- 控制器接收预验证的实体
- 网关响应应在网关层验证/转换
Go单体仓库模式
markdown
BUILD.bazel:
- - 添加新导入后运行gazelle <目录>
- 切勿从根目录运行bazel build //...
测试:
- - 使用表驱动测试
- 使用mockgen或bin/glue mock生成模拟
注意事项
- - 分析是只读的;不会修改任何会话
- 所有更改需要按目标位置组获得用户明确批准
- 经验路由到最具体的目标位置,而非全部倾倒到CLAUDE.md
- 目标位置:全局CLAUDE.md、现有技能引用、项目CLAUDE.md或新技能
- 关注可操作、具体的指导——避免过于泛泛的建议
- 写入前与现有内容去重