The Harness Is the Machine: Task Contracts, Worktrees, Receipts
A long-form X post outlining a production architecture for coding agents. The thesis: when an agent fails a multi-file refactor, the problem is not the prompt or the model but the environment around it — the harness. The author lays out a seven-stage pipeline: Opus compiles a task_contract.json with path allowlists and a cost/turn/timeout budget; the harness spawns an isolated git worktree; Sonnet edits only inside the boundary; Haiku validates every tool call parameter; a separate model acts as adversarial skeptic against the diff; a pre-commit hook checks test exit codes and signs a receipt.json; failures crystallize into rules, skills, and regression evals. Includes contract schema, isolate_worktree.sh, pre-tool.sh, receipt format, and a 10-point pre-flight checklist. Caveat: the Opus/Sonnet/Haiku/Fable 5.5 model names and the 18%→95% success numbers are unsourced, and the post ends with a Telegram funnel link.
A complete architectural guide to task contracts, isolated worktrees, adversarial verification, and the compounding flywheel across Opus, Sonnet, Haiku, and Fable 5.5
bookmark this and read the complete production agent playbook below ↓

一份完整的架构指南:任务契约、隔离 worktree、对抗式验证,以及 Opus、Sonnet、Haiku 和 Fable 5.5 之间不断复利的飞轮。
建议收藏,下面就是完整的生产级 agent 实战手册 ↓

When an autonomous AI agent fails 14 turns into a multi-file refactor, most developers make the same mistake
They rewrite the prompt
Then they switch models
Then they upgrade to a larger context window
The agent still forgets earlier decisions. It still modifies the wrong files. It still outputs: All 48 unit tests passed successfully, without running a test runner
The failure comes from the environment around the model. That environment is the harness. Designing it is Harness Engineering
一个自主 AI agent 在跨文件重构进行到第 14 轮时失败,多数开发者会犯同一个错误:
重写 prompt。
换模型。
升级到更大的上下文窗口。
但 agent 照样忘记之前的决定,照样改错文件,照样在根本没跑测试的情况下输出:“48 个单元测试全部通过”。
问题出在模型周围的环境。这个环境就是 harness。设计 harness 的工作,就是 Harness Engineering。
Dario Amodei, CEO of Anthropic, explained this during the launch of Claude Code:
Of course, you need an interface, you need a harness to use them
The model is the engine. The harness is the machine
Anthropic CEO Dario Amodei 在 Claude Code 发布时解释过这一点:
当然,你需要一个界面,需要一个 harness 才能用上这些模型。
模型是引擎,harness 才是机器。
Put Claude Sonnet 5.5 into an unmanaged chat window, and it achieves an 18% success rate on complex multi-file engineering tasks. Put that same model into an engineered harness with path boundaries, isolated git worktrees, sub-second linter sensors, and adversarial verification, and task completion reaches 95%
Below is the complete architectural blueprint for building production autonomous agents using Claude Code and the Anthropic 5.5 model stack across Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.5
把 Claude Sonnet 5.5 放进一个没有管理的聊天窗口,它处理复杂的跨文件工程任务成功率只有 18%。把同一个模型放进工程化 harness——有路径边界、隔离的 git worktree、亚秒级 linter 传感器和对抗式验证——任务完成率能到 95%。
下面是完整架构蓝图:用 Claude Code 和 Anthropic 5.5 模型栈(Opus 5.5、Sonnet 5.5、Haiku 5.5、Fable 5.5)构建生产级自主 agent。
-
Stage 1: Pre-Flight Task Contract Human intent compiles into a bounded task_contract.json via Claude Opus 5.5
-
Stage 2: Sandboxed Worktree Isolation Harness spawns an isolated git worktree before any tool executes
-
Stage 3: Autonomous Implementation Claude Sonnet 5.5 executes code modifications within strict path allowlists
-
Stage 4: Sub-Second Sensor Interception Claude Haiku 5.5 validates every bash tool call and parameter in real time
-
Stage 5: Adversarial Red-Teaming Claude Fable 5.5 attacks the diff, searching race conditions and edge cases
-
Stage 6: Deterministic Evidence Gate Physical pre-commit hook verifies test output and signs receipt.json
-
Stage 7: Compounding Memory Flywheel Failures crystallize into permanent rules, skills, and regression evals on disk
-
阶段 1:预检任务契约 人类意图由 Claude Opus 5.5 编译成有边界的
task_contract.json -
阶段 2:沙箱 worktree 隔离 任何工具执行前,harness 先创建一个隔离的 git worktree
-
阶段 3:自主实现 Claude Sonnet 5.5 在严格的路径 allowlist 内执行代码修改
-
阶段 4:亚秒级传感器拦截 Claude Haiku 5.5 实时校验每一次 bash 工具调用及其参数
-
阶段 5:对抗式红队 Claude Fable 5.5 攻击 diff,搜寻竞态条件和边界情况
-
阶段 6:确定性证据闸门 物理 pre-commit hook 验证测试输出,并签发
receipt.json -
阶段 7:复利记忆飞轮 失败沉淀为永久规则、skill 和回归 eval,写入磁盘
Observing the same model across two operating environments explains why autonomous agents break down:
System Breakdown: Raw Chat Window vs. Engineered Harness
Execution Surface
-
Raw Chat: Flat string buffer with interleaved chat history
-
Engineered Harness: Sandboxed git worktree filesystem plus state ledger files Task Boundaries
-
Raw Chat: Open-ended conversational prompt (e.g. Refactor auth)
-
Engineered Harness: Machine-readable JSON contract with strict path allowlists Tool Execution
-
Raw Chat: Unchecked tool calls where the model self-approves syntax
-
Engineered Harness: Pre-tool hooks and static typecheckers intercepting all inputs State Persistence
-
Raw Chat: Transient context window that dies when the session terminates
-
Engineered Harness: Durable append-only ledger persisted directly to disk Verification Logic
-
Raw Chat: Model validates itself and claims the code works
-
Engineered Harness: Decoupled skeptic agent (Claude Fable 5.5) proving test logs Failure Recovery
-
Raw Chat: Human reprompts while the model invents new excuses
-
Engineered Harness: Automatic rollback to clean checkpoint hash, recording failure to evals End-to-End Success Rate
-
Raw Chat: 18% completion on complex multi-turn workflows
-
Engineered Harness: 95% deterministic task convergence
同一个模型放在两种运行环境里,就能解释自主 agent 为什么崩溃:
系统拆解:裸聊天窗口 vs. 工程化 harness
执行面
-
裸聊天:扁平字符串缓冲区,聊天历史交错堆叠
-
工程化 harness:沙箱 git worktree 文件系统,加上状态账本文件 任务边界
-
裸聊天:开放式对话 prompt(比如“重构认证”)
-
工程化 harness:机器可读 JSON 契约,带严格路径 allowlist 工具执行
-
裸聊天:工具调用不受检查,模型自己批准语法
-
工程化 harness:pre-tool hook 和静态类型检查器拦截所有输入 状态持久化
-
裸聊天:临时上下文窗口,会话结束就死
-
工程化 harness:持久化 append-only 账本,直接落盘 验证逻辑
-
裸聊天:模型自证,声称代码能跑
-
工程化 harness:解耦的怀疑者 agent(Claude Fable 5.5)拿测试日志证明 失败恢复
-
裸聊天:人类重新 prompt,模型编新借口
-
工程化 harness:自动回滚到干净 checkpoint hash,并把失败记入 evals 端到端成功率
-
裸聊天:复杂多轮工作流 18% 完成率
-
工程化 harness:95% 确定性任务收敛
When an agent runs in a chat window, context pollution compounds with every turn. By turn 8, earlier instructions drown under thousands of tokens of raw tool output. The model begins guessing parameter names and enters repetitive error loops
The harness converts conversation into stateful software infrastructure
agent 在聊天窗口里跑,上下文污染会随着每一轮不断累积。到第 8 轮,早先的指令已经被成千上万 token 的原始工具输出淹没。模型开始猜参数名,陷入重复报错循环。
harness 把对话变成有状态的软件基础设施。
Building production agents on a single model fails economically. Running Opus 5.5 for file linting burns budget at $15 per million tokens. Running Haiku 5.5 for system decomposition breaks the architecture
A production harness uses role specialization:
The Claude 5.5 Harness Role Division
Claude Opus 5.5 (Lead Architect and Arbiter)
-
Assignment: Generates task contracts, reviews architectural invariants, settles merge conflicts
-
Economics: High reasoning depth at $15.00 per million tokens Claude Sonnet 5.5 (Autonomous Engineer)
-
Assignment: Writes production code, modifies modules, executes bash tool calls
-
Economics: Fast agentic coding at $3.00 per million tokens Claude Haiku 5.5 (Sub-Second Gatekeeper)
-
Assignment: Validates tool parameters, enforces path bounds, runs linters
-
Economics: Millisecond response latency at $0.25 per million tokens Claude Fable 5.5 (Adversarial Skeptic)
-
Assignment: Attacks code diffs, fuzzes boundary cases, searches race conditions
-
Economics: Hostile security red-teaming at $2.50 per million tokens

只靠一个模型构建生产级 agent,经济上一定失败。用 Opus 5.5 跑文件 lint,每百万 token $15 的预算直接烧穿。用 Haiku 5.5 做系统拆解,架构直接崩。
生产级 harness 用的是角色专精:
Claude 5.5 harness 角色分工
Claude Opus 5.5(首席架构师与仲裁者)
-
任务:生成任务契约、审查架构不变量、裁决合并冲突
-
经济性:强推理深度,每百万 token $15.00 Claude Sonnet 5.5(自主工程师)
-
任务:写生产代码、改模块、执行 bash 工具调用
-
经济性:快速 agentic 编码,每百万 token $3.00 Claude Haiku 5.5(亚秒级守门员)
-
任务:校验工具参数、强制路径边界、跑 linter
-
经济性:毫秒级响应,每百万 token $0.25 Claude Fable 5.5(对抗式怀疑者)
-
任务:攻击代码 diff、模糊测试边界情况、搜寻竞态条件
-
经济性:敌对式安全红队,每百万 token $2.50

An autonomous agent must not write code from conversational instructions. Before Claude Sonnet 5.5 generates token 1, Claude Opus 5.5 compiles a machine-readable task_contract.json
The contract defines four boundaries:
-
Path Boundary (filesystem_boundary): Explicit list of files the agent can read and edit. Any attempt to touch .env or root package files triggers an immediate interrupt
-
Economic Envelope (budget): Hard limits on dollar spend, conversation turns, and wall-clock execution seconds
-
Acceptance Invariants (acceptance_criteria): Deterministic shell commands that must exit with code 0
-
Required Artifacts (required_evidence): Verification files that must exist on disk before the task closes
{
"$schema": "https://anthropic.com/schemas/agent-contract-v1.json",
"task_id": "refactor-session-auth-842",
"created_at": "2026-11-04T19:30:00Z",
"architect_model": "claude-opus-5-5",
"worker_model": "claude-sonnet-5-5",
"budget": {
"max_cost_usd": 4.50,
"max_turns": 20,
"timeout_seconds": 600
},
"filesystem_boundary": {
"allowed_read": [
"src/auth/",
"src/types/auth.ts",
"tests/auth/",
"package.json"
],
"allowed_write": [
"src/auth/jwt.ts",
"src/auth/session_manager.ts",
"tests/auth/jwt.test.ts"
],
"forbidden_write": [
".env",
"src/database/",
"infra/",
"package.json"
]
},
"acceptance_criteria": [
{
"type": "command",
"exec": "npm run test:auth",
"expected_exit_code": 0
},
{
"type": "command",
"exec": "npx tsc --noEmit",
"expected_exit_code": 0
},
{
"type": "evidence",
"artifact_path": ".claude/receipts/receipt-refactor-session-auth-842.json"
}
]
}
自主 agent 不能靠对话指令直接写代码。Claude Sonnet 5.5 生成第 1 个 token 之前,Claude Opus 5.5 先把它编译成机器可读的 task_contract.json。
契约划出四个边界:
-
路径边界(filesystem_boundary):明确列出 agent 可读、可改的文件。任何试图碰 .env 或根目录 package 文件的操作都会立刻中断
-
经济包络(budget):对美元花费、对话轮数和实际执行秒数设硬上限
-
验收不变量(acceptance_criteria):必须以退出码 0 结束的确定性 shell 命令
-
必需产物(required_evidence):任务关闭前必须存在于磁盘上的验证文件
{
"$schema": "https://anthropic.com/schemas/agent-contract-v1.json",
"task_id": "refactor-session-auth-842",
"created_at": "2026-11-04T19:30:00Z",
"architect_model": "claude-opus-5-5",
"worker_model": "claude-sonnet-5-5",
"budget": {
"max_cost_usd": 4.50,
"max_turns": 20,
"timeout_seconds": 600
},
"filesystem_boundary": {
"allowed_read": [
"src/auth/",
"src/types/auth.ts",
"tests/auth/",
"package.json"
],
"allowed_write": [
"src/auth/jwt.ts",
"src/auth/session_manager.ts",
"tests/auth/jwt.test.ts"
],
"forbidden_write": [
".env",
"src/database/",
"infra/",
"package.json"
]
},
"acceptance_criteria": [
{
"type": "command",
"exec": "npm run test:auth",
"expected_exit_code": 0
},
{
"type": "command",
"exec": "npx tsc --noEmit",
"expected_exit_code": 0
},
{
"type": "evidence",
"artifact_path": ".claude/receipts/receipt-refactor-session-auth-842.json"
}
]
}
System Prompt: Opus 5.5 Contract Architect
You are the Lead System Architect operating inside Claude Code
Your sole job is to translate human feature requests and bug reports into a deterministic, bounded task contract
You do not write application code. You do not make assumptions
You analyze the repository structure and emit a valid JSON object matching the task_contract schema
Rules:
1. Never grant write access to root config files, environment secrets, or package manager lockfiles unless explicitly mandated
2. Define unambiguous, deterministic shell commands as acceptance criteria (e.g. npm test, pytest tests/unit/)
3. Estimate the economic envelope: assign strict limits for cost ($USD), conversation turns, and execution seconds
4. Restrict the write boundary to the minimum viable module
Output valid JSON only
系统提示词:Opus 5.5 契约架构师
You are the Lead System Architect operating inside Claude Code
Your sole job is to translate human feature requests and bug reports into a deterministic, bounded task contract
You do not write application code. You do not make assumptions
You analyze the repository structure and emit a valid JSON object matching the task_contract schema
Rules:
1. Never grant write access to root config files, environment secrets, or package manager lockfiles unless explicitly mandated
2. Define unambiguous, deterministic shell commands as acceptance criteria (e.g. npm test, pytest tests/unit/)
3. Estimate the economic envelope: assign strict limits for cost ($USD), conversation turns, and execution seconds
4. Restrict the write boundary to the minimum viable module
Output valid JSON only
Dumping 150,000 tokens of repository text into Claude Code triggers three failures:
-
Context Smearing: Attention over critical invariants degrades
-
Economic Waste: Every turn pays the full input token tax
-
Branch Contamination: Editing the live working branch leaves half-finished code that halts other engineers
Production harnesses use Topological Context and Worktree Isolation
把 150,000 token 的仓库文本一股脑塞进 Claude Code,会触发三种失败:
-
上下文涂抹:模型对关键不变量的注意力被稀释
-
经济浪费:每一轮都要为完整输入 token 交税
-
分支污染:直接改活跃工作分支,留下半成品代码,把其他工程师堵死
生产级 harness 用的是拓扑上下文(Topological Context)和 worktree 隔离。
1. The Root Map: Production CLAUDE.md
CLAUDE.md functions as an index map that directs attention to specific documentation nodes on demand:
Architecture Invariants
- Runtime: Node.js v22.x LTS, TypeScript v5.7
- Framework: Fastify (Strict schema-first routing)
- Storage: PostgreSQL via Prisma ORM, Redis for token revocation
Topological Directory Map
- src/auth/: JWT issuance, refresh rotation, cryptographic signatures
- src/middleware/: Fastify request lifecycle hooks and rate limiters
- tests/fixtures/: Synthetic database seeds and test tokens
- .claude/state/: Durable agent session ledgers and change receipts
Operational Rules
1. Never execute raw SQL queries; use Prisma client methods
2. Never commit code directly to main or develop
3. All code modifications must execute within .agent_worktrees/
4. Run npm run lint and npm run test before declaring task completion
1. 根地图:生产级 CLAUDE.md
CLAUDE.md 是一张索引地图,按需把注意力引向具体的文档节点:
Architecture Invariants
- Runtime: Node.js v22.x LTS, TypeScript v5.7
- Framework: Fastify (Strict schema-first routing)
- Storage: PostgreSQL via Prisma ORM, Redis for token revocation
Topological Directory Map
- src/auth/: JWT issuance, refresh rotation, cryptographic signatures
- src/middleware/: Fastify request lifecycle hooks and rate limiters
- tests/fixtures/: Synthetic database seeds and test tokens
- .claude/state/: Durable agent session ledgers and change receipts
Operational Rules
1. Never execute raw SQL queries; use Prisma client methods
2. Never commit code directly to main or develop
3. All code modifications must execute within .agent_worktrees/
4. Run npm run lint and npm run test before declaring task completion
2. Physical Isolation: isolate_worktree.sh
Instead of modifying the main working tree, the harness clones the repository into an isolated sandbox:
set -euo pipefail
TASK_ID="${1:-task-$(date +%s)}"
BASE_BRANCH="${2:-main}"
WORKTREE_PATH=".agent_worktrees/${TASK_ID}"
echo "[HARNESS] Initializing isolated git worktree for: ${TASK_ID}"
mkdir -p .agent_worktrees
git worktree add -b "agent/${TASK_ID}" "${WORKTREE_PATH}" "${BASE_BRANCH}"
if [ -f .env.example ]; then
cp .env.example "${WORKTREE_PATH}/.env"
fi
echo "[HARNESS] Isolated worktree ready at ${WORKTREE_PATH}"
echo "[HARNESS] Launching Claude Code in sandboxed boundary..."
cd "${WORKTREE_PATH}"
claude --dangerously-skip-permissions false
2. 物理隔离:isolate_worktree.sh
harness 不直接改主工作树,而是把仓库克隆到隔离沙箱里:
set -euo pipefail
TASK_ID="${1:-task-$(date +%s)}"
BASE_BRANCH="${2:-main}"
WORKTREE_PATH=".agent_worktrees/${TASK_ID}"
echo "[HARNESS] Initializing isolated git worktree for: ${TASK_ID}"
mkdir -p .agent_worktrees
git worktree add -b "agent/${TASK_ID}" "${WORKTREE_PATH}" "${BASE_BRANCH}"
if [ -f .env.example ]; then
cp .env.example "${WORKTREE_PATH}/.env"
fi
echo "[HARNESS] Isolated worktree ready at ${WORKTREE_PATH}"
echo "[HARNESS] Launching Claude Code in sandboxed boundary..."
cd "${WORKTREE_PATH}"
claude --dangerously-skip-permissions false
Most agent failures stem from mixing reasoning, execution, and memory inside one chat thread
A production harness separates the system into three distinct planes:
-
Brain Plane (Neural Weights): Claude Opus 5.5 for architecture, Claude Sonnet 5.5 for code implementation
-
Hands Plane (Execution Environment): Containerized bash, language runtimes, pre-tool interceptors
-
History Plane (Durable Substrate): Git worktrees, state files on disk, and decision_ledger.jsonl

Directory Architecture for Claude Code Production Harness:
my-project/
CLAUDE.md
.agent_worktrees/
.claude/
config.json
contracts/
task-auth-842.json
hooks/
pre-tool.sh
post-tool.sh
receipts/
receipt-auth-842.json
skills/
audit-diff.sh
state/
decision_ledger.jsonl
多数 agent 失败,是因为把推理、执行和记忆混在同一个聊天线程里。
生产级 harness 把系统拆成三个平面:
-
大脑平面(神经权重):Claude Opus 5.5 负责架构,Claude Sonnet 5.5 负责代码实现
-
手部平面(执行环境):容器化 bash、语言运行时、pre-tool 拦截器
-
历史平面(持久底座):git worktree、磁盘状态文件,以及 decision_ledger.jsonl

Claude Code 生产级 harness 的目录架构:
my-project/
CLAUDE.md
.agent_worktrees/
.claude/
config.json
contracts/
task-auth-842.json
hooks/
pre-tool.sh
post-tool.sh
receipts/
receipt-auth-842.json
skills/
audit-diff.sh
state/
decision_ledger.jsonl
A model must not evaluate its own code. If Claude Sonnet 5.5 writes an authentication module, its self-review overlooks its own assumptions. It claims: The implementation handles all race conditions and passed tests
Production systems separate generation from verification:
-
Claude Sonnet 5.5 builds the code
-
Claude Fable 5.5 acts as an Adversarial Skeptic with instructions to challenge the pull request
-
Claude Haiku 5.5 executes as a physical gatekeeper hook that intercepts shell commands before execution

模型不能评估自己写的代码。如果 Claude Sonnet 5.5 写了一个认证模块,它的自审会漏掉自己的假设,然后声称:实现处理了所有竞态条件,测试也通过了。
生产系统把生成和验证分开:
-
Claude Sonnet 5.5 写代码
-
Claude Fable 5.5 扮演对抗式怀疑者,任务是挑战这个 pull request
-
Claude Haiku 5.5 作为物理守门 hook,在执行前拦截 shell 命令

System Prompt: Fable 5.5 Adversarial Skeptic
You are the Lead Security Skeptic and Red Teamer in this repository
Claude Sonnet 5.5 has proposed a code modification. Your goal is to DISPROVE its correctness
You are not here to write praise
Your mission is to find reasons why this code will crash in production under scale, concurrency, or malicious input
Audit Checklist:
1. Concurrency: What happens if two requests arrive with identical payloads at the same millisecond?
2. Boundary Conditions: What happens with null, empty arrays, MAX_INT, or malformed UTF-8 inputs?
3. State Invariants: Does this commit mutate database state without a surrounding transactional rollback boundary?
4. Path Leaks: Did the worker touch or read any file outside its contract allowlist?
If you find a flaw, output:
STATUS: REJECTED
REASON: <Detailed vulnerability reproduction trace>
If you cannot break the implementation after hostile scrutiny, output:
STATUS: APPROVED
EVIDENCE: <Test command outputs and invariant proof>
系统提示词:Fable 5.5 对抗式怀疑者
You are the Lead Security Skeptic and Red Teamer in this repository
Claude Sonnet 5.5 has proposed a code modification. Your goal is to DISPROVE its correctness
You are not here to write praise
Your mission is to find reasons why this code will crash in production under scale, concurrency, or malicious input
Audit Checklist:
1. Concurrency: What happens if two requests arrive with identical payloads at the same millisecond?
2. Boundary Conditions: What happens with null, empty arrays, MAX_INT, or malformed UTF-8 inputs?
3. State Invariants: Does this commit mutate database state without a surrounding transactional rollback boundary?
4. Path Leaks: Did the worker touch or read any file outside its contract allowlist?
If you find a flaw, output:
STATUS: REJECTED
REASON: <Detailed vulnerability reproduction trace>
If you cannot break the implementation after hostile scrutiny, output:
STATUS: APPROVED
EVIDENCE: <Test command outputs and invariant proof>
Hook Script: .claude/hooks/pre-tool.sh
set -euo pipefail
TOOL_NAME="$1"
TOOL_INPUT_JSON="$2"
if [ "${TOOL_NAME}" = "Bash" ]; then
COMMAND=$(echo "${TOOL_INPUT_JSON}" | jq -r '.command // empty')
if [[ "${COMMAND}" =~ "git commit" ]] || [[ "${COMMAND}" =~ "git push" ]]; then
echo "[SECURITY GATE] Git commit detected. Verifying change receipt..."
RECEIPT_FILE=$(find .claude/receipts -type f 2>/dev/null | grep "receipt-" | head -n 1 || true)
if [ -z "${RECEIPT_FILE}" ]; then
echo "[SECURITY ERROR] No change receipt found in .claude/receipts/"
echo "[SECURITY ERROR] Action aborted. Run verification before committing"
exit 1
fi
VERDICT=$(jq -r '.verifier_verdict.status // empty' "${RECEIPT_FILE}")
if [ "${VERDICT}" != "APPROVED" ]; then
echo "[SECURITY ERROR] Receipt verdict is '${VERDICT}', not 'APPROVED'"
echo "[SECURITY ERROR] Commit blocked by Adversarial Skeptic Gate"
exit 1
fi
echo "[SECURITY GATE] Verified receipt: ${RECEIPT_FILE}. Authorization granted"
fi
fi
exit 0
Hook 脚本:.claude/hooks/pre-tool.sh
set -euo pipefail
TOOL_NAME="$1"
TOOL_INPUT_JSON="$2"
if [ "${TOOL_NAME}" = "Bash" ]; then
COMMAND=$(echo "${TOOL_INPUT_JSON}" | jq -r '.command // empty')
if [[ "${COMMAND}" =~ "git commit" ]] || [[ "${COMMAND}" =~ "git push" ]]; then
echo "[SECURITY GATE] Git commit detected. Verifying change receipt..."
RECEIPT_FILE=$(find .claude/receipts -type f 2>/dev/null | grep "receipt-" | head -n 1 || true)
if [ -z "${RECEIPT_FILE}" ]; then
echo "[SECURITY ERROR] No change receipt found in .claude/receipts/"
echo "[SECURITY ERROR] Action aborted. Run verification before committing"
exit 1
fi
VERDICT=$(jq -r '.verifier_verdict.status // empty' "${RECEIPT_FILE}")
if [ "${VERDICT}" != "APPROVED" ]; then
echo "[SECURITY ERROR] Receipt verdict is '${VERDICT}', not 'APPROVED'"
echo "[SECURITY ERROR] Commit blocked by Adversarial Skeptic Gate"
exit 1
fi
echo "[SECURITY GATE] Verified receipt: ${RECEIPT_FILE}. Authorization granted"
fi
fi
exit 0
In physical manufacturing, technicians do not install an aircraft component without an inspection certificate. Autonomous software engineering requires the same rule: No Receipt, No Commit
Every task writes a signed receipt-{task_id}.json to disk before the harness permits merging into the base branch
Change Receipt: receipt-refactor-session-auth-842.json
{
"receipt_id": "rcpt-20261104-99124",
"task_id": "refactor-session-auth-842",
"timestamp": "2026-11-04T19:38:12Z",
"worker_model": "claude-sonnet-5-5",
"verifier_model": "claude-fable-5-5",
"git_worktree": ".agent_worktrees/refactor-session-auth-842",
"head_commit_hash": "e7b8c4d21f890a3b",
"diff_summary": {
"files_changed": 2,
"insertions": 54,
"deletions": 11,
"modified_files": [
"src/auth/jwt.ts",
"src/auth/session_manager.ts"
]
},
"deterministic_evidence": {
"test_command": "npm run test:auth",
"exit_code": 0,
"tests_passed": 18,
"tests_failed": 0,
"typecheck_command": "npx tsc --noEmit",
"typecheck_exit_code": 0
},
"verifier_verdict": {
"status": "APPROVED",
"fuzzed_scenarios": [
"expired_refresh_token_replay",
"empty_bearer_header_injection",
"concurrent_session_revocation"
],
"cryptographic_signature": "sha256:4f89d3bc281e09"
}
}
在制造业,技师不会在没有检验证书的情况下装上飞机零件。自主软件工程也需要同一条规则:没有回执,不许提交。
每个任务都要在 harness 允许合并进基础分支之前,把签名的 receipt-{task_id}.json 写到磁盘上。
变更回执:receipt-refactor-session-auth-842.json
{
"receipt_id": "rcpt-20261104-99124",
"task_id": "refactor-session-auth-842",
"timestamp": "2026-11-04T19:38:12Z",
"worker_model": "claude-sonnet-5-5",
"verifier_model": "claude-fable-5-5",
"git_worktree": ".agent_worktrees/refactor-session-auth-842",
"head_commit_hash": "e7b8c4d21f890a3b",
"diff_summary": {
"files_changed": 2,
"insertions": 54,
"deletions": 11,
"modified_files": [
"src/auth/jwt.ts",
"src/auth/session_manager.ts"
]
},
"deterministic_evidence": {
"test_command": "npm run test:auth",
"exit_code": 0,
"tests_passed": 18,
"tests_failed": 0,
"typecheck_command": "npx tsc --noEmit",
"typecheck_exit_code": 0
},
"verifier_verdict": {
"status": "APPROVED",
"fuzzed_scenarios": [
"expired_refresh_token_replay",
"empty_bearer_header_injection",
"concurrent_session_revocation"
],
"cryptographic_signature": "sha256:4f89d3bc281e09"
}
}
The largest financial leak in agent development is transient debugging
A developer spends an hour correcting an agent. They point out an unexported type, an unhandled database transaction, or a violated schema. The agent fixes it, the session closes, and the terminal terminates
The next morning, the model starts from scratch. The team pays for the same intelligence, makes the same manual corrections, and burns the same token budget
A production harness converts failures into permanent software assets through four crystallization stages:
-
Runtime Incident: The agent fails a test or violates an invariant
-
Invariant Rule Extraction: Opus 5.5 synthesizes the negative constraint into .claude/rules/database_invariants.md
-
Executable Skill Synthesis: The procedural fix compiles into a bash tool in .claude/skills/verify-schema.sh
-
Regression Eval Hardening: The failing case joins the evals/ test suite to prevent regressions

agent 开发中最大的资金漏洞,是转瞬即逝的调试。
开发者花一小时纠正 agent,指出一个未导出的类型、一个没处理的数据库事务,或者一个被违反的 schema。agent 改好了,会话关闭,终端结束。
第二天早上,模型从零开始。团队为同样的智能再付一次钱,做同样的手工纠正,烧掉同样的 token 预算。
生产级 harness 通过四个结晶阶段,把失败变成永久软件资产:
-
运行时事故:agent 测试失败或违反不变量
-
不变量规则提取:Opus 5.5 把负向约束综合进 .claude/rules/database_invariants.md
-
可执行 skill 合成:修复流程编译成 .claude/skills/verify-schema.sh 里的 bash 工具
-
回归 eval 加固:失败用例加入 evals/ 测试套件,防止回归

Skill Script: .claude/skills/audit-diff.sh
set -euo pipefail
CONTRACT_FILE="${1:-.claude/contracts/active_contract.json}"
if [ ! -f "${CONTRACT_FILE}" ]; then
echo "[SKILL ERROR] Active contract file not found: ${CONTRACT_FILE}"
exit 1
fi
echo "[SKILL] Auditing modified files against contract path allowlist..."
ALLOWED_FILES=$(jq -r '.filesystem_boundary.allowed_write[]' "${CONTRACT_FILE}")
MODIFIED_FILES=$(git diff --name-only origin/main)
for file in ${MODIFIED_FILES}; do
MATCH=false
for pattern in ${ALLOWED_FILES}; do
if [[ "${file}" == ${pattern} ]]; then
MATCH=true
break
fi
done
if [ "${MATCH}" = false ]; then
echo "[SECURITY VIOLATION] File '${file}' is not in the contract write allowlist"
exit 1
fi
done
echo "[SKILL] Path boundaries validated successfully"
echo "[SKILL] Executing static type check..."
npx tsc --noEmit
echo "[SKILL] All checks passed. Diff is safe for adversarial review"
Skill 脚本:.claude/skills/audit-diff.sh
set -euo pipefail
CONTRACT_FILE="${1:-.claude/contracts/active_contract.json}"
if [ ! -f "${CONTRACT_FILE}" ]; then
echo "[SKILL ERROR] Active contract file not found: ${CONTRACT_FILE}"
exit 1
fi
echo "[SKILL] Auditing modified files against contract path allowlist..."
ALLOWED_FILES=$(jq -r '.filesystem_boundary.allowed_write[]' "${CONTRACT_FILE}")
MODIFIED_FILES=$(git diff --name-only origin/main)
for file in ${MODIFIED_FILES}; do
MATCH=false
for pattern in ${ALLOWED_FILES}; do
if [[ "${file}" == ${pattern} ]]; then
MATCH=true
break
fi
done
if [ "${MATCH}" = false ]; then
echo "[SECURITY VIOLATION] File '${file}' is not in the contract write allowlist"
exit 1
fi
done
echo "[SKILL] Path boundaries validated successfully"
echo "[SKILL] Executing static type check..."
npx tsc --noEmit
echo "[SKILL] All checks passed. Diff is safe for adversarial review"
Audit the workspace against this 10-point checklist before launching Claude Code on tasks longer than 15 minutes:
-
Path Allowlist Enforced: filesystem_boundary is defined with explicit allowlists in task_contract.json
-
Worktree Physical Isolation: The agent operates inside .agent_worktrees/ rather than the active branch
-
Top-Level Context Map: CLAUDE.md stays under 150 lines and serves as an index rather than an encyclopedia
-
Model Role Specialization: Roles divide across Opus 5.5 (Contract), Sonnet 5.5 (Worker), Haiku 5.5 (Linter), and Fable 5.5 (Skeptic)
-
Physical Tool Gatekeeper: .claude/hooks/pre-tool.sh intercepts git commit to enforce receipt verification
-
Decoupled Verification: Self-approval is disabled; verification requires an adversarial audit from Fable 5.5
-
Deterministic Acceptance Tests: The contract requires shell commands (npm test, pytest) to exit with code 0
-
Durable State on Disk: Session memory writes to .claude/state/decision_ledger.jsonl rather than the chat buffer
-
Change Receipt Generated: The completed task outputs a structured receipt-{task_id}.json containing diff stats and test logs
-
Financial Circuit Breaker: An economic envelope (budget.max_cost_usd) halts runaway loops automatically
在 Claude Code 上启动超过 15 分钟的任务之前,用这份 10 项清单审计工作区:
-
路径 allowlist 已强制:task_contract.json 里的 filesystem_boundary 定义了明确的 allowlist
-
worktree 物理隔离:agent 在 .agent_worktrees/ 里运行,而不是在活跃分支上
-
顶层上下文地图:CLAUDE.md 控制在 150 行以内,是索引,不是百科全书
-
模型角色专精:角色分给 Opus 5.5(契约)、Sonnet 5.5(工人)、Haiku 5.5(Linter)、Fable 5.5(怀疑者)
-
物理工具守门员:.claude/hooks/pre-tool.sh 拦截 git commit,强制校验回执
-
解耦验证:关闭自我批准;验证必须由 Fable 5.5 做对抗式审计
-
确定性验收测试:契约要求 shell 命令(npm test、pytest)以退出码 0 结束
-
磁盘持久状态:会话记忆写入 .claude/state/decision_ledger.jsonl,而不是聊天缓冲区
-
生成变更回执:完成任务输出结构化的 receipt-{task_id}.json,包含 diff 统计和测试日志
-
财务熔断器:经济包络(budget.max_cost_usd)自动叫停失控循环
Prompt engineering treated frontier models like magic chat boxes that required the right combination of words
Harness Engineering is the industrial phase of autonomous software
Claude Opus, Sonnet, Haiku, and Fable 5.5 are stochastic reasoning engines. They do not need more adjectives in their prompts. They need deterministic boundaries, isolated filesystems, adversarial verifiers, and physical circuit breakers
Investing in the harness turns model execution from a roulette wheel into predictable, composable, production-grade software infrastructure
bookmark this and share it with your engineering team before deploying your next autonomous agent cluster ↓
additional alpha - https://t.me/+-e0O9zoaMvQ1NjAy
~marfin
Prompt engineering 曾把前沿模型当成魔法聊天框,以为只要词组合对了就行。
Harness Engineering 是自主软件的工业化阶段。
Claude Opus、Sonnet、Haiku 和 Fable 5.5 是随机推理引擎。它们不需要 prompt 里堆更多形容词。它们需要确定性边界、隔离文件系统、对抗式验证器和物理熔断器。
投资 harness,就是把模型执行从轮盘赌变成可预测、可组合、生产级软件基础设施。
收藏这篇,在部署下一批自主 agent 集群之前转给你的工程团队 ↓
额外 alpha - https://t.me/+-e0O9zoaMvQ1NjAy
~marfin