正在加载陈远的个人网站

Claude Code 分层编排:Opus 顾问、Sonnet 主建、Haiku 蜂群

基于官方 advisor 工具的三级模型编排配方:Opus 在关键节点审查,Sonnet 主力构建,Haiku 并行蜂群,附可复制配置提示词。

原始内容

holy sh*t. Official Anthropic tip for Claude Code: stop burning Opus 5.5 context on tasks Haiku 5.5 can swarm, while Sonnet 5.5 builds put the architect on call with /advisor claude --advisor opus --subagents haiku Sonnet 5.5 drives the primary session on high effort, writing diffs and running test suites Haiku 5.5 subagents swarm the repo in parallel at 340 tok/s, handling file discovery and spec docs lookup Opus 5.5 stays on call in the background as the advisor, only stepping in at three critical moments: → before a plan locks: does the implementation plan miss auth invariants or schema contracts? → when a test breaks twice: are we fixing the root cause or falling into a recursive rabbit hole? → before calling done: did the full diff introduce hidden regressions or break pre-flight rules? Opus 5.5 reviews. Sonnet 5.5 builds. Haiku 5.5 swarms Jev engineering runs the identical pattern one layer down: mechanical decisions that need no reasoning (which file to open, which tool to invoke, retry or abort) execute in 16ms, so the frontier models only wake up when execution paths actually diverge Plan on high. Delegate on medium. Keep Opus on call. - the full advisor setup > Opus 5.5 on call reads full session history and catches deep architectural traps > Sonnet 5.5 lead drives edits, writes core logic, and executes test harnesses > Haiku 5.5 subagents swarm AST parsing, grep scans, and API docs in parallel > JEV micro-fork layer resolves 1,500+ mechanical routing branches in under 16ms > advisor stays completely silent on routine bash execution to protect context paste the setup and this prompt into Claude Code below: "Configure my Claude Code workspace for hierarchical advisor orchestration: 1. Audit ~/.claude/settings.json and project config for model roles fitting lead, subagents, and advisor: > Pin main session model: sonnet with effortLevel: high for primary execution > Pin subagents model: haiku with effortLevel: medium for parallel file discovery and docs retrieval > Pin advisor model: opus on call for strategic review 2. Enable the advisor tool in ~/.claude/settings.json: > Set advisorModel to claude-opus-5-5 > Enable subagent parallel dispatcher pool (3x workers) 3. Configure automatic advisor consultation checkpoints in ~/.claude/CLAUDE.md: > Consult /advisor opus before finalizing multi-file architecture plans > Automatically summon /advisor opus when the same test or compiler error fails twice > Enforce advisor diff contract audit before declaring tasks complete or staging git commits 4. Constrain subagent scopes: > Haiku subagents return structured AST summaries and docs snippets only without modifying main session context Show every configuration diff first. Do not apply edits until confirmed" ↳ https://t.co/gvAWk6KbDn

Harness Engineering: How to Build AI Workflows That Never Fall Apart Most people respond to a broken AI output by rewriting the prompt Then they switch models Then they upgrade to a larger context window The model still forgets instructions It still recommends the wrong tool It still skips verification It still claims success on broken work The problem sits outside the model weights The problem sits in the execution environment That environment is the harness Designing it is harness engineering Dario Amodei explained this directly during the launch of Claude Code: "Of course, you need an interface, you need a harness to use them" The model acts as a reasoning engine A model can predict the next logical step It cannot build a stable operating system on its own The harness controls what the model reads, what tools it can trigger, what data survives context resets, and when the execution must halt Prompt engineering adjusts the wording Harness engineering builds the infrastructure where that wording executes Put a frontier model in an empty chat box, and it generates casual prose Put that identical model in a repository with terminal access, automated test suites, project maps, and isolated workspaces, and it ships working software The weights stay identical The harness changes everything OpenAI recorded the identical pattern when training agents on Codex Their early runs failed because the environment was underspecified The engineering team avoided asking the model to try harder They built explicit capability checks and mechanical boundaries When an agent fails repeatedly, stop editing adjectives in the system prompt Inspect the operating system around the model --- # The Three Layers of a Reliable AI System Builders often treat prompt chains, agent loops, and multi-agent graphs as competing ideas They represent three distinct layers of one system ## 1. The Harness Layer (Environment and Memory) The harness consists of everything existing outside model weights It manages filesystem access, environment variables, authentication tokens, and durable files Andrej Karpathy established the defining mental model: The model is the CPU The context window is the RAM A raw CPU without storage or an operating system crashes instantly When users dump twenty pages of background text into a single prompt, they flood the RAM The model loses attention on critical rules A clean harness stores project knowledge in external markdown files It loads only the exact snippet needed for the immediate step ## 2. The Loop Layer (Evidence and Convergence) A model outputting code or text needs automated validation Asking the model "Are you sure this is right?" creates a circular hallucination loop The model evaluates its own probabilistic prediction and confirms its initial bias The loop layer introduces objective sensors: - Test runners (pytest, vitest, cargo test) - Format validators (JSON schema checkers, linters) - Execution budgets (maximum four attempts before human review) The model suggests the correction The harness runs the test and supplies the raw terminal output Execution continues only when mechanical evidence confirms the fix ## 3. The Graph Layer (Work Allocation) Long tasks crumble when forced into a single endless conversation thread The graph layer distributes work across isolated execution contexts One worker analyzes the task and writes an implementation blueprint A second worker writes the code in an isolated directory branch A third adversarial worker reviews the diff against project requirements Context stays clean No single prompt carries the burden of the entire project lifecycle --- # The 5 Core Jobs of a Personal AI Harness You do not need a massive enterprise platform to apply harness engineering A personal harness requires five mechanical rules in your everyday workflows ## 1. Turn Every Request into a Bounded Contract Conversational prompts allow models to silently redefine success When an ambiguous prompt encounters friction, the model solves an easier adjacent task and reports victory A production contract sets hard boundaries before generation starts: - Deliverable: Exact file name and format - Constraints: Dependencies allowed, style requirements, token budget - Non-Goals: Explicit list of items the model must avoid touching - Acceptance Criteria: The exact condition required to close the task Without an explicit contract, the model decides when it finishes With a contract, the criteria decides when the model finishes ## 2. Provide a Map, Not an Encyclopedia Context degradation strikes every frontier model over long horizons Dumping an entire project documentation file into chat burns tokens and dilutes focus Elite builders create a compact root map The map outlines where documentation, schemas, and source files live The model scans the map, selects the single relevant file, and reads that file alone A compact map preserves working memory A giant prompt dump exhausts it ## 3. Externalize Memory into Durable Files Chat history serves as temporary scratch space The conversation thread is not a database When a session runs long, attention fades and context windows fill up Store architecture decisions, user preferences, and unresolved bugs in a dedicated project file In Claude Code and Cursor, this file is `CLAUDE.md` or `.cursorrules` When starting a fresh session, the model reads the file and resumes immediately The work survives chat wipes, rate limits, and model switches ## 4. Build Sensors Before Granting Autonomy An agent cannot repair errors it cannot observe Telling a model "write bug-free code" changes nothing Providing a command that outputs exit code zero or a stack trace gives the model ground truth Sensors turn subjective quality into verifiable evidence: - Compilers and type checkers that fail on syntax errors - Automated test scripts that verify data transformations - Checklist validators that confirm all required fields exist The model creates the artifact The sensor generates the evidence The harness decides if the run passes ## 5. Apply the Dual-Encoding Rule Writing a rule in plain English leaves room for probabilistic failure The model reads the instruction, parses twenty other constraints, and skips the rule under load Dual-encoding solves this permanently: First, explain the rule in text so the model understands the goal Second, place a mechanical gate that blocks execution if the rule breaks If an agent must avoid deleting files, tell it in the prompt Then restrict its terminal permissions so `rm -rf` throws an operating system error The prompt guides the intention The mechanical gate protects the system --- # How to Set Up a Personal Micro-Harness Here is a five-minute harness structure you can paste into any repository, Claude Project, or Cursor workspace Save this content as `HARNESS.md` in your project root: ```markdown # Project Operating Contract ## Operating Boundaries - Allowed scope: Modify only files explicitly assigned in the current task - Forbidden actions: Never delete existing tests, never add unverified dependencies ## Project Map - /src: Application source code - /tests: Validation test suites - /docs/decisions.md: Durable log of accepted architectural choices ## Verification Protocol Before marking any task complete, run these checks in order: 1. Run local linter: `npm run lint` 2. Run test suite: `npm test` 3. Verify output format matches the requested schema ## Failure Escalation If a test fails twice on the same error: - Stop autonomous editing - Print the exact error log - State the proposed fix and wait for user confirmation ``` This short file replaces twenty lines of repetitive prompting in every chat It establishes project scope, controls file access, and forces mechanical verification --- # The Two-Pass Prompting Workflow When working on difficult reasoning tasks in standard chat interfaces, use a two-pass harness loop Most users ask for an answer and accept the first draft Production workflows split generation and critique into separate passes ## Pass 1: The Execution Pass ```markdown Draft the technical specification for [Feature X]. Follow the constraints listed in HARNESS.md. Do not evaluate your own output yet. Output the raw draft and state all assumptions made. ``` ## Pass 2: The Adversarial Review Pass ```markdown Review the draft above as a skeptical senior reviewer. Check against these specific failure points: 1. Are edge cases handled when input arrays are empty? 2. Does the logic introduce extra dependencies? 3. Does the solution violate any constraint from HARNESS.md? List every failure point found. Then output the revised version fixing those gaps. ``` Separating the creator role from the reviewer role cuts hallucinated claims in half The model cannot defend its own errors when explicitly instructed to attack them --- # Why the Harness Compounds Models update every few months Prompts that work today often produce different outputs on the next model checkpoint Harness engineering preserves your engineering effort When Anthropic releases an updated Claude or OpenAI launches a new reasoning model, your prompts might require minor adjustments Your test suites, project maps, permission boundaries, and durable state files remain intact They work on the new model immediately The model provides raw cognitive compute The harness provides the rails that turn compute into reliable execution Stop tweaking adjectives in your prompts Start building the harness around them

— @mirku21(mirku)的引用原文
在 X 上查看原视频

中文译文

机器翻译,保留原文供核对。

我去。Anthropic 官方给出的 Claude Code 技巧:别再让 Opus 5.5 的上下文浪费在 Haiku 5.5 能群殴完成的任务上,让 Sonnet 5.5 去构建 用 /advisor 把架构师挂成随叫随到 claude --advisor opus --subagents haiku Sonnet 5.5 以 high effort 驱动主会话,写 diff、跑测试套件 Haiku 5.5 子代理以 340 tok/s 在仓库里并行群扫,负责文件发现和规格文档检索 Opus 5.5 留在后台待命当顾问,只在三个关键时刻介入: → 计划锁定前:这份实施计划是否漏掉了鉴权不变量(auth invariants)或 schema 契约? → 测试两次失败时:我们是在修根因,还是掉进了递归兔子洞? → 宣布完成前:整份 diff 是否引入了隐藏回归,或破坏了 pre-flight 规则? Opus 5.5 审。Sonnet 5.5 建。Haiku 5.5 群扫。 Jev 工程把同一套模式下沉一层:不需要推理的机械决策(打开哪个文件、调用哪个工具、重试还是中止)在 16ms 内执行完,于是前沿模型只在执行路径真正分叉时才被唤醒 规划用 high。委派用 medium。Opus 保持待命。 - 完整的顾问配置 > Opus 5.5 待命时会读取完整会话历史,捕捉深层架构陷阱 > Sonnet 5.5 主控负责编辑、写核心逻辑、执行测试框架 > Haiku 5.5 子代理并行处理 AST 解析、grep 扫描和 API 文档 > JEV 微分叉层在 16ms 内解析 1500+ 条机械路由分支 > 常规 bash 执行时顾问完全静默,以保护上下文 把配置和下面这段提示词粘进 Claude Code: "为我的 Claude Code 工作区配置分层顾问编排: 1. 审计 ~/.claude/settings.json 和项目配置,确定适合主控、子代理、顾问三种角色的模型: > 固定主会话模型:sonnet,effortLevel: high,用于主执行 > 固定子代理模型:haiku,effortLevel: medium,用于并行文件发现与文档检索 > 固定顾问模型:opus 待命,用于策略性审查 2. 在 ~/.claude/settings.json 中启用 advisor 工具: > 把 advisorModel 设为 claude-opus-5-5 > 启用子代理并行调度池(3x workers) 3. 在 ~/.claude/CLAUDE.md 中配置自动顾问咨询检查点: > 在敲定多文件架构计划前咨询 /advisor opus > 当同一测试或编译器错误连续失败两次时,自动召唤 /advisor opus > 在宣布任务完成或暂存 git 提交前,强制执行顾问 diff 契约审计 4. 约束子代理作用域: > Haiku 子代理只返回结构化 AST 摘要和文档片段,不得修改主会话上下文 先展示每一处配置 diff。未确认前不要应用修改" ↳ https://t.co/gvAWk6KbDn

Harness Engineering:如何构建永不崩溃的 AI 工作流 多数人对跑偏的 AI 输出,第一反应是重写提示词 接着换模型 再升级到更大的上下文窗口 模型依然忘记指令 它依然推荐错误的工具 它依然跳过验证 它依然在成果已经坏掉时宣称成功 问题不在模型权重里 问题在执行环境里 那个环境就是 harness(执行框架) 设计它就是 harness engineering Dario Amodei 在 Claude Code 发布时直接解释过这一点: "当然,你需要一个界面,你需要一个 harness 才能使用它们" 模型充当推理引擎 模型能预测下一个合乎逻辑的步骤 它无法独自构建一个稳定的操作系统 harness 控制模型读什么、能触发哪些工具、哪些数据能在上下文重置后存活、以及执行何时必须中止 提示词工程调整措辞 harness 工程搭建让这些措辞得以执行的基建设施 把前沿模型放进一个空的聊天框,它只会产出闲聊式的文字 把同一个模型放进带终端访问、自动化测试套件、项目地图和 isolated 工作区的仓库里,它能交付可用的软件 权重完全没变 harness 改变了一切 OpenAI 在 Codex 上训练 agent 时记录了完全相同的模式 他们早期的运行失败,是因为环境定义不充分 工程团队没有去要求模型"再努力一点" 他们构建了显式的能力检查和机械边界 当一个 agent 反复失败时,别再改系统提示词里的形容词 去检查模型周围的那个操作系统 --- # 可靠 AI 系统的三层结构 构建者常把提示词链、agent 循环、多 agent 图看作互相竞争的理念 它们其实代表同一系统的三个不同层 ## 1. Harness 层(环境与记忆) harness 由模型权重之外的一切组成 它管理文件系统访问、环境变量、鉴权令牌和持久化文件 Andrej Karpathy 给出了那个定义性的心智模型: 模型是 CPU 上下文窗口是内存 没有存储、没有操作系统的裸 CPU 会瞬间崩溃 当用户把二十页背景文本一股脑塞进单个提示词时,他们淹没了内存 模型对关键规则的注意力随之流失 干净的 harness 把项目知识存进外部 markdown 文件 它只加载当前这一步所需的那一小段 ## 2. 循环层(证据与收敛) 输出代码或文本的模型需要自动化校验 问模型"你确定这是对的吗?"只会造出一个循环幻觉 模型评估自己的概率性预测,然后确认自己最初的偏见 循环层引入客观传感器: - 测试运行器(pytest、vitest、cargo test) - 格式校验器(JSON schema 检查器、linter) - 执行预算(最多尝试四次,之后交人工审查) 模型提出修正 harness 运行测试并提供原始终端输出 只有在机械证据确认修复后,执行才继续 ## 3. 图结构层(工作分配) 长任务一旦被塞进单条无尽对话线程就会崩坏 图结构层把工作分散到多个 isolated 执行上下文 一个 worker 分析任务并写出实施蓝图 第二个 worker 在 isolated 目录分支里写代码 第三个对抗性 worker 对照项目需求审查 diff 上下文保持干净 没有任何单条提示词需要背负整个项目生命周期的重量 --- # 个人 AI Harness 的 5 项核心工作 你不需要庞大的企业平台才能应用 harness engineering 个人 harness 只需要在日常工作流中落实五条机械规则 ## 1. 把每个请求变成有边界的契约 对话式提示词允许模型悄悄重新定义成功 当含糊的提示词遇上阻力,模型会去解一个更容易的相邻任务,然后报告胜利 生产级契约在生成开始前就设定硬边界: - 交付物:确切文件名和格式 - 约束:允许的依赖、风格要求、token 预算 - 非目标:模型必须避免触碰的事项的显式清单 - 验收标准:关闭该任务所需的确切条件 没有契约,由模型决定何时结束 有了契约,由标准决定模型何时结束 ## 2. 提供地图,而不是百科全书 在长周期任务中,上下文退化会击中每一个前沿模型 把整份项目文档倒进对话既烧 token 又稀释注意力 顶尖构建者会做一份紧凑的根地图 地图标出文档、schema 和源文件分别在哪 模型扫一遍地图,挑出唯一相关的那份文件,只读那一份 紧凑的地图保住工作记忆 巨大的提示词倾倒会把它耗尽 ## 3. 把记忆外置到持久化文件 聊天历史只是临时草稿纸 对话线程不是数据库 会话拖长后,注意力衰退,上下文窗口被填满 把架构决策、用户偏好、未解决的 bug 存进专门的项目文件 在 Claude Code 和 Cursor 里,这个文件是 `CLAUDE.md` 或 `.cursorrules` 开新会话时,模型读这个文件就能立刻接上 工作成果能扛过聊天清空、速率限制和模型切换 ## 4. 先建传感器,再授予自主权 agent 无法修复它观测不到的错误 告诉模型"写无 bug 的代码"什么也改变不了 给模型一条能输出退出码 0 或堆栈跟踪的命令,它才拿到基准事实 传感器把主观质量变成可验证的证据: - 语法错误就会失败的编译器和类型检查器 - 验证数据转换的自动化测试脚本 - 确认所有必填字段存在的清单校验器 模型产出制品 传感器产出证据 harness 决定这一轮是否通过 ## 5. 采用双重编码规则 用自然语言写一条规则,就留下了概率性失败的空间 模型读完指令,再解析另外二十条约束,在负载下就跳过了那条规则 双重编码能永久解决这个问题: 第一,用文字解释规则,让模型理解目标 第二,设置机械闸门,规则被破坏时阻断执行 如果 agent 必须避免删文件,就在提示词里告诉它 然后限制它的终端权限,让 `rm -rf` 直接抛出操作系统错误 提示词引导意图 机械闸门保护系统 --- # 如何搭建个人微型 harness 这是一个五分钟就能搭好的 harness 结构,可以粘进任何仓库、Claude Project 或 Cursor 工作区 把以下内容存为项目根目录的 `HARNESS.md`: ```markdown # Project Operating Contract ## Operating Boundaries - Allowed scope: Modify only files explicitly assigned in the current task - Forbidden actions: Never delete existing tests, never add unverified dependencies ## Project Map - /src: Application source code - /tests: Validation test suites - /docs/decisions.md: Durable log of accepted architectural choices ## Verification Protocol Before marking any task complete, run these checks in order: 1. Run local linter: `npm run lint` 2. Run test suite: `npm test` 3. Verify output format matches the requested schema ## Failure Escalation If a test fails twice on the same error: - Stop autonomous editing - Print the exact error log - State the proposed fix and wait for user confirmation ``` 这份短文件替代了每个对话里重复二十行的提示词 它确立项目范围、控制文件访问,并强制机械验证 --- # 两遍式提示词工作流 在标准聊天界面处理较难的推理任务时,使用两遍式 harness 循环 多数用户要一个答案,然后接受初稿 生产级工作流把生成与批判拆成两个独立回合 ## 第一遍:执行遍 ```markdown Draft the technical specification for [Feature X]. Follow the constraints listed in HARNESS.md. Do not evaluate your own output yet. Output the raw draft and state all assumptions made. ``` ## 第二遍:对抗性审查遍 ```markdown Review the draft above as a skeptical senior reviewer. Check against these specific failure points: 1. Are edge cases handled when input arrays are empty? 2. Does the logic introduce extra dependencies? 3. Does the solution violate any constraint from HARNESS.md? List every failure point found. Then output the revised version fixing those gaps. ``` 把创作者角色与审查者角色分开,能把幻觉式断言砍掉一半 当被明确要求攻击自己的错误时,模型无法为自己的错误辩护 --- # 为什么 harness 会复利 模型每隔几个月就更新 今天有效的提示词,在下一个模型检查点上常常产出不同结果 harness engineering 保住你的工程投入 当 Anthropic 发布新版 Claude,或 OpenAI 推出新的推理模型,你的提示词也许只需微调 你的测试套件、项目地图、权限边界和持久状态文件依然完好 它们在新模型上立刻可用 模型提供原始认知算力 harness 提供把算力变成可靠执行的轨道 别再调提示词里的形容词了 开始为它们搭 harness

引用内容译文

深度解析

是什么:推文与配套视频提出基于 Claude Code 官方 advisor 工具的三级模型编排配方:Sonnet 5.5 主会话高投入写代码跑测试,Haiku 5.5 子代理并行做文件发现与文档检索,Opus 5.5 作为顾问仅在关键节点介入,并附一份可直接粘贴进 Claude Code 的配置提示词。

核心论点链:官方文档证实 advisor 真实存在——主模型可在计划锁定前、同一错误反复失败、宣告完成前咨询更强模型;advisor 接收完整会话历史(含所有工具调用),以服务端工具运行,且有严格的模型配对等级表(顾问不得低于主模型)。推文在此基础上演绎出"Opus 审查、Sonnet 构建、Haiku 蜂群"的分工,以及"Plan on high. Delegate on medium. Keep Opus on call"的成本分层口诀。

关键洞察:把 token 花在真正决定结果的地方——机械决策(选文件、选工具、重试或中止)下沉到代码与廉价模型层,前沿模型只在执行路径分叉时醒来;顾问读全量上下文却对常规执行保持沉默,以保护上下文预算与提示缓存。

边界与风险:JEV 微 fork 层、16ms、1500+ 分支、340 tok/s 及 --subagents 旗标均不见于官方文档,疑为演绎或虚构数据;advisor 属实验特性,仅限 Anthropic API(Bedrock 等不可用),会推高 token 成本;文中提示词会改写 settings.json 与 CLAUDE.md,照搬前应先审查 diff、确认模型版本(需 v2.1.260+)。

精选追评与案例

  1. 直接贴出终端实测报错,证明 `--subagents` 参数并不存在。

    @mirku21 ``` $ claude --advisor opus --subagents haiku error: unknown option '--subagents' (Did you mean --agents?) ```

    中文译文 · 机器翻译

    ``` $ claude --advisor opus --subagents haiku error: unknown option '--subagents' (Did you mean --agents?) ```

  2. 指出配置行不通,并给出 Anthropic 官方的正确做法链接。

    @mirku21 That does not work as described - here is the right solution, directly from @AnthropicAI #Claude https://t.co/rOa2N4JgyI

    中文译文 · 机器翻译

    这与描述不符——这是来自 @AnthropicAI #Claude 的正确方案 https://t.co/rOa2N4JgyI

  3. 从缓存命中率与成本角度,拆穿多层路由反而更贵的逻辑漏洞。

    @mirku21 It does not make sense to let the router decide on every request where to send it as the cache hit rate will go down and you will pay more than just using Opus 5.5 Also, @jev often does not have the full context to make the right decision.

    中文译文 · 机器翻译

    让路由器对每个请求自行决定发往哪里并不合理,因为缓存命中率会下降,你付出的成本会比直接用 Opus 5.5 更高。另外,@jev 往往没有完整上下文来做正确判断。

  4. 提醒 Haiku 群组失败后回流主模型的成本可能更高,效果取决于任务边界如何切分。

    @mirku21 advisor+subagents这个思路是真不错,但别吹成万能。Haiku swarm失败的case最后回归主模型,成本可能反而更高,得看任务边界怎么切

  5. 质疑把调度职责交给 Haiku,指出上下文协调应由更强的模型承担。

    @mirku21 surely the haiku subagent dispatcher won’t be what you want u want that model to be better?? because it has to coordinate all the context and a2a messaging??? sonnet could do it tbf

    中文译文 · 机器翻译

    Haiku 子代理调度器恐怕不是你要的 你不想让那个模型更强一点吗??因为它得协调所有上下文和 agent 间消息??? 不过 Sonnet 干这个应该可以