← All guides

Harness Engineering Explained: Prompt vs Context vs Harness

In 2023 everyone learned prompt engineering. In 2025 it was context engineering. In 2026 the word is harness engineering. It is not one more buzzword. It names the part of an agent setup that decides most of the result: everything around the model. This guide explains the three terms in one line each, shows the data that makes the harness matter, and maps each part to the OpenClaw settings that control it.

Bottom Line

  • Prompt engineering is what you tell the model.
  • Context engineering is what the model can see right now.
  • Harness engineering is the system that runs the model: the loop, the tools, the checks, the permissions and the memory.
  • The harness changes results as much as the model. The same model scored 58.0% in one harness and 76.4% in another on Terminal-Bench 2.0.
  • In OpenClaw, the harness is your workspace and config: AGENTS.md, skills, hooks, the sandbox, exec approvals and compaction.

The Three Layers in One Table

LayerQuestion it answersExample
PromptWhat do I ask?”Fix the failing login test.”
ContextWhat can the model see now?The test file, the error, the repo rules, recent messages
HarnessWhat lets the model do the job?The loop, tools, tests, linters, sandbox, approvals, memory, compaction

Each layer contains the one before it. The harness decides what goes into the context. The context holds the prompt.

Anthropic’s engineering team gives the cleanest definitions:

  • Context engineering is “the set of strategies for curating and maintaining the optimal set of tokens” (September 2025).
  • The harness is “the loop that calls Claude and routes Claude’s tool calls” (April 2026).

Birgitta Böckeler’s article on martinfowler.com puts the common meaning in seven words: “everything in an AI agent except the model itself”.

Where the Word Came From

Two posts made the term popular in February 2026:

  1. Mitchell Hashimoto (5 February) wrote a step called “Engineer the Harness”. When the agent makes a mistake, you change the setup so it cannot make that mistake again.
  2. OpenAI (11 February) published “Harness engineering: leveraging Codex in an agent-first world”. A team of 3, later 7, engineers built an internal product where Codex wrote the code.

The OpenAI numbers are why people paid attention:

FactValue
Lines of codeAbout 1 million
Pull requests mergedAbout 1,500
Lines written by hand0
Pull requests per engineer per day3.5 on average
Longest single Codex runsOften more than 6 hours

The team’s summary: “Humans steer. Agents execute.” The engineers did not write code. They built the harness: a short AGENTS.md (about 100 lines) used as a map, a structured docs/ folder, custom linters, structural tests, a bootable app per worktree, and local logs and metrics the agent could query.

OpenAI also warns that this result “should not be assumed to generalize without similar investment”.

Why the Harness Matters: The Data

Same model, different score

The official Terminal-Bench 2.0 leaderboard lists the same models in many harnesses. Claude Opus 4.6:

HarnessScore
Meta-Harness76.4%
Capy75.3%
Terminus-KIRA74.7%
Droid69.9%
Terminus 262.9%
Claude Code58.0%

That is an 18.4-point spread with no change to the model. Gemini 3.1 Pro shows the same pattern: 80.2% in TongAgents and 61.4% in Gemini CLI.

Same model, different cost

FrontierHarness Eval (September 2026) ran one model, Kimi K3, through 9 harnesses on 30 tasks:

HarnessPass rateMedian cost per pass
Exo Harness53.3%$1.05
Pi60.0%$2.43
DSH Creator63.3%$3.28
Codex66.7%$3.47
Claude Code63.3%$18.34

Two harnesses passed the same 19 tasks at a 5.6x cost difference. The authors trace most of it to the prompt cache: 25% cache hits in Claude Code against 91.6% to 99.1% in the others. Claude Code is built for Anthropic’s cache rules, and this model uses a different one. One task took 381 turns in Claude Code and 90 in Pi.

The lesson is not “harness X is bad”. A harness is tuned for one model. Pair it with another and the cost or the score can move a lot.

A model upgrade can make harness parts useless

Anthropic found that Sonnet 4.5 needed context resets in a long task. On Opus 4.5, the problem was gone and “the resets had become dead weight.” A March 2026 Anthropic post says every harness part “encodes an assumption about what the model can’t do”.

So a harness is not done when it works. Check it again after each model change.

The Parts of a Harness

PartWhat it doesFails like this when it is missing
LoopCalls the model, runs tool calls, repeatsThe agent answers once and stops
InstructionsRepo rules and a map of where things areThe agent guesses the build command
ToolsShell, files, browser, APIsThe agent can describe a fix but cannot make it
ChecksTests, linters, type checksThe agent says “done” and it is not
PermissionsWhat the agent may do without askingOne bad command runs on your real machine
SandboxWhere commands runThe agent can reach your keys and files
CompactionShrinks old turns near the context limitThe session fails, or loses decisions
MemoryNotes that survive a new sessionEach session starts from zero

Böckeler sorts these into two kinds. Guides steer the agent before it acts, such as instructions. Sensors tell it what went wrong after it acts, such as test output. A good harness has both.

Where Each Part Lives in OpenClaw

OpenClaw is a harness. You do harness engineering when you change these files and settings:

PartOpenClaw featureSetting
InstructionsAGENTS.md and the other workspace files, loaded each sessionagents.defaults.workspace, bootstrapMaxChars (20,000), bootstrapTotalMaxChars (60,000)
Reusable proceduresSkills: folders with a SKILL.mdskills.entries, skills.load.extraDirs
Event codeInternal hooks on events such as /new and /resethooks.internal.entries.<name>
SandboxRuns tools in Docker, Podman, OpenShell or SSH. Off by defaultagents.defaults.sandbox.mode: off, non-main, all
Tool policyWhich tools the agent hastools.allow, tools.deny, tools.profile
Exec approvalsWhich shell commands need your yestools.exec.mode: deny, allowlist, ask, auto, full
CompactionSummarizes older turns, keeps recent onesagents.defaults.compaction
MemoryPlain Markdown: MEMORY.md, memory/YYYY-MM-DD.mdagents.defaults.compaction.memoryFlush.enabled

Two notes from the OpenClaw docs:

  • Bootstrap files are cut when they pass the character limits. A long AGENTS.md does not all reach the model. Keep it short, like OpenAI’s 100-line map.
  • Memory is only what is on disk. The docs say “there is no hidden state.”

How to Start Harness Engineering This Week

  1. Write down the last 3 mistakes your agent made. For each one, ask which harness part would have stopped it.
  2. Fix it in the harness, not in the prompt. A wrong build command goes in AGENTS.md. A repeated bad edit gets a linter rule or a test.
  3. Give the agent a check it can run. If it cannot run the tests, it cannot know it is done.
  4. Turn on the sandbox and exec approvals. Our security checklist has the settings.
  5. Cut your instructions. Move detail into docs/ files or skills and keep AGENTS.md as a map.
  6. Test again after a model change. Remove the parts the new model does not need.

Honest Caveats

  1. Leaderboard scores mix many things. Each harness entry was submitted separately, often by its maker. The spread shows that the harness matters, not by exactly how much.
  2. FrontierHarness is small. It used one model and 30 tasks, so one task is 3.3 points. The authors say this themselves.
  3. OpenAI’s result came from a team that built a lot of tooling. Do not expect it from a default setup.
  4. OpenClaw config keys change between versions. Older guides use tools.exec.security and tools.exec.ask. The docs say openclaw doctor migrates them to tools.exec.mode.

Sources

See Also

Read next

Agent Loops Explained: Goal, Act, Verify, Stop
Every AI agent is a loop: goal, act, verify, stop. Loop engineering is designing that loop so it checks its own work and ends at the right time. Stop conditions in Claude Code, Codex, the OpenAI Agents SDK and OpenClaw, the verification data, and the runaway costs.
Agent Memory Explained: State, Not a Vector Database
RAG finds what is relevant. Memory must know what is true now. How RAG, memory, context, skills and tools differ, why a vector store returns stale facts, the LongMemEval and LoCoMo evidence, memory poisoning, and how OpenClaw memory works.
Context Rot Explained: Why Agents Get Worse Over Time
Context rot is the drop in model accuracy as the input grows, long before the context window is full. The benchmark data, why a 1M window is not 1M useful tokens, what compaction loses, and the fixes in Claude Code, the Claude API and OpenClaw.
Pass Rate vs Completion Rate Explained: Agent Benchmarks
Why the best coding agents pass only 40% of Android Bench 2.0's long tasks but complete over 80% of the work. Pass rate vs completion rate, pass@k vs pass^k, harness effects, saturated benchmarks, and a checklist for reading any agent benchmark claim.