Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Self-Improving Plugin

基于Hermes Agent的self-improving机制,为Claude Code打造的自动学习和改进系统。

核心功能

功能 说明
Session Scoring 每次session结束自动评分(错误率、重试率、人工修正)
Pattern Detection 检测重复模式,3次以上自动promote为规则
Skill Auto-Creation 复杂任务后自动创建可复用skill
Memory Promotion MEMORY.md → CLAUDE.md rules 自动提升
Effectiveness Tracking 追踪每个改进的效果,无效自动回滚
Dashboard /improve 命令查看改进状态

安装

# 复制到你的项目
cp -r claude-self-improve/ /path/to/your/project/.claude/

# 或者全局安装
cp -r claude-self-improve/ ~/.claude/

# 运行测试
python test.py

使用

自动模式(推荐)

安装后自动运行,每次session结束会:

  1. 分析transcript(JSONL)
  2. 评分0-100
  3. 提取patterns
  4. 检查是否值得创建skill
  5. 追踪规则效果

手动命令

/improve          # 查看改进仪表盘
/improve review   # 审查待promote的patterns
/improve scores   # 查看历史评分
/improve skills   # 查看已创建的skills
/improve effects  # 查看规则效果追踪
/improve revert [rule_key]  # 回滚指定规则

架构

Session结束
    ↓
Hook触发 → 解析JSONL transcript
    ↓
┌─────────────────────────────────────────────────────────────┐
│ Step 1: 评分引擎                                             │
│   - 错误率 (30%)                                             │
│   - 重试率 (20%)                                             │
│   - 修正率 (30%)                                             │
│   - 工具误用 (20%)                                           │
└─────────────────────────────────────────────────────────────┘
    ↓
┌─────────────────────────────────────────────────────────────┐
│ Step 2: 模式检测                                             │
│   - 高错误率 (>20%)                                          │
│   - 频繁修正 (>=2次)                                         │
│   - 重试过多 (>=3次)                                         │
│   - 低分session (<60)                                        │
└─────────────────────────────────────────────────────────────┘
    ↓
┌─────────────────────────────────────────────────────────────┐
│ Step 3: 规则提升                                             │
│   - 3次以上重复 → 生成CLAUDE.md rule提案                      │
│   - 用户审查 → /improve review                               │
│   - 批准 → 写入.claude/rules/                                │
└─────────────────────────────────────────────────────────────┘
    ↓
┌─────────────────────────────────────────────────────────────┐
│ Step 4: Skill创建                                            │
│   - 检测复杂任务 (>=5次工具调用 或 >=3种工具)                  │
│   - 自动生成skill文件                                        │
│   - 保存到 learnings/skills/                                 │
└─────────────────────────────────────────────────────────────┘
    ↓
┌─────────────────────────────────────────────────────────────┐
│ Step 5: 效果追踪                                             │
│   - 追踪每条规则的使用情况                                    │
│   - 计算效果分数 (0-100)                                     │
│   - 无效规则自动标记/回滚                                     │
└─────────────────────────────────────────────────────────────┘

文件结构

.claude/
├── self-improve/
│   ├── hooks/
│   │   └── session-end.sh      # Session结束hook
│   ├── commands/
│   │   └── improve.md          # /improve命令文档
│   ├── scripts/
│   │   ├── score.py            # 评分引擎
│   │   ├── detect.py           # 模式检测
│   │   ├── promote.py          # 规则提升
│   │   ├── skills.py           # Skill自动创建
│   │   ├── effectiveness.py    # 效果追踪
│   │   └── dashboard.py        # 仪表盘执行脚本
│   ├── learnings/              # 学习记录
│   │   ├── patterns.json       # 检测到的模式
│   │   ├── scores.json         # 历史评分
│   │   ├── effectiveness.json  # 效果追踪数据
│   │   └── skills/             # 自动创建的skills
│   └── config.json             # 配置
└── rules/
    └── auto-generated.md       # 自动生成的规则

配置

.claude/self-improve/config.json:

{
  "auto_promote": false,
  "min_occurrences": 3,
  "rules_file": "auto-generated.md",
  "revert_after_sessions": 10,
  "min_effectiveness_score": 30,
  "auto_revert": false,
  "score_weights": {
    "error_rate": 0.3,
    "retry_rate": 0.2,
    "correction_rate": 0.3,
    "tool_misuse": 0.2
  },
  "skill_threshold": 5,
  "patterns": {
    "high_error_rate": {
      "enabled": true,
      "threshold": 0.2,
      "description": "工具调用错误率超过20%"
    },
    "frequent_corrections": {
      "enabled": true,
      "threshold": 2,
      "description": "用户修正次数>=2"
    },
    "excessive_retries": {
      "enabled": true,
      "threshold": 3,
      "description": "重试次数>=3"
    },
    "low_score_session": {
      "enabled": true,
      "threshold": 60,
      "description": "Session评分低于60"
    }
  },
  "dashboard": {
    "show_recent_scores": 10,
    "show_patterns": true,
    "show_skills": true,
    "show_effectiveness": true
  }
}

配置说明

参数 说明 默认值
auto_promote 自动promote规则(不推荐) false
min_occurrences promote所需的最小出现次数 3
revert_after_sessions 追踪多少个session后判断规则是否有效 10
min_effectiveness_score 最低效果分数(低于此值标记为无效) 30
auto_revert 自动回滚无效规则 false
skill_threshold 创建skill所需的最小工具调用次数 5

仪表盘示例

📊 Self-Improving Dashboard
━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Recent Scores:
  2026-01-15:  78.0/100 ████████░░
  2026-01-14:  82.0/100 █████████░
  2026-01-13:  65.0/100 ██████░░░░
  2026-01-12:  91.0/100 █████████░
  2026-01-11:  73.0/100 ███████░░░

Rolling Average: 75.0/100

Patterns Detected: 12
  ├─ Promoted: 5
  ├─ Pending: 6
  └─ Rejected: 1

Skills Created: 3
  ├─ git-workflow
  ├─ api-testing
  └─ error-handling

Rules Tracked: 5
  ├─ Effective: 2
  ├─ Ineffective: 1
  └─ Tracking: 2

Run /improve review to see pending patterns.

与Hermes的对比

功能 Hermes Claude版
Skill创建 ✅ 自动 ✅ 自动
Memory三层 ✅ 内置 ✅ CLAUDE.md + MEMORY.md + learnings/
Curator ✅ 后台进程 ⚠️ 手动/improve review
Session Search ✅ FTS5 ⚠️ 基础grep
效果追踪 ✅ 内置 ✅ effectiveness.json
自动回滚 ✅ 内置 ✅ auto_revert配置

开发

# 运行测试
python test.py

# 手动运行各模块
python scripts/score.py <transcript> <scores_file>
python scripts/detect.py <scores_file> <patterns_file>
python scripts/promote.py <patterns_file> <config_file>
python scripts/skills.py <transcript> <skills_dir> <config_file>
python scripts/effectiveness.py <rules_dir> <effectiveness_file> <scores_file> [config_file]
python scripts/dashboard.py <command> [self_improve_dir]

License

MIT

About

Self-improving plugin for Claude Code - auto scoring, pattern detection, and rule promotion based on Hermes Agent

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages