Skip to content

feat: rewrite Claude Code architecture article (278→1,333 lines)#28

Merged
wenshao merged 1 commit into
mainfrom
rewrite/architecture-doc
Apr 3, 2026
Merged

feat: rewrite Claude Code architecture article (278→1,333 lines)#28
wenshao merged 1 commit into
mainfrom
rewrite/architecture-doc

Conversation

@wenshao

@wenshao wenshao commented Apr 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Complete rewrite of docs/tools/claude-code/03-architecture.md based on v2.1.89 decompiled source analysis
  • Expanded from 278 lines to 1,333 lines across 22 sections with 44 source code references
  • Updated README.md index entry to reflect new content scope

New/Rewritten Sections (22)

# Section Key Content
1 运行时与二进制格式 Bun runtime (not Node.js SEA), 22 feature flag DCE, native modules
2 Bootstrap 启动链 3-level lazy loading, fast paths, parallel prefetch
3 模块架构 Full directory tree with layer descriptions
4 核心运行时循环 QueryEngine AsyncGenerator, REPL vs headless, process model
5 状态管理 35-line pub/sub Store, AppState (71+ fields), SpeculationState
6 API 通信层 4-provider factory (Direct/Bedrock/Vertex/Foundry), SSE streaming, stall detection
7 模型选择与路由 5-level priority, Fast Mode ($30/$150), Advisor server-side review, Extended Thinking
8 上下文窗口管理 7-level resolution, 8k→64k slot optimization, 1M context support
9 Prompt Caching global/org scope, system prompt cache strategy, break detection
10 重试与退避 Foreground/background 529 handling, Opus→Sonnet degradation, persistent retry
11 成本追踪 Full pricing table (7 tiers), cost formula, session persistence
12 系统提示构建 8 sections, 6-level assembly priority, cache splitting
13 消息类型 Message type hierarchy, 6 system subtypes, content block types
14 工具系统 39 tools registry, 3 conditional loading mechanisms, execution pipeline
15 权限与安全模型 6 permission modes, 8-source rule priority, 23 Bash security checks, 18 Zsh commands, 12 substitution patterns
16 命令系统 ~88 commands (79 external), 3 command types, dispatch mechanism
17 Hook 事件系统 24 hook events, response schema, event dispatch
18 插件系统 3-scope hierarchy, lifecycle, marketplace
19 自动更新 Dual-channel (npm/GCS), lock mechanism, kill switches
20 遥测系统 782 tengu events, GrowthBook, Machine ID, privacy controls, MDM
21 关键依赖 13 dependency categories
22 内部代号 8 codenames (tengu, kairos, chicago, etc.)

7-Round Audit Fixes

Round Type Issues Fixed
1 Source verification 7 (runtime Bun vs Node.js SEA, Zsh count 17→18, pattern count 11→12, typo)
2 Reverse verification 3 (permission priority order reversed, Ink vendored fork, React 19)
3 Cross-doc consistency 3 (tools 40+→39, hooks 26+→24, commands 88+→~88)
4 Precise source check 1 (BQ p99 = 4,911 tokens confirmed)
5 Omission audit 3 (added Advisor, Extended Thinking, Plugin System, Auto-Update)
6 Format & numbering 10 (section renumbering after insertions)
7 Final consistency 0 (clean)

Test plan

  • Verify markdown renders correctly on GitHub
  • Cross-check numerical claims with 04-tools.md (39 tools) and 06-settings.md (24 hooks)
  • Spot-check 3+ source code references against decompiled source

🤖 Generated with Claude Code

…ce-code-verified)

Complete rewrite of 03-architecture.md based on v2.1.89 decompiled source analysis.
22 sections covering: Bun runtime, 22 feature flag DCE, bootstrap chain, module
architecture, QueryEngine loop, state management, API 4-provider communication,
Advisor server-side review, Extended Thinking, context window, prompt caching,
retry/backoff (529 degradation), cost tracking, system prompt construction,
message types, 39 tools, 23 Bash security checks, permission model, command system,
24 hook events, plugin system, auto-update, telemetry system. 44 source references.

7-round audit: fixed runtime (Node.js SEA→Bun), permission priority order,
Zsh command count (17→18), substitution pattern count (11→12), cross-doc
consistency (tools 40+→39, hooks 26+→24), init() call chain accuracy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wenshao wenshao merged commit 8991114 into main Apr 3, 2026
wenshao added a commit that referenced this pull request Apr 5, 2026
Added PR progress links to detail items:
- p0-p1-core #3 (Speculation): PR#2525 ✓
- p0-p1-engine #22 (Thinking retention): PR#2897
- p0-p1-engine #23 (Output token escalation): PR#2898
- p2-stability #28 (Dangerous actions guidance): PR#2889

Previously only the matrix had PR links, now clicking ↓ also shows progress.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
wenshao added a commit that referenced this pull request Apr 5, 2026
New items from second round of source code comparison:

P0 (2 items):
- #19: Environment variable sanitization (25+ patterns)
- #20: Dangerous command blacklist (rm -rf, find -exec, git -c, etc.)

P1 (4 items):
- #21: Edit fuzzy matching with Levenshtein distance (10% tolerance)
- #22: Omission placeholder detection (prevent "// ... rest")
- #23: JIT context discovery for read/write/edit tools
- #24: OS-level sandbox (Linux bwrap, macOS Seatbelt, Windows)

P2 (6 items):
- #25: Folder trust discovery (pre-execution scanning)
- #26: Web fetch rate limiting + SSRF hardening
- #27: Grep advanced parameters (include/exclude/names_only)
- #28: Advanced vim operations (big words, find, replace, toggle)
- #29: Footer customization dialog
- #30: Write file LLM content correction

P3 (2 items):
- #31: OAuth flow refactoring (shared utils + RFC 9728)
- #32: Conseca safety framework (context-aware policy)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant