Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All notable changes to this documentation set are recorded here. The format foll

## [Unreleased]

### Changed

- Re-verified all 13 chapters against Claude Code 2.1.227 and upstream commit `54cc51a`; updated current auto memory, compaction, permission modes, MCP configuration, shipped 1M context, and voice interaction, while labeling March source snapshot counts as historical.

## [1.1.0] — 2026-08-11

### Fixed
Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Sourcemap 是前端构建工具生成的调试辅助文件,记录了编译后

我用 Claude Code 对这份源码做了系统化的技术分析,逐模块拆解,写了 13 篇技术文档,中英双语。

从架构设计到 Agent 循环的六阶段实现,从三层消息压缩体系到权限校验系统,从五层记忆加载到工具的执行流水线
从架构设计到 Agent 循环的六阶段实现,从三层消息压缩体系到权限校验系统,从四种指令作用域与自动记忆到工具的执行流水线

同时从 82 个 feature flag 里挖出了 Anthropic 还没发布的未来功能蓝图:Kairos 自主运行模式、Context Collapse 上下文折叠、Voice Mode 语音交互。
同时从 2026 年 3 月快照的 82 个 feature flag 里挖出了 Anthropic 当时探索的未来功能蓝图:Kairos 自主运行模式、Context Collapse 上下文折叠、Voice Mode 语音交互。

最后几篇是我自己的思考:这份代码到底值不值钱、AI Coding 时代工程师怎么做 Code Review、以及从源码里能看到 Claude 封号机制的哪些线索。

Expand All @@ -51,16 +51,16 @@ Sourcemap 是前端构建工具生成的调试辅助文件,记录了编译后
| [03-Agent 循环](./docs/03-Agent循环.md) | 六阶段 ReAct 循环、AsyncGenerator 设计、状态管理、思维链保留 |
| [04-上下文工程](./docs/04-上下文工程.md) | System Prompt 构建、CLAUDE.md 加载、分层优先级、预取缓存、Prompt Cache 优化 |
| [05-消息压缩系统](./docs/05-消息压缩系统.md) | 三层压缩:微压缩、Session Memory、Full Compact,熔断器、递归保护 |
| [06-权限系统](./docs/06-权限系统.md) | 三模式权限、YOLO 分类器、42 条拦截规则、文件沙箱、Dangerous Rule Stripping |
| [07-记忆管理](./docs/07-记忆管理.md) | 五层记忆加载、@include 指令、MEMORY.md 管理、Session Memory |
| [06-权限系统](./docs/06-权限系统.md) | 六种权限模式、YOLO 分类器、历史快照中的 42 条规则、文件沙箱、Dangerous Rule Stripping |
| [07-记忆管理](./docs/07-记忆管理.md) | 四种指令作用域、自动记忆、@include 指令、MEMORY.md 管理、Session Memory |
| [08-工具与 Skill 系统](./docs/08-工具与Skill系统.md) | 40+ 工具注册、执行流水线、Pre/Post Hook、Skill fork 机制 |
| [09-MCP 集成](./docs/09-MCP集成.md) | 六种传输协议、OAuth、七种配置作用域 |
| [09-MCP 集成](./docs/09-MCP集成.md) | 四种传输类型(CLI 支持三种)、OAuth、三种安装作用域 |

### 前瞻篇

| 文档 | 内容 |
|------|------|
| [10-未来功能蓝图](./docs/10-未来功能蓝图.md) | 82 个 feature flag 解析、Kairos 自主模式、Context Collapse、语音模式 |
| [10-未来功能蓝图](./docs/10-未来功能蓝图.md) | 历史快照中的 82 个 feature flag、Kairos 自主模式、Context Collapse、已发布的语音模式 |
| [11-AI Coding 时代的 Code Review](./docs/11-AI-Coding时代的Code-Review.md) | 个人/团队/CICD 三层 Review 范式、Review Agent 设想 |
| [12-从权限系统学 Agent 安全设计](./docs/12-从Claude%20Code权限系统学Agent安全设计.md) | 三层防御体系拆解、L0-L4 安全成熟度模型、落地建议 |
| [13-啃完源码之后的一些发现](./docs/13-啃完源码之后的一些发现.md) | AI 工程化短板、生产事故、Claude 封号机制分析 |
Expand Down Expand Up @@ -104,9 +104,27 @@ bun run dev --version
|---|---|
| 源码快照 | 2026-03-31 的 sourcemap 还原产物 |
| 该构建自报版本 | `2.1.888` |
| 章节内容最近复核 | 2026-04-24(v1.0.0) |
| 章节内容最近复核 | 2026-08-11(Claude Code `2.1.227`,上游提交 `54cc51a`) |
| 仓库最近维护 | 2026-08-11(v1.1.0,链接与工具链,未改章节结论) |

这次复核以 npm 发布的 Claude Code `2.1.227` 和 Anthropic 的公开仓库提交 `54cc51a` 为基线。章节中关于 2026-03-31 sourcemap 的源码路径、行数和 feature flag 数量仍然是历史快照,不代表当前内部实现。

| 章节 | 复核结果 |
|---|---|
| 01 架构总览 | 历史源码快照保留;当前版本差异见 04、05、06、07、09、10 |
| 02 价值之争 | 分析性内容,无需版本修正 |
| 03 Agent 循环 | 核心循环分析保留为快照内容 |
| 04 上下文工程 | 更新当前模型上下文和记忆说明 |
| 05 消息压缩系统 | 更新当前可配置的自动压缩窗口 |
| 06 权限系统 | 更新当前六种权限模式;42 条规则标注为快照数据 |
| 07 记忆管理 | 更新自动记忆已在当前版本启用 |
| 08 工具与 Skill 系统 | 保留 40+ 这一保守下限,补充当前工具变化说明 |
| 09 MCP 集成 | 更新当前公开的传输类型和配置范围 |
| 10 未来功能蓝图 | 标出自动记忆、语音和 1M 上下文已落地 |
| 11 AI Coding 时代的 Code Review | 分析性内容,无需版本修正 |
| 12 Agent 安全设计 | 同步第 06 章的当前权限模式说明 |
| 13 源码发现 | 将 feature flag、依赖数和自动记忆预测标注为快照或已落地 |

上游改动导致某章描述失效,请开 [版本漂移 issue](https://github.com/anneheartrecord/claude-code-docs/issues/new?template=version-drift.yml)。这是本仓库最欢迎的一类 issue。

## 参与贡献
Expand Down
30 changes: 24 additions & 6 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Ironically, based on git history, this code was most likely written by AI itself

I used Claude Code to systematically analyze this source, module by module, producing 13 technical documents in both Chinese and English.

From architecture design to the six-phase Agent loop implementation, from the three-tier message compaction system to the 6,300-line permission system, from five-layer memory loading to the 40+ tool execution pipeline. I also extracted Anthropic's unreleased feature roadmap from 82 feature flags: Kairos autonomous mode, Context Collapse, Voice Mode.
From architecture design to the six-phase Agent loop implementation, from the three-tier message compaction system to the 6,300-line permission system, from four instruction scopes and auto memory to the 40+ tool execution pipeline. I also extracted Anthropic's explored feature directions from the 82 feature flags in the March 2026 snapshot: Kairos autonomous mode, Context Collapse, and Voice Mode.

The final documents include my own analysis: whether this code is truly valuable, how engineers should do Code Review in the AI Coding era, and what clues the source reveals about Claude's account ban mechanism.

Expand All @@ -51,16 +51,16 @@ The final documents include my own analysis: whether this code is truly valuable
| [03-Agent Loop](./docs/03-Agent-Loop.md) | Six-phase ReAct loop, AsyncGenerator design, state management, thinking chain preservation |
| [04-Context Engineering](./docs/04-Context-Engineering.md) | System prompt construction, CLAUDE.md loading, layered priorities, prefetch caching, prompt cache optimization |
| [05-Compaction System](./docs/05-Compaction-System.md) | Three-tier compaction: microcompact, session memory, full compact, circuit breaker, recursion guard |
| [06-Permission System](./docs/06-Permission-System.md) | Three-mode permissions, YOLO classifier, 42 interception rules, filesystem sandbox, dangerous rule stripping |
| [07-Memory System](./docs/07-Memory-System.md) | Five-layer memory loading, @include directives, MEMORY.md management, session memory |
| [06-Permission System](./docs/06-Permission-System.md) | Six permission modes, YOLO classifier, 42 rules from the historical snapshot, filesystem sandbox, dangerous rule stripping |
| [07-Memory System](./docs/07-Memory-System.md) | Four instruction scopes, auto memory, @include directives, MEMORY.md management, session memory |
| [08-Tools & Skills](./docs/08-Tools-and-Skills.md) | 40+ tool registry, execution pipeline, pre/post hooks, skill fork mechanism |
| [09-MCP Integration](./docs/09-MCP-Integration.md) | Six transport protocols, OAuth, seven config scopes |
| [09-MCP Integration](./docs/09-MCP-Integration.md) | Four transport types (three CLI transports), OAuth, three installation scopes |

### Forward-Looking

| Document | Content |
|----------|---------|
| [10-Future Features](./docs/10-Future-Features.md) | 82 feature flags decoded, Kairos autonomous mode, Context Collapse, voice mode |
| [10-Future Features](./docs/10-Future-Features.md) | 82 feature flags from the historical snapshot, Kairos autonomous mode, Context Collapse, shipped voice mode |
| [11-AI Code Review](./docs/11-AI-Code-Review.md) | Individual/team/CICD three-layer review paradigm, Review Agent concept |
| [12-Agent Security Design](./docs/12-Agent-Security-Design.md) | Three-layer defense system, L0-L4 security maturity model, practical guide |
| [13-Source Code Findings](./docs/13-Source-Code-Findings.md) | AI engineering blind spots, production incidents, Claude ban mechanism analysis |
Expand Down Expand Up @@ -103,9 +103,27 @@ A source teardown goes stale. Rather than leave readers guessing, here is exactl
|---|---|
| Source snapshot | sourcemap reconstruction dated 2026-03-31 |
| Version that build self-reported | `2.1.888` |
| Chapter content last re-verified | 2026-04-24 (v1.0.0) |
| Chapter content last re-verified | 2026-08-11 (Claude Code `2.1.227`, upstream commit `54cc51a`) |
| Repository last maintained | 2026-08-11 (v1.1.0 — links and tooling; no chapter conclusions changed) |

This review used the npm-published Claude Code `2.1.227` package and Anthropic's public repository at commit `54cc51a`. Claims about source paths, line counts, and feature-flag totals from the 2026-03-31 sourcemap remain historical snapshot data, not statements about the current private implementation.

| Chapter | Review result |
|---|---|
| 01 Architecture Overview | Historical source snapshot retained; current differences are covered in 04, 05, 06, 07, 09, and 10 |
| 02 Value Debate | Analytical content, no version correction needed |
| 03 Agent Loop | Core loop analysis retained as snapshot content |
| 04 Context Engineering | Current model context and memory wording updated |
| 05 Compaction System | Current configurable auto-compaction window updated |
| 06 Permission System | Current six permission modes added; 42-rule count marked as snapshot data |
| 07 Memory System | Current auto-memory availability updated |
| 08 Tools and Skills | Conservative 40+ lower bound retained, current tool changes noted |
| 09 MCP Integration | Current public transport types and configuration scope updated |
| 10 Future Features | Auto-memory, voice, and 1M context marked as shipped |
| 11 AI Code Review | Analytical content, no version correction needed |
| 12 Agent Security Design | Current permission-mode wording synced with chapter 06 |
| 13 Source Code Findings | Feature flags, dependency count, and auto-memory prediction marked as snapshot or shipped |

If an upstream change has invalidated something a chapter says, please open a [version drift issue](https://github.com/anneheartrecord/claude-code-docs/issues/new?template=version-drift.yml). It is the most welcome issue type here.

## Contributing
Expand Down
21 changes: 12 additions & 9 deletions docs/01-Architecture-Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# 01 Architecture Overview: How Claude Code Actually Runs

> Version scope: the source paths, line counts, permission modes, memory layers, and other exact figures in this chapter describe the March 31, 2026 sourcemap snapshot. They are historical implementation evidence, not a claim about the current private client.

## First, some background: how the source leaked

In March 2026, someone noticed that the Claude Code client package published to npm shipped with sourcemap files. Sourcemaps exist for debugging — they record the mapping between bundled code and the original source. They should be excluded at publish time, but Anthropic's build pipeline missed that step.
Expand Down Expand Up @@ -71,15 +73,16 @@ The whole picture first, then layer by layer.
┌───────────▼──────────┐ ┌──────────▼───────────────────┐
│ Permission system │ │ Tool execution layer │
│ 6,300 lines/25 files │ │ 40+ tools │
│ 3 modes + 42 rules │ │ Bash / File / Web / Agent │
│ ML classifier + jail │ │ Skill / MCP / Task │
│ March snapshot: │ │ Bash / File / Web / Agent │
│ 3 modes + 42 rules │ │ Skill / MCP / Task │
│ ML classifier + jail │ │ │
└──────────────────────┘ └───────────────────────────────┘
│ │
└───────────┬───────────┘
┌───────────────────────▼──────────────────────────────────┐
│ Context and memory layer │
CLAUDE.md five-layer loading / MEMORY.md / Session Memory
March snapshot: five-layer CLAUDE.md / MEMORY.md
│ Git status injection / Skill list / permission rules │
│ Three-tier compaction: micro / Session Memory / full │
└───────────────────────┬──────────────────────────────────┘
Expand Down Expand Up @@ -130,7 +133,7 @@ Before calling the API the system assembles a complete context. That context det
**The system prompt is concatenated from:**

1. built-in agent behavior rules telling the model it is Claude Code, that it can read and write files and execute commands, and how it should interact with the user
2. the user's CLAUDE.md memory files, loaded across five priority layers from global to project to local
2. the user's CLAUDE.md memory files, loaded across five priority layers in the March snapshot
3. a snapshot of the current Git repository: branch, recent commits, which files changed
4. permission rules: which tools may run automatically and which need confirmation
5. the Skill list: the extension capabilities currently available
Expand All @@ -155,7 +158,7 @@ If the model decides to call a tool, it emits a `tool_use` block in the response

Once `tool_use` arrives, the permission check runs first:

- hardcoded rules: 42 dangerous commands rejected outright, without asking
- March snapshot: 42 dangerous command patterns rejected outright, without asking
- ML classifier: judges whether this command is safe
- user rules: matched against the user's configured allow and deny lists
- confirmation prompt: when none of the above match, ask the user
Expand Down Expand Up @@ -192,9 +195,9 @@ If you want to read the source yourself, this table will orient you:
| `src/QueryEngine.ts` | 1,300 | Session state machine, 20+ config parameters | Understanding session management and config |
| `src/main.tsx` | 5,000+ | CLI entry, everything crammed in | Understanding the startup path |
| `src/context.ts` | 200+ | Git status injection, context assembly | Understanding context engineering |
| `src/utils/claudemd.ts` | 1,400+ | CLAUDE.md five-layer loading, @include | Understanding the memory system |
| `src/utils/claudemd.ts` | 1,400+ | March snapshot's five-layer loading, @include | Understanding the memory system |
| `src/services/compact/` | 26 files | Three-tier message compaction | Understanding long-conversation management |
| `src/utils/permissions/` | 6,300+ | Three-mode permission system | Understanding the security design |
| `src/utils/permissions/` | 6,300+ | March snapshot's three-mode permission system | Understanding the security design |
| `src/services/api/claude.ts` | 800+ | API client, retry, model fallback | Understanding the API layer |
| `src/tools.ts` | 300+ | Tool registry, feature flag control | Finding out which tools exist |
| `src/services/mcp/` | 12,000+ | MCP protocol integration | Understanding external tool integration |
Expand All @@ -207,9 +210,9 @@ If you want to read the source yourself, this table will orient you:
|---|---|---|---|---|
| Form | Terminal CLI | IDE plugin | Python library | Python framework |
| Agent loop | In-house ReAct + AsyncGenerator | Not public | ReAct / Plan-and-Execute | GroupChat + Planner |
| Permissions | 6,300 lines, 3 modes + ML classifier | IDE-level sandbox | Essentially none | Essentially none |
| Permissions | 6,300 lines, March snapshot: 3 modes + ML classifier | IDE-level sandbox | Essentially none | Essentially none |
| Context management | Three-tier compaction + prefetch cache + prompt cache optimization | Not public | Simple token truncation | None |
| Memory | Five-layer CLAUDE.md + MEMORY.md + Session Memory | Project-level index | Manual configuration | ConversableAgent memory |
| Memory | March snapshot: five-layer CLAUDE.md + MEMORY.md + Session Memory | Project-level index | Manual configuration | ConversableAgent memory |
| Tools | 40+ built in, plus Skill and MCP | Built in plus plugins | Register your own | Register your own |
| Codebase size | 515K lines | Not public | ~50K lines | ~30K lines |

Expand Down
Loading