What Is Harness Engineering? A Practical Guide for AI Engineers (2026)
Harness engineering is the design of everything around an LLM that makes an agent reliable: context, tools, control flow, verification gates and feedback loops. Learn which parts of a harness the next model will absorb and how to build the parts that survive upgrades.
Table of Contents
- Harness Engineering, Defined in One Paragraph
- Where the Term Came From and Why It Took Off in 2026
- Why coding agents made the harness visible
- The Anatomy of an Agent Harness
- Context and Memory Management
- Tools, Hooks, and Skills
- Control Flow, Constraints, and Verification Gates
- Harness Engineering vs Context Engineering vs Prompt Engineering
- A Minimal Harness Example
- Will the Next Model Make Your Harness Obsolete?
- Designing Harnesses That Survive Model Upgrades
- Harness Engineering Best Practices
- How to Start Learning Harness Engineering
- Frequently Asked Questions
- Is harness engineering the same as building an agent framework like LangChain?
- Do I need to learn harness engineering if I already use Claude Code or Cursor?
- What is the difference between a harness and scaffolding?
- Is harness engineering only for coding agents?
- Are there books or courses on harness engineering?
Harness engineering is the design of everything around a large language model that makes an agent reliable. The model reasons. The harness handles everything else: context, tools, control flow, constraints, verification and recovery. This guide covers what a harness contains, how it differs from prompt and context engineering, and which parts of your harness the next model will make redundant.
Harness Engineering, Defined in One Paragraph
Harness engineering covers everything around the model:
- what goes into the context window
- which tools the model can call, and how
- the control flow that drives the loop
- the constraints that bound the agent
- the verification gates its output must pass
- the state it carries between steps
- the error handling and feedback loops that turn failures into corrections
The shortest version comes from the explainer Harness Engineering 101: the LLM is the brain, and the harness is the body. A brilliant brain with no hands, no eyes and no reflexes doesn't ship much code.
If you searched for what harness engineering is and found three different answers, that's expected. The term emerged in early 2026, and definitions still vary.
- MindStudio stresses context management, tool interfaces, control flow and error handling.
- NxCode calls it the discipline of designing environments, constraints and feedback loops that make AI coding agents reliable.
- Robert Matsuoka describes it as building the agents, hooks, skills, gates and workflow around a model.
Writing in July, Matsuoka put the term at about five months old and noted that half the people using it mean different things by it.
Where the Term Came From and Why It Took Off in 2026
The phrase gained traction in March 2026.
- An early post titled Harness Engineering: The Power of AI, Guided by Human framed it as what you need to produce production-grade AI-generated code.
- That post pointed to the metaphor hidden in the name. A harness doesn't make a horse stronger. It lets a human direct strength the horse already has.
- Other March pieces defined it as the structural layer around an agent: constraints, tools, verification gates and state.
Cobus Greyling gave the idea its most quoted framing. He called the harness the missing architectural layer that determines whether AI agents actually work in production. That points at a familiar pattern: a demo agent impresses, then the production agent falls apart. The model is usually the same in both cases. What changes is everything around it.
Why coding agents made the harness visible
Coding agents such as Anthropic's Claude Code, Cursor and Google's Antigravity made the harness hard to ignore.
- Same model, different results. These tools can run on similar frontier models, yet they behave differently on the same task. The difference lives in the stack around the model, which is why analyses of what sits inside these products drew attention.
- Exposed configuration. Claude Code in particular made harness components user-configurable: project instruction files like CLAUDE.md, hooks, skills and subagents. Developers stopped treating the harness as a black box and started tuning it.
- Checkable outcomes. Code compiles or it doesn't, and tests pass or fail. That makes coding the domain where harness quality is easiest to measure, and where gains from a better harness show up fastest.
The Anatomy of an Agent Harness
Matsuoka's inventory lists five parts:
- Agents: the model-driven loops, including subagents with narrower roles.
- Hooks: code that runs before or after agent actions.
- Skills: reusable, packaged capabilities.
- Gates: checks the work must pass.
- Workflow: the sequence that ties the other parts together.
Combined with the other definitions, these parts group into three layers.
Context and Memory Management
The context window is the agent's working memory, and it is finite. Good context management decides what goes in, when, and what gets dropped.
- Project instructions. A CLAUDE.md or AGENTS.md-style file tells the agent the conventions it can't infer: how to run tests, which directories are generated, which patterns to avoid. Keep it short and factual. It loads on every run, so every line costs tokens.
- Compaction. Long sessions overflow the window. The harness summarizes older turns, keeps decisions and open problems, and discards raw tool output the model no longer needs.
- Persistent state files. A progress file or task list on disk survives compaction, crashes and new sessions. The agent reads it at the start of a run and updates it as it goes. This is the simplest form of long-term memory, and it works with any model.
- Retrieval on demand. Give the agent tools to search and read files rather than preloading the whole repo. Pulling context as needed usually beats front-loading it.
Tools, Hooks, and Skills
Tool interfaces are the agent's hands, and their design matters as much as any API you'd ship to humans.
A good tool has three traits:
- a clear name and a description that says when to use it
- a tight input schema
- output sized for a context window, not a terminal
Poorly designed tools degrade agent behavior in predictable ways:
- Overlapping tools make the model guess which one to call.
- A tool that dumps 50,000 lines of logs pushes the useful context out of the window.
- A vague error like "failed" gives the model nothing to correct, so it retries the same call or invents a workaround.
Hooks are deterministic code that wraps the agent's actions:
- Pre-tool hooks can block destructive shell commands, refuse writes to protected paths, or require approval for network calls.
- Post-tool hooks can run the formatter after every edit, or trigger the type checker after changes to a typed module.
Hooks matter because they don't depend on the model remembering an instruction. They simply run.
Skills package instructions, scripts and reference material for a specific job, such as running a database migration or cutting a release. The harness loads a skill only when it's relevant, which keeps the base context lean.
Control Flow, Constraints, and Verification Gates
At its core, an agent is a loop: call the model, execute the tool it requested, append the result, and repeat until done. The harness decides what "done" means and what happens along the way.
- Plan/execute splits. One pass produces a plan, often reviewed by a human or a second model. A separate pass executes it. This catches bad approaches before they turn into hundreds of edited lines.
- Iteration and budget limits. A maximum turn count and token budget stop runaway loops.
- Sandboxing. Run the agent in a container or disposable workspace, with network access limited to what the task needs.
- Permission limits. Allowlist safe commands, require approval for risky ones, and deny the rest.
Verification gates are the most important part. Before work is accepted, it must pass tests, linters and type checks. A gate that fails sends its output back to the model as the next message. That is the feedback loop: a mechanical check produces a concrete error, and the model gets another attempt with better information.
Harness Engineering vs Context Engineering vs Prompt Engineering
These terms nest rather than compete:
- Prompt engineering is a subset of context engineering. The prompt is one piece of what lands in the context window.
- Context engineering is a subset of the harness. The context window is one thing the harness manages.
| Prompt engineering | Context engineering | Harness engineering | |
|---|---|---|---|
| Scope | The wording of instructions | Everything in the context window at each step | The whole system around the model: context, tools, control flow, gates, state, environment |
| Unit of work | A single prompt or template | A model call and its assembled inputs | A full agent run, from task to verified result |
| Failure modes it addresses | Misread instructions, wrong format, wrong tone | Missing facts, irrelevant noise, overflowing windows, forgotten decisions | Runaway loops, unsafe actions, unverified output, silent failures, lost progress |
| Who does it | Anyone writing prompts | Engineers building LLM features and agents | Engineers building or configuring agents for production work |
The practical takeaway on harness engineering vs context engineering: good context can't save an agent that never checks its own output. And a perfect test gate can't help a model that never saw the file it needed. You need both, and the harness is where they meet.
A Minimal Harness Example
The fastest way to understand a harness is to build a tiny one. The October 2026 Harness Engineering 101 video takes this approach: a simple harness in JavaScript, running in a browser, that builds itself up from almost nothing.
Below is a sketch of a minimal coding-agent harness with five parts: a loop, a tool registry, a test gate, retry with error feedback, and a state file.
const tools = { read_file, write_file, list_dir, run_tests };
const MAX_TURNS = 40;
async function runAgent(task) {
const state = readFile('PROGRESS.md');
const history = [user('Task: ' + task + '\nProgress so far:\n' + state)];
for (let turn = 0; turn < MAX_TURNS; turn++) {
const reply = await model.call({ system: PROJECT_INSTRUCTIONS, messages: history, tools });
history.push(reply);
if (reply.toolCall) {
const check = preToolHook(reply.toolCall); // block unsafe calls
const result = check.ok
? await tools[reply.toolCall.name](reply.toolCall.args)
: 'Blocked: ' + check.reason;
history.push(toolResult(truncate(result, 4000)));
continue;
}
// The model says it is done. Verify, don't trust.
const gate = await runTests();
appendFile('PROGRESS.md', summarize(reply, gate));
if (gate.passed) return reply;
history.push(user('Tests failed:\n' + tail(gate.output, 4000) + '\nFix the cause, then finish again.'));
}
throw new Error('Turn budget exhausted; see PROGRESS.md');
}Several harness decisions are packed into those lines:
- Tool output is truncated, so one noisy command can't flood the window.
- The agent's claim of completion triggers a gate instead of ending the run.
- Test failures come back as specific feedback rather than "try again".
- Progress persists to disk, so a crash or a new session doesn't start from zero.
- The turn budget fails loudly instead of looping forever.
For harness engineering examples at production scale, read open-source coding-agent harnesses on GitHub, such as OpenHands, Aider, Cline, SWE-agent and OpenAI's Codex CLI. Study how each one handles tool definitions, context truncation, edit formats and permission prompts. Their differences are a free education in design tradeoffs.
Will the Next Model Make Your Harness Obsolete?
Take the skeptic's case seriously, because much of it is right. Matsuoka notes that the people building the most capable coding agents keep going on record to say the scaffolding you build will be absorbed into the next model.
History supports them:
- "Think step by step" prompting mattered a lot until reasoning models made explicit chain-of-thought coaxing largely unnecessary.
- Elaborate tricks for getting valid JSON out of a model gave way to native tool calling and structured outputs.
- Rigid multi-step pipelines that once compensated for weak planning become a ceiling once the model can plan better than your script.
Matsuoka goes further than most. He argues harness engineering is the most important skill you can build right now beyond coding and architecture. He's candid that he has written harnesses for over a year and calls that a disclosed bias. He even concedes the disposable-scaffolding case is "largely correct" before arguing that it doesn't touch the skill he means.
That argument deserves some pushback. "Most important skill" is a big claim from someone invested in it. And his supporting point, that most engineers don't yet believe they need it, is a provocation rather than evidence. The more defensible version is narrower: some harness work is disposable, some is durable, and the durable part is mostly classic engineering discipline applied to a new kind of worker.
| Disposable (expect the next model to absorb it) | Durable (survives model upgrades) |
|---|---|
| Prompt hacks and magic phrasing | Verification gates: tests, type checks, linters, policy checks |
| Workarounds for one model's quirks or formatting bugs | Evals that measure task success across models |
| Rigid step-by-step scripts that dictate process | Environment and repo legibility: clear structure, fast tests, documented commands |
| Hand-tuned retry phrasing for a specific failure | Permission boundaries and sandboxing |
| Over-engineered context stuffing for small windows | Observability: logged trajectories, costs and outcomes |
The pattern is simple. Anything that compensates for what the model can't do yet is temporary. Anything that defines what correct, safe and observable means for your system stays. A smarter model still needs to know whether the build passed, and it still shouldn't have write access to production.
So is harness engineering worth learning? Yes, if you learn the durable half. The future of harness engineering probably looks less like prompt craft and more like building good CI, good sandboxes and good evals.
Designing Harnesses That Survive Model Upgrades
- Keep model-specific logic thin and swappable. Put prompt templates, quirk workarounds and model parameters in one adapter layer, apart from your gates and tools. Swapping models should touch one file.
- Invest in evals first. Keep a fixed set of real tasks with mechanical pass/fail checks. When a new model ships, run the suite with and without each piece of scaffolding. Data, not vibes, tells you what still earns its place.
- Prefer gates that check outcomes over instructions that dictate process. "All tests pass and the type checker is clean" survives any model. "First read file A, then edit function B" breaks the moment a better model finds a better path.
- Delete scaffolding when it becomes redundant. Treat every workaround as having an expiry date. When evals show a new model does as well without it, remove it. Dead scaffolding costs tokens and can constrain a stronger model.
Harness Engineering Best Practices
A checklist you can apply this week:
- Make the repo legible to agents. Use a predictable structure, one documented command to build and one to test, a short project instruction file, and clearly marked generated code.
- Fail loudly. Tools should return specific, actionable errors. Silent failures and swallowed exceptions are the agent equivalent of a liar.
- Verify mechanically. Never accept "done" on the model's word. Gate on tests, type checks, linters and anything else a machine can check.
- Log every trajectory. Record prompts, tool calls, outputs, gate results and costs. When a run goes wrong, the log is your debugger. Over time, it becomes your eval set.
- Start minimal. Begin with a loop, a few tools and a test gate. Add constraints only when observed failures demand them, and note which failure each one fixes.
- Keep a human in the loop at high-risk gates. Require approval for deploys, migrations, deletions and anything touching credentials or money. Automate the rest.
How to Start Learning Harness Engineering
- Build a toy agent loop. Write the minimal harness above against any model API. Give it three tools and a test gate. Then break it on purpose: remove truncation, remove the gate, give it a misleading tool description, and watch what happens.
- Study open-source coding-agent harnesses. Read the tool definitions and context handling in the GitHub projects mentioned earlier. Compare how they solve the same problems differently.
- Read the key blogs. Start with Robert Matsuoka's Hyperdev essay on whether you need to learn it, Cobus Greyling's writing on the rise of AI harness engineering, and the NxCode harness engineering guide. Read them critically, since each has its own angle.
- Use courses and books where they exist. The field is young, so long-form material lags the practice. At least one video course packages the topic into 10 lessons with PDF and EPUB editions. Expect blogs and source code to stay ahead of books for a while.
- Apply it to your daily workflow. If you use Claude Code or Cursor, write a real project instruction file. Add a hook that runs your formatter. Make tests the definition of done. Keep a log of where the agent fails. That log is your harness backlog.
Frequently Asked Questions
Is harness engineering the same as building an agent framework like LangChain?
No. A framework is a library of building blocks: model wrappers, tool abstractions, orchestration helpers. Harness engineering is the design work of choosing what your specific agent sees, can do, must pass and remembers. You can build a harness with a framework, without one, or by configuring an existing agent.
Do I need to learn harness engineering if I already use Claude Code or Cursor?
Those tools ship with a harness, but they expose much of it for you to configure: project instructions, hooks, skills, permissions, and the tests and checks in your repo. The quality of that configuration, plus how legible your codebase is, largely decides how well they work for you. You're already doing harness engineering, whether deliberately or not.
What is the difference between a harness and scaffolding?
People often use the terms interchangeably. A useful distinction: scaffolding is the temporary support that compensates for current model limits, like prompt tricks and rigid step scripts. The harness is the broader system, including durable pieces like gates, sandboxes and observability. Scaffolding is the part you expect to remove.
Is harness engineering only for coding agents?
No, but coding is where it is most visible, because results are easy to verify. The same ideas apply to research, support and data agents: managed context, well-designed tools, constraints and mechanical checks. The hard part outside coding is defining gates, since "is this answer correct?" rarely has a test suite.
Are there books or courses on harness engineering?
Some, and more are coming. A short video course with 10 lessons and PDF/EPUB editions already exists. Much of the best material is still in blogs such as Hyperdev and Cobus Greyling's posts, the NxCode guide, and the source code of open-source coding agents. Pair any course with building your own harness, because the feedback from a real failing agent teaches faster than reading.