本文由 AI 分析生成
建立時間: 2026-03-31 來源: https://x.com/YukerX/status/2038959908968919297
Summary
A deep-dive analysis of Claude Code’s accidentally leaked 512,000-line TypeScript source code. The author frames Claude Code not as a coding assistant but as an operating system: 42 tools as system calls, a permission system as user privilege management, skills as an app store, MCP as device drivers, agent swarms as process management, and context compression as memory management. The engineering patterns revealed — layered prompt assembly, fail-closed tool defaults, multi-AI safety review, three-tier context compression, and KAIROS dream-time memory consolidation — are the actual source of Claude Code’s superior feel.
對 Claude Code 意外洩露的 51.2 萬行 TypeScript 源碼的深度分析。作者將 Claude Code 框架為作業系統:42 個工具作為系統呼叫、權限系統作為使用者權限管理、skills 作為應用商店、MCP 作為裝置驅動、agent 蜂群作為行程管理、上下文壓縮作為記憶體管理。揭示的工程模式是 Claude Code 優越感的真實來源。
Key Points
- System prompt is assembled in 7 dynamic layers with a cache boundary (SYSTEM_PROMPT_DYNAMIC_BOUNDARY) splitting static (shared/cached) from dynamic (per-user) sections
- Each tool has its own prompt.ts “manual written for the AI” — BashTool’s is 370 lines of behavioral constraints
- Tool defaults are fail-closed: isConcurrencySafe and isReadOnly both default false — unknown tools are assumed unsafe
- “Pre-read before edit” is enforced at the code level: FileEditTool errors if you haven’t read the file first
- Memory retrieval uses a second AI (Claude Sonnet) to select up to 5 relevant memory files — precision over recall
- KAIROS mode: raw logs during the day, /dream skill distills them into structured topic files overnight (“AI sleeping to consolidate memory”)
- Three compression tiers: micro-compaction (clear old tool results), auto-compaction at 87% context usage with circuit breaker, full AI summarization with mandatory no-tool preamble
- Sub-agent anti-recursion: child agents receive an explicit “You ARE the fork. Do NOT spawn sub-agents” injection
Insights
The internal vs. external version divergence is the most revealing detail: Anthropic’s internal build requires AI to admit uncertainty explicitly, demands verification before claiming success, and applies “倒金字塔” (inverted pyramid) writing. These are the properties Anthropic considers ideal AI behavior — and they ship a softer external version. The implication is that the publicly available Claude Code is deliberately more forgiving than what Anthropic trusts internally.
Connections
Raw Excerpt
“Claude Code好用,60%靠Opus模型本身的能力,40%靠围绕模型搭建的工程系统(也就是harness)。”