Reflect - Agent Self-Improvement Skill
Transform your AI assistant into a continuously improving partner. Every correction becomes a permanent improvement that persists across all future sessions.
Quick Reference
| Command | Action |
|---|
| INLINECODE0 | Analyze conversation for learnings |
| INLINECODE1 |
Enable auto-reflection |
|
reflect off | Disable auto-reflection |
|
reflect status | Show state and metrics |
|
reflect review | Review pending learnings |
When to Use
- - After completing complex tasks
- When user explicitly corrects behavior ("never do X", "always Y")
- At session boundaries or before context compaction
- When successful patterns are worth preserving
Workflow
Step 1: Scan Conversation for Signals
Analyze the conversation for correction signals and learning opportunities.
Signal Confidence Levels:
| Confidence | Triggers | Examples |
|---|
| HIGH | Explicit corrections | "never", "always", "wrong", "stop", "the rule is" |
| MEDIUM |
Approved approaches | "perfect", "exactly", "that's right", accepted output |
|
LOW | Observations | Patterns that worked but not explicitly validated |
See signal_patterns.md for full detection rules.
Step 2: Classify & Match to Target Files
Map each signal to the appropriate target:
| Category | Target Files |
|---|
| Code Style | INLINECODE5 , backend-developer, INLINECODE7 |
| Architecture |
solution-architect,
api-architect,
architecture-reviewer |
| Process |
CLAUDE.md, orchestrator agents |
| Domain | Domain-specific agents,
CLAUDE.md |
| Tools |
CLAUDE.md, relevant specialists |
| New Skill | Create new skill file |
See agent_mappings.md for mapping rules.
Step 3: Check for Skill-Worthy Signals
Some learnings should become new skills rather than agent updates:
Skill-Worthy Criteria:
- - Non-obvious debugging (>10 min investigation)
- Misleading error (root cause different from message)
- Workaround discovered through experimentation
- Configuration insight (differs from documented)
- Reusable pattern (helps in similar situations)
Quality Gates (must pass all):
- - [ ] Reusable: Will help with future tasks
- [ ] Non-trivial: Requires discovery, not just docs
- [ ] Specific: Can describe exact trigger conditions
- [ ] Verified: Solution actually worked
- [ ] No duplication: Doesn't exist already
Step 4: Generate Proposals
Present findings in structured format:
CODEBLOCK0 diff
+ New rule from learning
CODEBLOCK1
Step 5: Apply with User Approval
On Y (approve):
- 1. Apply each change using Edit tool
- Commit with descriptive message
- Update metrics
On N (reject):
- 1. Discard proposed changes
- Log rejection for analysis
On modify:
- 1. Present each change individually
- Allow editing before applying
On selective (e.g., 1,3):
- 1. Apply only specified changes
- Commit partial updates
State Management
State is stored in ~/.reflect/ (configurable via REFLECT_STATE_DIR):
CODEBLOCK2
Metrics Tracking
CODEBLOCK3
Safety Guardrails
Human-in-the-Loop
- - NEVER apply changes without explicit user approval
- Always show full diff before applying
- Allow selective application
Incremental Updates
- - ONLY add to existing sections
- NEVER delete or rewrite existing rules
- Preserve original structure
Conflict Detection
- - Check if proposed rule contradicts existing
- Warn user if conflict detected
- Suggest resolution strategy
Output Locations
Project-level (versioned with repo):
- -
.claude/reflections/YYYY-MM-DD_HH-MM-SS.md - Full reflection - INLINECODE21 - New skills
Global (user-level):
- -
~/.reflect/learnings.yaml - Learning log - INLINECODE23 - Aggregate metrics
Examples
Example 1: Code Style Correction
User says: "Never use var in TypeScript, always use const or let"
Signal detected:
- - Confidence: HIGH (explicit "never" + "always")
- Category: Code Style
- Target: INLINECODE27
Proposed change:
CODEBLOCK4
Example 2: Process Preference
User says: "Always run tests before committing"
Signal detected:
- - Confidence: HIGH (explicit "always")
- Category: Process
- Target: INLINECODE28
Proposed change:
CODEBLOCK5
Example 3: New Skill from Debugging
Context: Spent 30 minutes debugging a React hydration mismatch
Signal detected:
- - Confidence: HIGH (non-trivial debugging)
- Category: New Skill
- Quality gates: All passed
Proposed skill: INLINECODE29
Troubleshooting
No signals detected:
- - Session may not have had corrections
- Check if using natural language corrections
Conflict warning:
- - Review the existing rule cited
- Decide if new rule should override
- Can modify before applying
Agent file not found:
- - Check agent name spelling
- May need to create agent file first
Reflect - 智能体自我改进技能
将您的AI助手转变为持续改进的伙伴。每一次修正都将成为永久性的改进,并延续到所有未来的会话中。
快速参考
| 命令 | 操作 |
|---|
| reflect | 分析对话以获取学习内容 |
| reflect on |
启用自动反思 |
| reflect off | 禁用自动反思 |
| reflect status | 显示状态和指标 |
| reflect review | 审查待处理的学习内容 |
何时使用
- - 完成复杂任务后
- 用户明确纠正行为时(永远不要做X、总是Y)
- 会话边界或上下文压缩前
- 成功的模式值得保留时
工作流程
第一步:扫描对话中的信号
分析对话中的修正信号和学习机会。
信号置信度级别:
| 置信度 | 触发条件 | 示例 |
|---|
| 高 | 明确修正 | 永远不要、总是、错误、停止、规则是 |
| 中 |
认可的方法 | 完美、正是、没错、被接受的输出 |
|
低 | 观察结果 | 有效但未明确验证的模式 |
完整检测规则请参见 signal_patterns.md。
第二步:分类并匹配目标文件
将每个信号映射到相应的目标:
| 类别 | 目标文件 |
|---|
| 代码风格 | code-reviewer、backend-developer、frontend-developer |
| 架构 |
solution-architect、api-architect、architecture-reviewer |
| 流程 | CLAUDE.md、编排智能体 |
| 领域 | 领域特定智能体、CLAUDE.md |
| 工具 | CLAUDE.md、相关专家 |
| 新技能 | 创建新的技能文件 |
映射规则请参见 agent_mappings.md。
第三步:检查值得创建技能的信号
某些学习内容应成为新技能而非智能体更新:
值得创建技能的标准:
- - 非显而易见的调试(超过10分钟的排查)
- 误导性错误(根本原因与错误信息不同)
- 通过实验发现的变通方案
- 配置洞察(与文档不同)
- 可复用的模式(在类似情况下有帮助)
质量关卡(必须全部通过):
- - [ ] 可复用:对未来任务有帮助
- [ ] 非平凡:需要发现过程,而非仅靠文档
- [ ] 具体:能描述确切的触发条件
- [ ] 已验证:解决方案确实有效
- [ ] 无重复:尚未存在
第四步:生成提案
以结构化格式呈现发现:
markdown
反思分析
会话上下文
检测到的信号
| # | 信号 | 置信度 | 来源引用 | 类别 |
|---|
| 1 | [学习内容] | 高 | [确切措辞] | 代码风格 |
建议的变更
变更1:更新 [智能体名称]
目标:[文件路径]
章节:[章节名称]
置信度:高
diff
+ 来自学习内容的新规则
审查提示
应用这些变更?(Y/N/修改/1,2,3)
第五步:经用户批准后应用
输入 Y(批准):
- 1. 使用编辑工具应用每个变更
- 提交并附带描述性信息
- 更新指标
输入 N(拒绝):
- 1. 丢弃建议的变更
- 记录拒绝原因供分析
输入 modify(修改):
- 1. 逐一呈现每个变更
- 允许在应用前编辑
选择性输入(例如 1,3):
- 1. 仅应用指定的变更
- 提交部分更新
状态管理
状态存储在 ~/.reflect/ 中(可通过 REFLECTSTATEDIR 配置):
yaml
reflect-state.yaml
auto_reflect: false
last_reflection: 2026-01-26T10:30:00Z
pending_reviews: []
指标追踪
yaml
reflect-metrics.yaml
total
sessionsanalyzed: 42
total
signalsdetected: 156
total
changesaccepted: 89
acceptance_rate: 78%
confidence_breakdown:
high: 45
medium: 32
low: 12
most
updatedagents:
code-reviewer: 23
backend-developer: 18
skills_created: 5
安全护栏
人在回路中
- - 未经用户明确批准,绝不应用变更
- 始终在应用前显示完整差异
- 允许选择性应用
增量更新
- - 仅添加到现有章节
- 绝不删除或重写现有规则
- 保留原始结构
冲突检测
- - 检查建议的规则是否与现有规则冲突
- 如检测到冲突,警告用户
- 建议解决策略
输出位置
项目级别(随仓库版本控制):
- - .claude/reflections/YYYY-MM-DD_HH-MM-SS.md - 完整反思
- .claude/skills/{name}/SKILL.md - 新技能
全局级别(用户级别):
- - ~/.reflect/learnings.yaml - 学习日志
- ~/.reflect/reflect-metrics.yaml - 汇总指标
示例
示例1:代码风格修正
用户说:在TypeScript中永远不要使用 var,始终使用 const 或 let
检测到的信号:
- - 置信度:高(明确的永远不要+始终)
- 类别:代码风格
- 目标:frontend-developer.md
建议的变更:
diff
风格指南
+ * 在TypeScript中使用 const 或 let 替代 var
示例2:流程偏好
用户说:始终在提交前运行测试
检测到的信号:
- - 置信度:高(明确的始终)
- 类别:流程
- 目标:CLAUDE.md
建议的变更:
diff
提交规范
+ * 在创建提交前运行测试套件
示例3:调试中的新技能
上下文:花费30分钟调试React水合不匹配问题
检测到的信号:
- - 置信度:高(非平凡的调试)
- 类别:新技能
- 质量关卡:全部通过
建议的技能:react-hydration-fix/SKILL.md
故障排除
未检测到信号:
- - 会话可能没有修正内容
- 检查是否使用了自然语言修正
冲突警告:
- - 审查引用的现有规则
- 决定新规则是否应覆盖
- 可在应用前修改
智能体文件未找到: