Harness Engineering: The Emerging Playbook for Building AI Agents
Harness engineering is the discipline of building execution environments that make AI agents reliable: five principles, the ratchet rule, and what to measure.
Table of Contents
Your agent fixes the bug, then a week later reintroduces the same one in a different file. You tighten the prompt. It behaves for a day, then drifts again. Each prompt tweak is a patch that fades. The durable fix changes the system so that specific mistake becomes structurally hard to repeat, and that practice now has a name.
That name is harness engineering, and it has become the way serious teams build agents in 2026. This guide covers what the discipline is, who named it, its five-principle playbook, the ratchet rule at its center, and how to measure whether your harness is actually working.
What Harness Engineering Is (and What It Replaced)
Harness engineering is the practice of designing the full execution environment around an agent: the rules, constraints, feedback loops, and verification gates that govern its behavior across an entire task. It sits one level above the prompt and the context window.
The field arrived in three steps. Prompt engineering, roughly 2022 to 2024, tuned the wording of a single instruction. Context engineering, through 2025, managed what entered the model’s window for one decision. Harness engineering, in 2026, governs the whole run: which tools exist, when context resets, what state persists, and which checks must pass before work is accepted.
Each layer subsumes the one below it. A perfect prompt still fails on a task that spans hours, and a perfectly packed context window still fails when the task outlasts it. The harness is the layer that holds a long, messy job together, which is why attention moved there.

Who Established the Term and Why
Mitchell Hashimoto, the engineer behind Terraform and Ghostty, named the discipline in a February 2026 essay titled “My AI Adoption Journey.” He stated the core move plainly: “anytime you find an agent makes a mistake, you take the time to engineer a solution such that the agent never makes that mistake again.”
The scale proof came from OpenAI. Its Codex team reported building roughly one million lines of production code in about five months, starting with three engineers and growing to seven. The team merged around 1,500 pull requests with no hand-written code. InfoQ reported the headline figures, and OpenAI’s own account supplied the finer numbers.
Together the two sources gave the practice both a name and a proof point. One engineer articulated the principle; a well-known lab showed it holding up across a codebase most teams would consider unmanageable for an agent.
The timing explains the traction. By early 2026, enough teams had hit the same wall, agents that shine in a demo and stall on real multi-hour work, that a shared name for the fix spread fast. Naming the practice turned a set of scattered habits into something teams could point at, argue about, and put on a checklist.
Harness Engineering vs Context Engineering: Where One Ends and the Other Begins
Context engineering manages what enters the window for a single decision. Harness engineering operates outside that window. It decides when to reset context, what state to persist externally, which verification runs, and how a failure turns into a permanent rule. This is the crux of harness engineering vs context engineering.
| Layer | Time scope | What it controls | Core artifact | Insufficient for |
|---|---|---|---|---|
| Prompt engineering | Single interaction | Instruction wording | System prompt | Multi-step tasks |
| Context engineering | One context window | Token selection and ordering | RAG pipeline, memory retrieval | Tasks that exceed a reliable window |
| Harness engineering | Full task lifetime | Tool orchestration, state, verification, gates | AGENTS.md, CI pipeline, linters | Highest scope |
Augment Code draws the same three-scope split. Prompt engineering optimizes one interaction, context engineering curates information across turns inside a single window, and harness engineering governs everything around both. The line is not academic, because it tells you where to spend your effort when an agent stalls on a long task.
A concrete case makes the split obvious. Suppose an agent is halfway through a refactor and its window fills up. Context engineering asks which files and summaries to keep in the next prompt. Harness engineering asks a different set of questions: should the run reset now, what state gets written to disk first, and which test must pass before the work counts as done. One curates a window, the other governs the run around it.
The Core Playbook: Five Principles
The OpenAI Codex account and the writers who unpacked it converge on five repeatable principles. Treat the repository as the source of truth, enforce constraints with linters instead of prompts, ratchet every failure into a structural rule, grant autonomy in stages, and read failures as harness gaps instead of model gaps.
Repository as the Source of Truth
An AGENTS.md file and the repository’s own structure tell the agent how the project works. Guidance lives in version control, where every run reads the same current rules, not in a chat message that disappears when the session ends. When the file says the project uses one test runner and one import style, every future run inherits that decision without a human repeating it.
Constraints via Linters, Not Prompts
A linter or type checker blocks a bad pattern every single time. A sentence in the prompt only asks the model nicely and hopes. Machine-enforced rules hold under pressure, so the durable constraints belong in tooling. Telling the model to avoid a deprecated API is a request it may forget by the next turn; a lint rule that fails the build on that API is a wall it cannot walk through.
The Ratchet: Convert Every Failure Into a Structural Rule
Addy Osmani frames the harness as a ratchet: it only tightens, never loosens. Each recurring failure earns a new guard, and constraints accumulate only after a real mistake, never on speculation. This is the heart of agent harness engineering, and it compounds over time. The first time an agent forgets a null check, you add a guard; the tenth agent to touch that code inherits the guard for free, so that class of bug closes for good.
Incremental Autonomy and Staged Gates
Give the agent more freedom as it earns trust, with gates between stages. A small error caught at an early gate cannot cascade into a large one that reaches production, so autonomy grows without raising blast radius. A new agent might start allowed only to open a draft pull request, then earn the right to run the full test suite, and later be trusted to merge behind a green build, each step gated by the one before it.
Harness Failures, Not Model Failures
When output is wrong, the first question is what the harness allowed, not why the model erred. The model is fixed for now, and the harness is the part you can actually change, so that is where the fix goes. The reframing pays off because a fix shipped to the harness holds for every future run, while a better model helps only whenever it happens to arrive.

The Three Operating Layers
Augment Code groups harness mechanisms into three layers by when they act. Constraint harnesses act before the agent moves, feedback loops correct it mid-task, and quality gates enforce a standard at the end. Most reliable systems run all three.
Constraint harnesses are feedforward: rules files, linters, and type systems that make a whole class of mistakes impossible to express. Feedback loops are corrective: structured error signals, such as a failing test or a compiler message, fed straight back so the agent can fix its own work. Quality gates are enforcement: CI barriers that block a merge until the change clears every check.
A concrete run touches all three. A type system stops an invalid call before it happens, a failing unit test tells the agent exactly what broke, and a CI gate refuses to merge until the suite is green. Feedforward, correction, enforcement.
The three layers cover different failure moments, which is why strong systems run all of them. A constraint alone cannot catch a logic error that is still valid code. A feedback loop alone cannot stop a bad change from merging. A gate alone gives no early signal while the agent works. Stacked together, they catch a mistake before it forms, during the work, and at the door.
Context Resets as a First-Class Technique
For tasks that outrun a single window, clearing the context and restarting from a structured handoff beats trying to compress everything. Anthropic’s engineering team documented this pattern in “Effective harnesses for long-running agents,” published in November 2025, and treated the reset as a feature instead of a failure.
The handoff rides on durable artifacts, not on the model’s memory. A JSON feature list carries a status for each item, a progress file records what is done and what remains, and descriptive git commits capture what actually shipped. A fresh context reads those artifacts and continues the work as if it had never stopped.
This inverts a common instinct. Instead of fighting to keep everything in one enormous window, a harness-engineered agent externalizes its state and resets deliberately, which keeps each stretch of work inside a window the model handles well.
How to Measure Whether Your Harness Is Working
Four metrics tell you whether the harness is doing its job. Task Resolution Rate, Code Churn Rate, Verification Tax, and Defect Escape Rate track reliability across a task. The number to distrust is lines of code accepted, which measures volume, not whether the work holds.
| Metric | Measures | Method | Pitfall to avoid |
|---|---|---|---|
| Task Resolution Rate | Correct completions | Share of tasks meeting acceptance criteria | Do not count partial completions |
| Code Churn Rate | Rework burden | Share of AI code discarded within two weeks | High churn points to the harness, not the model |
| Verification Tax | Audit overhead | Audit time over time-to-first-commit | Rises when feedback loops are weak |
| Defect Escape Rate | Gate safety | AI-authored defects reaching production | The lagging indicator of gate failure |
| Lines Accepted (anti) | Volume only | Lines of AI code merged | Measures output, not reliability |
Code Churn Rate is the most diagnostic of the set. When a large share of accepted code gets thrown out within two weeks, the model is rarely the culprit. The harness let weak work through, and the fix is a tighter gate or a sharper feedback signal, which is exactly what these metrics are meant to surface. Augment Code proposes this set for that reason.
The other three each point at a different weak spot. A low Task Resolution Rate says the agent is not finishing what it starts. A high Verification Tax says humans spend too long checking its work, usually because feedback signals are weak. A rising Defect Escape Rate says bad changes are slipping past the final gate. Read together, the four tell you which part of the harness to tighten next.
Observability-Driven Evolution: Where the Discipline Is Heading
The newest work automates the discipline itself. A 2026 paper, Agentic Harness Engineering, evolves harness components from observability data instead of tuning them by hand, treating the harness as something a system can improve on its own.
Across ten iterations on Terminal-Bench 2, the method raised pass@1 from 69.7% to 77.0%, passing the human-designed Codex-CLI harness at 71.9%. The full method is in the paper Agentic Harness Engineering. The signal for builders is that harness quality is now measurable and improvable, not a matter of taste.
Return to the bug that kept coming back. In a harness-engineered system, its second appearance meets a linter or a gate that the first appearance created, so it never reaches your review again. Every failure becomes a rule, and the system only tightens. For a running catalog of tools and patterns, the community maintains an awesome-harness-engineering list. To see the components these principles shape, read what an agent harness is and agent harness architecture, and when you are ready to build one, follow how to build a coding agent harness.
Frequently asked questions
What is harness engineering?
How is harness engineering different from prompt engineering?
What is harness engineering vs context engineering?
Who invented harness engineering?
What is the ratchet principle?
How do you measure harness quality?
An agent harness is the runtime layer around an LLM that manages tools, context, state, execution, and safety. Learn how it shapes reliability.
How agent harness architecture shapes performance across five dimensions, from context and tools to safety and the loop that often outweighs a model upgrade.
Agent harness vs framework: a framework supplies reusable abstractions, while a harness runs and controls the agent loop. Learn when you need each.