Harness Engineering 6 months ahead, in a few hours.

What is harness engineering? Definition and a real example

Thomas Poulain Ā·

Your AI agent says it has finished its task. On review, half the features are missing and the unit tests fail. Harness engineering addresses this problem. It gives the agent (Claude Code, Codex, Copilot…) everything it needs to deliver the expected result, safely and autonomously. What used to take you a day then takes an hour.

What is harness engineering?

Harness engineering is the practice of designing and tuning everything around the model in a coding agent, meaning its instructions, permissions, tools and automated checks. Together, those pieces are called the harness.

The goal is an agent that does good work by default, so you stop typing the same corrections on every task. A prompt works once. A harness is written once, then Claude Code reloads it in every session on the project.

What’s in an agent harness for Claude Code?

You can split the Claude Code harness into six layers, which the course covers one by one. Here they are, in the order a task goes through them.

  • Intent. Before any code, Claude interviews you about what you need and writes a spec. You approve it, then Claude implements it in a fresh session. In plan mode, which you enter with /plan, Claude explores the code and proposes a plan without editing anything.
  • Context. You write your project’s commands and conventions in CLAUDE.md. Claude reads it at the start of every session. If your repository has no CLAUDE.md but already has an AGENTS.md, the instruction file other coding agents use, Claude Code reads that one, as the post on AGENTS.md explains.
  • Tooling. An MCP server is a program that gives Claude new tools, for example to read your tickets or query your database.
  • Skills. A skill is a procedure you write once in a SKILL.md file. Claude loads it when your request matches, or you run it yourself with /skill-name.
  • Guardrails. A hook is a command Claude Code runs at a set point in the session, such as your linter after every edit. Permission rules say what Claude may read, edit or run, and a deny rule forbids an action. In auto mode, a second model called the classifier reviews the actions your rules don’t cover and blocks the destructive ones. The sandbox limits which files and network hosts Bash commands can reach.
  • Shipping. Claude checks its work, then commits and opens the pull request. The built-in /verify skill runs your app to try the change, and /code-review reviews your branch. A subagent is a Claude instance your session starts for one specific task. It begins with an empty context, without your conversation history, so it reviews the code without having followed the session that wrote it.

How is harness engineering different from prompt engineering and context engineering?

They differ in what you tune and in how long the result keeps working.

PracticeWhat you tuneHow long it lasts
Prompt engineeringThe wording of one requestOne task
Context engineeringWhat the model can see while it works, its context windowOne session, or longer once it’s in a file
Harness engineeringEverything around the model, including code that runs without itEvery session on the project

The three nest inside each other. A good harness still relies on clear requests and well-chosen context.

The harness goes further with the pieces that run without the model. Claude gets CLAUDE.md as a message and tries to follow it, with no hard guarantee. A hook, on the other hand, runs every time its event fires, and a deny rule blocks the action whatever the model decides.

What does harness engineering look like on a real task?

Say you work on the billing API of a SaaS product, written in TypeScript on top of Postgres. Support has been asking for weeks to refund part of an invoice, and the ticket finally lands in your sprint. You hand it to Claude Code with a one-line request: ā€œAdd an endpoint for partial refunds.ā€

Without a harness, Claude tells you fifteen minutes later that POST /invoices/:id/refunds is ready. The endpoint records the refund and updates the invoice status. But nothing stops you from refunding more than the invoice total, and no credit note is created. Everyone on the team knows those two rules, but the ticket was one line long and Claude had no way to guess them.

The tests fail too. Claude stored the amount in dollars, with decimals, while the rest of the code counts in cents. The tests on invoice totals break, and Claude didn’t notice because it never ran them before wrapping up. To add its column, it also edited a migration that was already deployed to production.

So you spend the rest of your morning reviewing the diff and sending the problems back one at a time.

A week later, on another ticket, you explain once more that amounts are in cents.

With a harness, you deal with each of these problems once, starting with the missing features. Before any code is written, you ask Claude to interview you about the ticket. Its questions, such as ā€œwhat happens if someone refunds the same invoice twice?ā€, bring out the rules nobody had written down. Claude puts them in a spec that you approve, with acceptance criteria that say what ā€œdoneā€ means for this ticket.

## Acceptance criteria
- `POST /invoices/:id/refunds` refunds a given amount in cents
- The request is rejected if total refunds would exceed the invoice total
- The invoice moves to `partially_refunded`, then to `refunded` once fully refunded
- Every refund creates a credit note
- A test covers each of these cases

Then you switch to plan mode with /plan. Claude explores the code and proposes its plan, which you read before it edits a single file.

The cents and the migration matter beyond this ticket. They are project rules, so you write them in CLAUDE.md, next to the commands, where Claude reads them at the start of every session.

## Commands
- All tests: `pnpm test`
- Lint: `pnpm lint`

## Rules
- Amounts are integers in cents, never floats
- Never edit a migration in `migrations/` that's already deployed, add a new one

That leaves the tests Claude never ran. A line in CLAUDE.md isn’t enough here, because Claude tries to follow it with no guarantee. So you hand that check to a Stop hook, which fires every time Claude is about to hand control back to you. The hook runs a small script, and the script runs pnpm test. If a test fails, Claude reads the error and fixes its work until the test passes.

You declare the hook in .claude/settings.json:

{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/run-tests.sh"
          }
        ]
      }
    ]
  }
}

The script also has to avoid sending Claude back to work forever, and the post on hooks shows how.

Once this harness is in place, every new ticket benefits from the same rules and checks without you repeating them. Claude hands back work that covers the approved criteria, with passing tests, and all that’s left is to review the diff. When a new mistake shows up, it becomes one more line in CLAUDE.md or one more automated check.

Is harness engineering only for Claude Code?

No. The idea works with any coding agent that reads instructions from the repository and runs commands. Codex, for example, reads its own from AGENTS.md.

The file names change from one tool to the next. Claude Code reads CLAUDE.md, its settings in .claude/settings.json, its skills in .claude/skills/ and its subagents in .claude/agents/.

How do you start building your harness?

Start small, on a project where you already use Claude Code.

  1. Run /init. Claude Code analyzes your codebase and drafts a first CLAUDE.md.
  2. Read it. Keep what matters in every session, such as build and test commands, conventions and gotchas.
  3. Add a line when Claude makes the same mistake twice, or when you type the same correction as last session. That rule of thumb comes from the Claude Code docs.
  4. When an instruction must apply every time, move it into a hook or a permission rule.
  5. Commit CLAUDE.md and .claude/settings.json so your whole team gets the same harness.

Then run /context to see what your harness already loads into the context window.

The first module of the course is free. It covers tokens, the context window and the harness, and the modules after it build each layer on your own codebase.

To see these articles more often on Google, add Harness Engineering to your preferred sources.

You might also like