展示 HN:Claude Reflect – 将 Claude 的更正自动转化为项目配置
Show HN: Claude Reflect – Auto-turn Claude corrections into project config

原始链接: https://github.com/BayramAnnakov/claude-reflect

## Claude Reflect:Claude 代码的自学习系统 Claude Reflect 是一个为 Claude 代码设计的插件,旨在帮助它从您的更正和偏好中学习。它会在您的编码过程中自动捕获反馈——包括否定更正(“不,使用 X”)和积极强化(“完美!”)。 这些捕获的信息会被排队,然后通过 `/reflect` 命令呈现给您进行审核。您可以批准这些“学习成果”,将其永久添加到全局 `CLAUDE.md` 文件(影响所有项目)或项目特定的 `CLAUDE.md`,甚至兼容代理的 `AGENTS.md`。 该插件包含自动运行的钩子,用于检测更正并提醒您在提交后运行 `/reflect`。功能包括扫描过去会话以查找遗漏的学习内容(`/reflect --scan-history`)、预览更改(`/reflect --dry-run`)和去重条目(`/reflect --dedupe`)。每个学习成果都会被分配一个置信度评分,帮助您优先审核。 本质上,Claude Reflect 将您的交互转化为一个不断改进的知识库,用于您的 Claude 代码环境。

## Claude Reflect:讨论总结 Bayramannakov 的 “Claude Reflect”(一个 GitHub 项目)旨在自动捕获在编码会话中对 Claude 的更正和反馈,并将其转化为项目配置,具体为一个 `CLAUDE.md` 文件。其核心思想是主动记录隐式更正,提高一致性并减少“上下文腐烂”——即 LLM 性能随着大型提示而下降的问题。 讨论的重点是有效管理 `CLAUDE.md` 的策略。主要收获包括:用优先信息构建文件(快速参考与详细文档)、保持简洁,以及将更正视为潜在的 linting 规则或测试。 许多用户强调了*不要*让文件变成一个庞大的待办事项列表的重要性。一些人更喜欢链接到单独的 markdown 文件以获取详细信息,而另一些人则提倡让 Claude 本身建议更新,并由人工进行监督。一个常见的担忧是 Claude 倾向于忽略参考资料,需要手动将文件包含在提示中。 项目创建者承认需要人工审查,并发布了 v2 版本来解决报告的问题并提高兼容性。最终,该工具旨在补充现有的工作流程,而不是取代它们,通过捕获通用模型训练可能遗漏的项目特定细微差别来实现。
相关文章

原文

A self-learning system for Claude Code that captures corrections, positive feedback, and preferences — then syncs them to CLAUDE.md and AGENTS.md.

When you correct Claude Code during a session ("no, use gpt-5.1 not gpt-5", "use database for caching"), these corrections are captured and can be added to your CLAUDE.md files so Claude remembers them in future sessions.

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  You correct    │ ──► │  Hook captures  │ ──► │  /reflect adds  │
│  Claude Code    │     │  to queue       │     │  to CLAUDE.md   │
└─────────────────┘     └─────────────────┘     └─────────────────┘
      (automatic)            (automatic)            (manual review)
# Add the marketplace
claude plugin marketplace add bayramannakov/claude-reflect

# Install the plugin
claude plugin install claude-reflect@claude-reflect-marketplace

# IMPORTANT: Restart Claude Code to activate the plugin

After installation, restart Claude Code (exit and reopen). Then hooks auto-configure and commands are ready.

First run? When you run /reflect for the first time, you'll be prompted to scan your past sessions for learnings.

  • Claude Code CLI installed
  • jq for JSON processing (brew install jq on macOS)
  • python3 (included on most systems)
Command Description
/reflect Process queued learnings with human review
/reflect --scan-history Scan ALL past sessions for missed learnings
/reflect --dry-run Preview changes without applying
/reflect --targets Show detected config files (CLAUDE.md, AGENTS.md)
/reflect --review Show queue with confidence scores and decay status
/reflect --dedupe Find and consolidate similar entries in CLAUDE.md
/skip-reflect Discard all queued learnings
/view-queue View pending learnings without processing

Stage 1: Capture (Automatic)

Hooks run automatically to detect and queue corrections:

Hook Trigger Purpose
capture-learning.sh Every prompt Detects correction patterns and queues them
check-learnings.sh Before compaction Blocks compaction if queue has items
post-commit-reminder.sh After git commit Reminds to run /reflect after completing work

Stage 2: Process (Manual)

Run /reflect to review and apply queued learnings to CLAUDE.md.

The capture hook detects corrections AND positive feedback:

Corrections (what went wrong):

  • "no, use X" / "don't use Y"
  • "actually..." / "I meant..."
  • "use X not Y" / "that's wrong"

Positive patterns (what works):

  • "Perfect!" / "Exactly right"
  • "That's what I wanted" / "Great approach"
  • "Keep doing this" / "Nailed it"

Explicit markers:

  • "remember:" — highest confidence

Each captured learning has a confidence score (0.60-0.95) based on pattern strength. Higher confidence = more likely to be a real learning.

When you run /reflect, Claude presents a summary table:

════════════════════════════════════════════════════════════
LEARNINGS SUMMARY — 5 items found
════════════════════════════════════════════════════════════

┌────┬─────────────────────────────────────────┬──────────┬────────┐
│ #  │ Learning                                │ Scope    │ Status │
├────┼─────────────────────────────────────────┼──────────┼────────┤
│ 1  │ Use gpt-5.1 for reasoning tasks         │ global   │ ✓ new  │
│ 2  │ Database for persistent storage         │ project  │ ✓ new  │
└────┴─────────────────────────────────────────┴──────────┴────────┘

You choose:

  • Apply all - Accept recommended changes
  • Select which - Pick specific learnings
  • Review details - See full context before deciding

Approved learnings are synced to:

  • ~/.claude/CLAUDE.md (global - applies to all projects)
  • ./CLAUDE.md (project-specific)
  • AGENTS.md (if exists - works with Codex, Cursor, Aider, Jules, Zed, Factory)

Run /reflect --targets to see which files will be updated.

claude plugin uninstall claude-reflect@claude-reflect-marketplace
claude-reflect/
├── .claude-plugin/
│   └── plugin.json         # Plugin manifest (auto-registers hooks)
├── commands/
│   ├── reflect.md          # Main command
│   ├── skip-reflect.md     # Discard queue
│   └── view-queue.md       # View queue
├── hooks/
│   └── hooks.json          # Auto-configured when plugin installed
├── scripts/
│   ├── capture-learning.sh       # Hook: detect corrections
│   ├── check-learnings.sh        # Hook: pre-compact check
│   ├── post-commit-reminder.sh   # Hook: post-commit reminder
│   ├── extract-session-learnings.sh
│   └── extract-tool-rejections.sh
└── SKILL.md                # Skill context for Claude

First time using claude-reflect? Run:

This scans all your past sessions for corrections you made, so you don't lose learnings from before installation.

Claude filters out:

  • Questions (not corrections)
  • One-time task instructions
  • Context-specific requests
  • Vague/non-actionable feedback

Only reusable learnings are kept.

Before adding a learning, existing CLAUDE.md content is checked. If similar content exists, you can:

  • Merge with existing entry
  • Replace the old entry
  • Skip the duplicate

Over time, CLAUDE.md can accumulate similar entries. Run /reflect --dedupe to:

  • Find semantically similar entries (even with different wording)
  • Propose consolidated versions
  • Clean up redundant learnings

Example:

Before:
  - Use gpt-5.1 for complex tasks
  - Prefer gpt-5.1 for reasoning
  - gpt-5.1 is better for hard problems

After:
  - Use gpt-5.1 for complex reasoning tasks
  1. Use explicit markers for important learnings:

    remember: always use venv for Python projects
    
  2. Run /reflect after git commits - The hook reminds you, but make it a habit

  3. Historical scan on new machines - When setting up a new dev environment:

    /reflect --scan-history --days 90
    
  4. Project vs Global - Model names and general patterns go global; project-specific conventions stay in project CLAUDE.md

Pull requests welcome! Please read the contributing guidelines first.

MIT

联系我们 contact @ memedata.com