L2S3 · 模型与编排S4 · 交互与 HITLS6 · 安全与成本Verified: 2026-11-17
L2 产品拆解 · Claude Code Agent Harness 设计、Subagent 委派与前缀缓存经济学
剖析终端编码代理标杆 Claude Code 的极简高鲁棒设计哲学:少而精的原子工具集(Read/Edit/Bash/Glob)、基于 `CLAUDE.md` 与 Prefix-Stable Prompt 的 >85% 前缀缓存命中率、自动 Context Compaction 与 Subagent 调研隔离。
适用场景 (Best For)
AI Engineer / Agent Framework 架构师设计长程命令行 Agent、工具契约简化与缓存经济成本控制。
人机边界 (Human-AI Boundary)
只读工具(Glob/Grep/Read)无阻塞并发放行;写入编辑、依赖安装与非安全命令严格遵循分档权限确认与项目 `CLAUDE.md` 边界守则。
常见反模式与避坑 (Anti-Patterns)
- Registering 60 overlapping MCP/API tool schemas in the system prompt, bloating per-turn tokens and confusing model tool selection
- Injecting changing timestamps or mutating earlier messages mid-session, invalidating expensive Anthropic prompt cache checkpoints
延迟成本与评测门禁
Cached prefill cuts multi-turn TTFT 60%–80%; interactive permission prompts cleanly asynchronous · 90% input token discount on append-only cached prompt prefixes
- Prefix Cache Read Share & Unattended Edit Verification Rate: >= 85% cached_read_tokens / total_input_tokens across multi-step repo sessions (Never mutate static system prompts, tool definitions, or earlier turns until explicit context compaction)
💰 商业 ROI 模型与证据等级
production_practice在长达 40–80 轮工具循环的真实软件工程任务中,Append-Only 前缀缓存将平均 Input Token 单价压低接近 8–10 倍;叠加洁净 Subagent 探索避免主上下文腐烂(Context Rot),一次性解决率显著攀升。
🏗️ 端到端系统架构流水线
Step 1: Append-Only 缓存稳定前缀 + 极简高正交工具集
系统指令、`CLAUDE.md` 与固定工具签名锁在最顶端;对话历史严格追加并在末尾挂 Cache Breakpoint,避免局部修改打破缓存。
Step 2: Context 临界压缩(Compaction)与子代理隔离检索
宽范围探索交给子代理过滤后再摘要回传;逼近上下文上限时总结历史进展并重建全新高信噪比锚点上下文。
⚖️ 工程选型与架构权衡矩阵
Minimal General Tools (Bash + Read/Edit + Search) + Strong Harness
适用条件:具备清晰命令行测试与构建反馈的软件工程与运维自动化。
核心权衡:泛化极强无需维护几十个脆性 API 封装,安全完全托底给沙箱与分层审批权限。
📊 同类技术选型与基准对比
- Strict Append-Only Prompt Cache vs Uncached Dynamic History Formatting: saves up to 80%+ multi-turn session spend on frontier coding models.
🚨 生产失效模式与可观测特征
- Mutating tool descriptions or live environment timestamps inside the prefix on each step, losing all cache discounts
- Auto-compacting silently and dropping key architecture constraints or modified file paths if structured state isn't preserved
⚡
想检验本题的肌肉记忆?进入 3 阶闪卡主动回忆盲测
隐藏答案遮罩,自测:审题锚点 ➔ 数理公式机理 ➔ 工业标杆代码与连环追问。3 分钟攻破认知盲区!
上下游关联知识链路
[L0 Card] Prompt Caching/RadixAttention[L0 Card] ReAct / Plan-Execute / Reflexion[L0 Card] 10 万并发 Code Agent 系统设计[L0] 大模型 Token FinOps、前缀缓存与语义缓存网关原语[L0] SGLang RadixAttention 自动前缀复用与零拷贝调度引擎[L0] Agent 多步轨迹与工具调用失败归因评测原语[L1] Stage 3 · 主从 Subagent Context 隔离与 Map-Reduce 分治模式[L1] Stage 4 · 高危写操作人工二次确认断点与 Diff 预览 UX 模式
站内交互工具与信源依据
- Anthropic Engineering — Claude Code Best Practices & Agentic Coding (engineering_blog, 2026-11-17)