A coding agent is a model wrapped in code
In Level 1 you saw that one model can score very differently depending on what surrounds it. This level gives a name to each thing that surrounds it. Once you can name the parts, you can find them in any agent, measure them and change them.
Think of a racing car. The model is the engine. The harness is everything else: steering, brakes, fuel lines, dashboard and pit crew. Put the same engine in a better chassis and it posts better lap times. When a coding agent "decides" to run your tests after an edit, it is often the chassis doing that, not the engine.
The six parts
+--------------------------------------------+
user task ->| CONTEXT: system prompt, AGENTS.md/CLAUDE.md, |
| conversation history, tool results |
+----------------------+---------------------+
v
+--------------+ +--------+ +-------------+
| MODEL CLIENT |<->| LOOP |<->| TOOLS |
| (one API | | call, | | read, edit, |
| call) | | act, | | run shell |
+--------------+ | repeat,| +------+------+
| stop | |
+--------+ v
+-----------------------+ +-------------------+
| GUARDRAILS: permission| | VERIFICATION: |
| checks, hooks, limits | | tests, lint, types|
+-----------------------+ +-------------------+
| Part | Responsible for | Typical failure when it is weak |
|---|---|---|
| Model client | Sending one request to a model and returning its reply | Provider quirks leak through the whole codebase |
| Loop | Calling the model again and again, feeding results back, deciding when to stop | Stops too early, or runs forever |
| Tools | The actions the model can ask for: read a file, edit, run a command | The model can't do the job, or misuses vague tools |
| Context | What the model sees on each call | The model ignores conventions it was never shown |
| Guardrails | Code that blocks, permits or changes actions whatever the model wants | rm -rf runs because you only asked nicely |
| Verification | Checking the work and returning the evidence to the model | "Done!" with failing tests |
The model only produces text, and some of that text is structured tool requests. Everything else in the table, including reading files, running commands, remembering conventions, refusing dangerous actions and stopping, is harness code.
Finding the parts in an agent you already use
Here is Claude Code, with notes on other agents:
- Context. Claude Code loads
CLAUDE.mdfiles into every session and can read a repository'sAGENTS.mdin their place. OpenAI's Codex CLI readsAGENTS.mditself. It walks from the project root down to your working directory and stops adding files once they total 32 KiB by default. Gemini CLI looks forGEMINI.mdby default and can be configured to readAGENTS.md.AGENTS.mdis an open format now run by the Agentic AI Foundation under the Linux Foundation. - Tools. File read, edit and write, grep, shell and web fetch. MCP servers add more tools.
- Guardrails. Permission rules in
.claude/settings.json, plus hooks: your own scripts that run on events. APreToolUsehook runs before a tool call and can deny it. - Verification. A
PostToolUsehook runs after a tool call succeeds. The hooks guide shows one that runs Prettier after everyEdit|Write. The same pattern can run your linter or tests. - Loop and client. These are built in and you don't see them, but they explain the turn-by-turn rhythm you watch in the terminal.
A small project config shows guardrails and verification as code, not prose:
// .claude/settings.json (illustrative; check current docs for exact schema)
{
"permissions": {
"deny": ["Bash(rm -rf:*)"] // guardrail: blocked even if the model asks
},
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write", // only after file-editing tools
"hooks": [{ "type": "command", "command": "npx prettier --write ." }]
}]
}
}
Gotcha: if you write "never delete files" in
CLAUDE.md, that is context, and the model follows it only most of the time. A deny rule is a guardrail, and code enforces it every time. Mixing the two up is the most common harness mistake.
Model behaviour or harness behaviour?
Use this test: could you change the behaviour by editing code or config, without touching the model's weights? If yes, it's the harness.
| Behaviour you've seen | Owner |
|---|---|
| Asks before running a shell command | Harness (guardrail) |
| Knows your test command in a new session | Harness (context file) |
| Long command output cut short with "...truncated" | Harness (tool/context) |
| Stops after a fixed number of turns | Harness (loop) |
| Writes idiomatic, well-named code | Model |
| Calls a function that doesn't exist in your library | Model (though a type check in the harness can catch it) |
The last row matters most. Many failures start in the model but can be caught by the harness, and that is where you have leverage.
Set up the course repo
Every later level adds to one repo with matching Python and TypeScript halves. You don't need a model SDK yet; that comes next level.
mkdir harness-course && cd harness-course && git init
# Python half (uv manages the venv and pyproject.toml)
uv init py --no-package # app layout, not an installable package
cd py && uv add --dev pytest ruff && cd ..
# TypeScript half (use a current Node LTS, 24 or newer)
mkdir ts && cd ts
npm init -y
npm install -D typescript tsx @types/node
npx tsc --init
cd ..
Add a map of the parts that both halves will fill in:
harness-course/
AGENTS.md # context for any coding agent working on THIS repo
py/harness/ # client.py loop.py tools.py guardrails.py verify.py
ts/src/harness/ # client.ts loop.ts tools.ts guardrails.ts verify.ts
Create those files as empty stubs, each with a one-line comment saying what it owns. Keeping a file per part means you can later measure each part, and delete it, on its own.
Exercise
- Open a coding agent you use (Claude Code, Codex CLI, Gemini CLI, Cursor or another) and find at least one concrete example of each of the six parts: a file, a setting, a log line or a prompt.
- Write down five behaviours you saw in your last real session and sort them into model and harness using the test above.
- Commit the scaffold with
AGENTS.mddescribing how to runuv run pytestandnpx tsc --noEmit.
Key takeaways
- A harness has six parts: model client, loop, tools, context, guardrails and verification.
- The model only produces text and tool requests. Acting, remembering, blocking and checking all happen in harness code.
- Instructions in context files are followed only most of the time. Permission rules and hooks are enforced every time.
- If code or config can change a behaviour, it belongs to the harness, which makes it yours to measure and improve.
- Keep one module per part so each can be tested, swapped or cut later.