Home / Chapter 5 · Agents
    Last edited · 10 min read

    Use with AI

    The coding-agent harness

    A coding agent is a model plus a harness: everything around the model that turns it into a working agent. The model proposes the next step. The harness decides what the model sees, what actually runs and what can be undone.

    In plain wordsA skilled contractor on a building site. The skill is theirs, but the site decides the rest: which tools are laid out, what the job sheet and site rules say, which rooms are locked, who has to sign off before a wall comes down, and whether there is a spirit level to check the work. The same contractor does very different work on a well-run site and on a chaotic one.

    Replay one task in a coding agent: partial refunds are 1 cent short. Switch off one part of the harness, press ▶ and see what changes

    agent turn
    tokens in this call
    input tokens since the start

    Illustrative numbers: a 200k window, a 12k system prompt with built-in tools, 3k of project memory, about 5k tokens of history per turn, compaction at 80% of the window, 50k for all MCP definitions loaded up front. The subagent’s own tokens are not counted. The repository, commands and model behaviour are made up to show typical failures.

    What the harness is made of

    Same model, different harness

    Working with a coding agent

    Failure modes

    Check yourself

    What does a harness add to the model in a coding agent, and why does the same model score differently in two harnesses?

    A harness is everything around the model that makes it an agent: the loop, a few general tools (read, edit, shell, search), the system prompt and a project file such as AGENTS.md, a todo list, context management (clearing old results, compaction, subagents, tool search), skills loaded on demand, permissions and a sandbox, hooks and checkpoints. The model only proposes calls; the harness decides what it sees, what runs and what can be undone. So tools, prompts and a verification loop move scores: LangChain reports 13.7 more points on Terminal-Bench 2.0 after changing only the harness. The harness also keeps the prefix stable for prompt caching, which sets most of the bill.

    Po polsku

    Harness to wszystko wokół modelu, co robi z niego agenta: pętla, kilka ogólnych narzędzi (odczyt, edycja, powłoka, wyszukiwanie), system prompt i plik projektu, np. AGENTS.md, lista zadań, zarządzanie kontekstem (czyszczenie starych wyników, kompakcja, subagenci, wyszukiwanie narzędzi), skille ładowane na żądanie, uprawnienia i sandbox, hooki oraz checkpointy. Model tylko proponuje wywołania, a harness decyduje, co model widzi, co się wykona i co da się cofnąć. Dlatego narzędzia, prompty i pętla weryfikacji zmieniają wyniki: LangChain podaje 13,7 punktu więcej w Terminal-Bench 2.0 po zmianie samego harnessu. Harness trzyma też stały prefiks pod prompt caching, a od tego zależy większość rachunku.

    Follow-up questions (5)
    Why doesn’t “never run git push” in AGENTS.md protect you?
    The file is context, not configuration. The model usually follows it, but a long session, an ambiguous request or injected text can outweigh it. A rule that must hold goes where the harness enforces it: a deny rule, a hook that blocks the call before it runs (in Claude Code this works even in bypass mode), a sandbox, or a token without push rights.
    The sandbox is on. How can the agent still destroy your work?
    The sandbox limits writes to the working directory and the network to allowed domains, and the repository is inside that boundary, so git clean -fdx or rm -rf src goes through. Claude Code checkpoints don’t track changes made by shell commands. What helps: frequent commits, an ask or deny rule for destructive commands, and a separate worktree or container for risky tasks.
    The agent keeps reporting success while CI fails. What do you change in the harness?
    A fast check the agent can run itself, with the command named in AGENTS.md. A hook for the moment the agent wants to finish that runs the tests and returns failures to the model as feedback. The result is judged by the exit code and the diff, not the summary. Anthropic and LangChain both describe a premature “done” as one of the most common failures of coding agents.
    Costs doubled after you connected three MCP servers. Why, and what do you do?
    Tool definitions sit in the prefix, so you pay for them on every turn, and in a harness that loads them up front, connecting a server mid-session invalidates the cache. What helps: tool search, so only names sit in the prefix, only the servers the task needs, and a fixed tool set for the whole session. Check the effect in usage: the ratio of cache reads to cache writes.
    When is a subagent better than doing the work in the main session?
    For side tasks that mostly read: searching the repository, reading logs, reviewing a diff. The subagent spends tokens in its own window and returns a short summary, so the main context stays short. Edits that depend on decisions from the main thread stay in the main session, because the subagent doesn’t see those decisions, and in Claude Code its edits usually don’t go into your checkpoints. In total, subagents cost more tokens, not fewer.

    Sources

    Report an error · Suggest a fix