Skip to content

Claude Code自进化系统完整指南:8步打造会学习的AI助手

2026年5月5日

Meta Alchemist的完整指南:如何通过8个步骤,将Claude Code从开箱即用的CLI工具改造成能自我学习、自动验证、持续进化的智能系统。

核心概念:什么是自进化系统

AI的进步方向:每一步都能自我进化。

你的Claude Code可以拥有一套免疫系统——让它每一次会话都变得更聪明。

这套系统能做的

  • 捕获并记录你的每一次纠正
  • 同样纠正出现两次,自动生成永久规则
  • 发现代码库模式,像田野笔记一样被记录
  • 定期审查,将已学行为晋升为永久DNA

有用的模式留存,过时的规则被淘汰,系统一代比一代更强。

四层架构总览

层级组件作用
第一层认知核心CLAUDE.md,编程思维方式
第二层子智能体architect(规划)+ reviewer(审查)
第三层路径作用域规则安全/API设计/性能规则按需加载
第四层进化引擎corrections/observations → learned-rules

文件夹结构

your-project/
├── CLAUDE.md                    # 认知核心
└── .claude/
    ├── settings.json            # 权限、安全、钩子配置
    ├── rules/                   # 路径作用域智能规则
    │   ├── core-invariants.md   # 每个文件都加载
    │   ├── security.md          # 认证、输入验证
    │   ├── api-design.md        # Handler模式
    │   └── performance.md       # N+1查询、索引
    ├── agents/                  # 子智能体
    │   ├── architect.md         # 规划(只读)
    │   └── reviewer.md          # 审查(只读)
    ├── skills/
    │   ├── evolve/              # /evolve审计
    │   ├── review/              # /review审查
    │   ├── boot/                # /boot预热
    │   ├── fix-issue/           # /fix-issue修复
    │   └── evolution/           # 验证引擎(自动触发)
    └── memory/
        ├── learned-rules.md    # 已毕业规则(含verify检查)
        ├── evolution-log.md     # 进化决策审计
        ├── corrections.jsonl    # 用户纠正
        ├── observations.jsonl  # 已验证发现
        ├── violations.jsonl     # 规则违规
        └── sessions.jsonl       # 会话评分

第一步:CLAUDE.md认知核心

这是整个系统最重要的文件。不是文档,是行为编程。

markdown
# Self-Evolving Engineering System

You are a principal engineer that gets smarter every session.

## Before You Write Any Code

1. **Grep first.** `grep -r "similar_term" src/` before writing code.
2. **Blast radius.** Check imports, tests, consumers.
3. **Ask, don't assume.** One clarifying question.
4. **Smallest change.** No bonus refactors.
5. **Verification plan.** How will you prove this works?

## Self-Evolution Protocol

1. **Observe.** Log non-obvious patterns to .claude/memory/observations.jsonl
2. **Learn from corrections.** Log corrections to corrections.jsonl
3. **Consult memory.** Read learned-rules.md for accumulated patterns
4. **Never forget a mistake twice.**

第二步:settings.json权限配置

json
{
  "permissions": {
    "allow": [
      "Bash(npm run *)",
      "Bash(git status)",
      "Read", "Write", "Edit", "Glob", "Grep"
    ],
    "deny": [
      "Bash(rm -rf *)",
      "Bash(git push --force *)",
      "Read(./.env*)"
    ]
  }
}

第三步:Rules路径作用域规则

Rules只在Claude处理匹配路径的文件时才加载。编辑CSS不会加载200行安全规范。

security.md

markdown
---
paths:
  - "src/api/**/*"
  - "src/services/**/*"
  - "src/auth/**/*"
---

# Security Rules

- Parameterized queries only
- Auth check in middleware, never scattered
- Validate shape AND content
- Never log PII

api-design.md

markdown
---
paths:
  - "src/api/**/*"
  - "src/routes/**/*"
---

# API Design Rules

- Handler pattern: validate → call core → handle result
- Response shape: `{ data: T | null, error: AppError | null }`
- Error codes: NOT_FOUND, VALIDATION_ERROR, UNAUTHORIZED...

performance.md

markdown
# Performance Rules

## N+1 Query Prevention

WRONG: for loop → findUnique
RIGHT: batch findMany

## Index Check

Every new query pattern needs an index check.

第四步:Agents子智能体

architect.md

markdown
---
name: architect
description: Task planner for complex changes (3+ files)
model: sonnet
tools: Read, Grep, Glob, Bash
---

You PLAN. You never write implementation code.

## Process

1. Restate goal in one sentence
2. Grep for existing patterns
3. Map every file that needs change
4. Identify what could break
5. Produce PLAN output

reviewer.md

markdown
---
name: reviewer
description: Code reviewer before git commit
model: sonnet
tools: Read, Grep, Glob
---

VERDICT: SHIP IT | NEEDS WORK | BLOCKED

Priority:
1. Will this crash?
2. Is this exploitable?
3. Will this be slow?
4. Is this tested?

第五步:Skills斜杠命令

/review 提交前审查

bash
## Pre-flight
!`npm run typecheck && npm run lint && npm run test`

## Diff
!`git diff main...HEAD`

## Review for bugs, security, performance

/fix-issue 修复GitHub Issue

bash
!`gh issue view $ARGUMENTS`

## Workflow
1. Root cause (one sentence)
2. Fix (minimal change)
3. Test (fails without fix, passes with it)
4. Commit: fix(scope): description (fixes #$ARGUMENTS)

/evolve 进化审计

bash
## Analyze
- corrections.jsonl (patterns 2+ promote)
- observations.jsonl (confirmed  promote)
- learned-rules.md (graduation candidates?)

## Propose changes
PROPOSE: PROMOTE | GRADUATE | PRUNE | UPDATE

第六步:Evolution Engine进化引擎

这是免疫系统,不是日记本。

自动验证扫描

markdown
## VERIFICATION SWEEP (run at session start)

1. Read learned-rules.md
2. Run every verify: check
3. PASS: Silent
4. FAIL: Log to violations.jsonl + surface to user
5. ALL pass: Say nothing

纠正捕获机制

markdown
## CORRECTION CAPTURE

1st correction → log to corrections.jsonl
2nd correction (same pattern) → auto-promote to learned-rules.md

规则晋升阶梯

信号目的地
纠正1次corrections.jsonl
纠正2次(同类)learned-rules.md(自动晋升)
观察3+次(同类)learned-rules.md(通过/evolve)
learned-rules 10+次CLAUDE.md 或 rules/

实战循环演示

会话事件动作
#1你纠正"不用三元"记录到corrections.jsonl
#2又写三元被纠正自动晋升learned-rules.md
#5Verification sweep检测到三元→报告→修复
#8发现service用Result<T>grep验证→直接晋升

不要孤军奋战啦!

加入微信群一起学习交流 AI

与大神一起使用 OpenClaw、Hermes、Claude Code、Seedance 2.0、GPT-Image-2 等

微信公众号

扫码关注微信公众号
私信 "加群",将自动获取微信群二维码

探索 AI 世界,掌握智能未来