---
title: "Harness Engineering: What It Is and How to Make Your Agent More Reliable"
author: "Ecem Karaman"
source: "https://aiwithecem.com/guides/harness-engineering"
published: 2026-11-04
tools: ["Claude","Codex","Multi-Tool"]
topics: ["AI Agents","Workflows","Setup"]
---

# Harness Engineering: What It Is and How to Make Your Agent More Reliable

Give two people the same model and one gets an agent that finishes the job while the other gets one that loses the thread halfway. The difference is usually the harness: everything built around the model. Last year the attention was on prompts. Now the teams getting reliable results are engineering the harness, and you can apply the same ideas to the Claude Code or Codex setup you already use.

**Details checked against [Claude Code's docs](https://code.claude.com/docs/en/how-claude-code-works), [OpenAI's Codex docs](https://developers.openai.com/codex), [Anthropic's engineering blog](https://www.anthropic.com/engineering/managed-agents) and the [Claude Platform docs](https://platform.claude.com/docs/en/managed-agents/dreams) on November 4, 2026.**

> **In this guide**
>
> 1. [What a harness is](#what-a-harness-is)
> 2. [A real harness, taken apart](#a-real-harness-taken-apart)
> 3. [Six changes to make this week](#six-changes-to-make-this-week)
> 4. [Where it pays off](#where-it-pays-off)
> 5. [Caveats](#caveats)
> 6. [Start here](#start-here)

## What a harness is

Claude Code's docs put it plainly: models reason, tools act, and Claude Code is "the layer around the model that provides the tools and manages the context the model sees." That layer is the agentic harness. It has five parts:

| Part | What it does | What breaks without it |
| ---- | ------------ | ---------------------- |
| **Loop** | Calls the model, runs the tool it asks for, feeds the result back, repeats | The agent answers once and stops |
| **Context** | Decides what the model sees each turn: instructions, files, skills, history | It forgets the brief or drowns in noise |
| **Tools and sandbox** | Where actions happen: files, shell, browser, APIs | It can describe the fix but not make it |
| **Session log** | A record of every step | A crash means starting over |
| **Memory** | What carries over to the next session | Every run starts from zero |

Harness engineering is shaping those five parts for the task in front of you, instead of accepting the defaults.

## A real harness, taken apart

Anthropic's [engineering post on Managed Agents](https://www.anthropic.com/engineering/managed-agents) shows these ideas at production scale. They split the agent into three pieces:

- **Brain:** Claude plus the loop that routes its tool calls.
- **Hands:** sandboxes and tools, each called like a function. A sandbox only starts when the agent needs one.
- **Session:** an append-only log stored outside both.

The results:

- Median time to first token dropped about 60%, and the slowest 5% of requests improved by over 90%.
- If a container dies, the harness reports it to Claude as a tool error and Claude can retry in a fresh one.
- If the harness itself crashes, a new one reads the log and picks up from the last event.

Research points the same way. [Harness²](https://hyper.ai/en/papers/2610.14224), from Northwestern and Google Cloud AI Research, improves results by refining the harness while leaving the model's weights untouched. [DynaFlow](https://hyper.ai/en/papers/2610.34467), from the National University of Singapore, has a main agent write a custom workflow program for each problem instead of following a fixed graph.

## Six changes to make this week

**1. Put the task in the harness, not the prompt.** Repeated instructions belong in a skill, which both Claude Code and Codex load only when it's relevant. Rules that must always hold belong in a hook, which runs every time. A `PreToolUse` hook can block a command before it executes.

**2. Keep a log you can resume from.** Name long sessions so you can find them again. Then pick up where you left off instead of re-explaining:

```text
claude --continue        # most recent session in this folder
claude --resume <name>   # a specific one
codex resume             # Codex equivalent
```

**3. Make failure cheap.** In Claude Code, press `Esc` twice or run `/rewind` to roll the code or the conversation back to an earlier prompt. Rewind doesn't track files changed only by shell commands, so commit to git before big changes.

**4. Review memory before you trust it.** Claude Code's auto memory is on by default and saves plain markdown files you can open with `/memory`. Codex memories are opt-in. Anthropic's [dreaming](https://platform.claude.com/docs/en/managed-agents/dreams) feature, in research preview, rebuilds an agent's memory from past sessions. It writes a new store and leaves the old one untouched, so you review it before you switch. Copy that habit: read what your agent learned before it shapes the next run. The [weekly context audit](/guides/weekly-context-audit) is a ten-minute routine for it.

**5. Hand narrow jobs to subagents.** A subagent works in its own context window and returns a summary, so research and searches don't clutter your main session. Both Claude Code and Codex support them.

**6. Route by cost.** Not every step needs the strongest model. In Claude Code, set `model: haiku` on an exploration subagent, or use `opusplan`, which plans with Opus and executes with Sonnet. Codex lets you set a model per custom agent.

## Where it pays off

| Use case | Harness parts that matter most |
| -------- | ------------------------------ |
| An incident agent that investigates alerts (the demo in Anthropic's workshop) | Sandbox, session log, retries |
| A daily digest that runs at 8 a.m. without you | Scheduling, memory |
| Code review on every pull request | Skills, hooks, a cheaper model for first pass |
| A content pipeline, like [editing video with agents](/guides/ai-video-editing-stack) | Skills, subagents, a review step before render |

## Caveats

- **It's a trade-off, not a free upgrade.** Builder Viv Trivedy [argues](https://x.com/Vtrivedy10/status/2052100726608781363) that a tuned harness can beat Claude Code or Codex on a specific task with the same model, and that a truly general-purpose harness doesn't exist. Every hook and skill is something you now maintain.
- **A self-improving agent can learn the wrong lesson.** Only keep a learned rule after it passes a test you can rerun, and make sure you can trace a regression back to the session that caused it.
- **Research results are early.** Both papers report benchmark gains from a single study. They show a direction, not a guarantee for your workload.
- **Casual chat doesn't need this.** The ChatGPT and Claude apps already wrap the model in a harness. This matters once you run agents on repeated or long tasks.

## Start here

- [ ] Find the instruction you repeat most and turn it into a skill.
- [ ] Add one hook for a rule your agent keeps breaking.
- [ ] Name your next long session and resume it tomorrow instead of starting fresh.
- [ ] Open your agent's memory and delete anything wrong or stale.
- [ ] Move one search-heavy job to a subagent on a cheaper model.

**Go deeper:** [Anthropic's 12-minute Managed Agents talk](https://www.youtube.com/watch?v=xHVbj_rOubw) · [How Claude Code works](https://code.claude.com/docs/en/how-claude-code-works) · [Subagents](/guides/subagents) · [Weekly context audit](/guides/weekly-context-audit)
