本文由 AI 分析生成
建立時間: 2026-05-30 來源: https://x.com/AlchainHust/status/2038944798816505991
Summary
Following the accidental source map exposure of Claude Code’s 1902 TypeScript source files, this analysis dissects the harness engineering behind Claude Code. Key findings: a 7-section assembled system prompt with a cache boundary, a 4-tier security pipeline using a separate Claude Sonnet classifier, a strict memory system (user preferences only, never code facts), 9-segment structured context compression, and a swarm multi-agent framework with enterprise-like team coordination.
Claude Code 源碼意外外洩後的深度剖析。發現 Harness 核心:7 層動態拼裝的 System Prompt(含緩存分界線)、用第二個 AI 做安全分類的四層權限流水線、只記偏好不記代碼事實的記憶系統、9 段式結構化上下文壓縮、以及像真實公司一樣運作的 Swarm 多 Agent 框架。
Key Points
- System prompt split at SYSTEM_PROMPT_DYNAMIC_BOUNDARY: static parts cached (shared across users), dynamic parts loaded fresh per session
- Security: 4-tier pipeline (rule match → low-risk skip → read-only whitelist → Claude Sonnet classifier at temp=0); circuit breaker after 3 consecutive or 20 total denials
- Memory: extracted by a sandboxed fork agent; categorized into user/feedback/project/reference; deliberately NEVER stores code facts (code changes, memory doesn’t)
- Context compression: 9 structured segments; user messages are NEVER compressed — they contain implicit preferences
- Swarm: each team member has a mailbox file for async communication; permission requests bubble up to Leader rather than interrupting the user
- Search: uses grep/ripgrep — no vector embeddings. Smart brain + simple search beats complex search + weaker reasoning
- autoDream: triggers after 24h + 5+ new sessions to consolidate memory files into structured topics
- Internal (ant) vs external builds differ in code style, honesty strictness, output style, and A/B-tested features (Verification Agent, KAIROS)
Insights
The “memory stores preferences, not code” design principle is the right answer to a subtle problem: code is constantly changing, but if memory references specific line numbers or function names, it becomes outdated and actively misleading. By restricting memory to high-level user preferences and project context, the system ensures memory remains accurate indefinitely.
The 4-layer security pipeline with a separate AI classifier (not the same model doing the coding) is architecturally important: the coding model may have been manipulated by the context, but an independent classifier with its own system prompt is more robust. This is defense in depth applied to AI agent security.
Connections
Raw Excerpt
“Claude Code 好用,60% 靠模型能力,40% 靠 Harness 工程。同樣的底層模型,套上不同的 Harness,就是完全不同的產品。”