Effective harnesses for long-running agents
TL;DR. Compaction alone does not let a coding agent build a large app across many context windows. Left to itself, the agent tries to build everything at once and runs out of context mid-feature, or a later session sees progress and declares the job done. The fix is a harness with two prompts. An initializer session expands the user’s request into a JSON list of 200+ end-to-end features (all failing), an init.sh script, a progress log and a first git commit. Every later coding session reads these artifacts, checks that the app still works, builds one feature, tests it in a browser like a user would, and ends with a commit and a progress note.
Why it matters now. Long-horizon agents (coding, deep research, RL-trained tool agents) all face the same problem: the task is longer than one context window, so state has to be handed off. This essay is a concrete, reusable recipe for that handoff, and it names the failure modes clearly. Read it together with the March 2026 follow-up on harness design and the April 2026 Managed Agents essay. Both make the point that harness workarounds encode assumptions about what a model cannot do, and those assumptions go stale as models improve.
Key idea
Section titled “Key idea”The problem. The Claude Agent SDK already does compaction, so in principle an agent could work forever. In practice, given a one-line prompt asking for a claude.ai clone, Opus 4.5 in a loop across context windows fell short of a production-quality app. The essay saw two failure patterns:
- One-shotting. The agent did too much at once, ran out of context in the middle of a feature, and left the next session with half-built, undocumented code. Compaction did not always pass on clear enough instructions.
- Premature victory. Later in a project, a fresh session looked around, saw that much had been built, and declared the job finished.
The harness. The essay calls them two agents, but a footnote says they share the same system prompt, tools and harness. Only the first user prompt differs.
- Initializer session. Writes a comprehensive feature list in JSON. Each entry has a category, a description, test steps and a
passesflag set to false; the claude.ai clone had over 200. It also writesinit.sh(starts the dev server),claude-progress.txt(a log of what agents have done) and makes an initial git commit. - Coding sessions. Each one gets its bearings with a fixed routine: run
pwd, read the progress log and git log, read the feature list and pick the highest-priority unfinished feature, runinit.sh, and run a basic end-to-end test (start a chat, send a message, get a reply) to catch anything the last session broke. Then it implements one feature, verifies it end to end with browser automation (Puppeteer MCP), flips only that feature’spassesflag, commits with a descriptive message and appends a progress note.
Guardrails on the spec. Coding agents may change only the passes field. The prompt says: “It is unacceptable to remove or edit tests because this could lead to missing or buggy functionality.” JSON was chosen over Markdown because the model was less likely to overwrite it inappropriately.
Testing was the last big gap. Without explicit prompting, the agent tested with unit tests or curl against the server and marked features done that did not work end to end. Prompting it to test in a browser as a human would, the essay reports, greatly improved performance. Gaps remained: the agent cannot see browser-native alert modals through Puppeteer MCP, so features that used them were buggier.
Worked example (illustrative numbers, not from the essay). Take features, one attempted per session, and suppose a session ends with a correctly verified feature with probability . Then
Now remove the feature list, and suppose each session independently declares the project done with probability . The chance of getting through 250 sessions without stopping early is
A 2% per-session chance of premature victory almost guarantees an unfinished project. The feature list changes the stop rule from the agent’s impression to a checkable condition: every flag is true. Verification matters for a related reason. If features are wrongly marked passing at rate , about broken features remain. Sessions only pick features that are not yet passing, so these are never revisited unless the start-of-session smoke test happens to hit them.
| Plain compaction loop | Initializer + coding-session harness | |
|---|---|---|
| State between windows | Model-written summary of the conversation | Feature list, progress log, init.sh, git history |
| Unit of work | Whatever the agent chooses (often everything) | One feature per session |
| Stop rule | The agent’s judgement | All passes flags true |
| Verification | Unit tests or curl, if any | Smoke test at start; browser end-to-end test before flipping a flag |
| What did not change | The model, system prompt, tools and Agent SDK harness; only the first user prompt differs between the two session types | |
| Evidence | Qualitative observations on one internal demo; no numbers |
The 2026 follow-ups. The harness-design essay (Prithvi Rajasekaran) extends the recipe into a planner, generator and evaluator, because agents grading their own work tend to praise it. It also describes this earlier harness as relying on context resets because Sonnet 4.5 showed context anxiety: wrapping up early as it sensed its context limit. Opus 4.5 largely lost that behaviour, so the resets were dropped, and with Opus 4.6 the sprint decomposition was removed too. The motivating example in the November essay names Opus 4.5, so the two essays do not fully agree on which model the earlier harness used. Managed Agents generalises the lesson. Instead of betting on one harness, it fixes the interfaces around the model:
- an append-only session log outside any context window, read back in slices with
getEvents(); - a stateless harness that can be restarted with
wake(sessionId); - sandboxes reached only through
execute(name, input) → string, with credentials kept out of them.
Key results
Section titled “Key results”There are no quantitative results in this essay. All claims are vendor-reported and qualitative, from one internal demo (a claude.ai clone with 200+ features).
- Incremental work (one feature per session) was critical to stopping the one-shot failure, and commits plus progress notes removed the need to guess what had happened.
- Browser automation for testing greatly improved how many bugs the agent found and fixed. Alert modals that Puppeteer MCP cannot see remained a weak spot.
- Four failure modes, four fixes (the essay’s table): early victory → feature list; buggy or undocumented state → git repo, progress notes and a start-of-session test; premature “done” flags → self-verification before flipping; rediscovering how to run the app →
init.sh. - Follow-up numbers (harness-design essay, also vendor-reported): on a retro game-maker prompt with Opus 4.5, a solo agent ran about 20 minutes for USD 9 while the full planner-generator-evaluator harness ran about 6 hours for USD 200 and produced a working play mode the solo run lacked. A simplified harness on Opus 4.6 built a browser audio workstation in about 4 hours for USD 124.
- Managed Agents reports p50 time-to-first-token down about 60% and p95 down over 90% after moving the harness out of the container.
Limitations & open questions
Section titled “Limitations & open questions”- No measurements. No completion rates, no baseline comparison and no independent test suite. The feature list and tests were written by the agent itself.
- Self-grading. The coding agent decides when a feature passes. The follow-up essay found that agents grading their own work are lenient, which is why it added a separate evaluator.
- Prompt-level guardrails. Not editing tests is enforced only by instructions. A model under pressure, or trained with test-based rewards, could still edit them.
- Model-specific. Parts of the harness stopped being necessary a model generation later. Results do not transfer automatically.
- Open questions named in the essay. Is one general coding agent best, or would specialised agents for testing, QA and cleanup do better? Do the lessons transfer to long tasks such as scientific research or financial modelling?
Connections
Section titled “Connections”- Effective context engineering: compaction, structured note-taking and sub-agents, the general techniques this harness puts into practice.
- Building effective agents: the evaluator-optimizer pattern that the follow-up harness adopts.
- Demystifying evals for AI agents: why graders must be independent and hard to game.
- Writing effective tools for agents: the tool side of the same harness.
- Recursive language models: context as an object outside the window, which Managed Agents cites for its session log.
- MemGPT: an earlier design for paging state in and out of a fixed context window.
- SWE-agent: another coding-agent harness, focused on the agent-computer interface.
- ImpossibleBench: measures agents that edit or work around tests, the risk the no-test-editing rule targets.
- Long-horizon tool agents: training agents for tasks longer than one context window.
- BrowseComp-Plus: a fixed-corpus setting where a research version of this harness could be tested.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
Use the page's illustrative model of the claude.ai clone: N = 200 features, one feature attempted per session, and a session ends with a correctly verified feature with probability s = 0.8. Compute the expected number of coding sessions. Then suppose that, without a feature list, each session after the first independently declares the project finished with probability d = 0.02, and compute the chance of reaching the needed number of sessions without stopping early. Finally, if unverified features are wrongly marked passing at rate f = 0.15, how many silently broken features remain, and why does the harness rarely revisit them?
What a strong answer covers
- Expected sessions = N / s = 200 / 0.8 = 250 (each session is a Bernoulli trial for one feature; this is the mean of a sum of geometric waits).
- No early stop over about 250 sessions: (1 − 0.02)^250 = exp(250 · ln 0.98) ≈ exp(−5.05) ≈ 0.0064, so under 1%. Even a small per-session chance of declaring victory almost guarantees an unfinished project.
- The feature list replaces the agent's judgement of being done with an objective stop rule: every passes field is true.
- False passes: f · N = 0.15 × 200 = 30 broken features marked passing.
- Coding sessions choose the highest-priority feature that is not yet passing, so a false pass removes a feature from the work queue; only the start-of-session smoke test or a later regression would expose it, which is why end-to-end testing before flipping the flag matters.
- Mechanism
Compaction lets one agent keep going on a summarised history, yet the essay says compaction is not sufficient. Explain the mechanism by which the initializer artifacts plus a fixed start-of-session routine let a fresh context window recover the state of the project, why each coding session is limited to one feature, and why the feature list is JSON in which only the passes field may change.
What a strong answer covers
- A compaction summary is written by the model and may not pass clear instructions on; the files and git history are explicit, durable and inspectable state outside any context window.
- Routine: pwd, read the progress log and git log, read the feature list and choose the top unfinished feature, run init.sh to start the server, run a basic end-to-end test; this costs few tokens and reconstructs what matters.
- One feature per session prevents the one-shot failure: running out of context mid-feature leaves half-built, undocumented code that the next session must guess about.
- Ending with a git commit and a progress note leaves a clean, mergeable state, and git lets a later session revert a bad change.
- JSON was chosen because the model was less likely to overwrite or rewrite it than Markdown; allowing only the passes field to change keeps the spec fixed so agents cannot shrink the task by editing tests.
- Critique
The essay's evidence is a single internal demo (a claude.ai clone) with qualitative observations and no numbers, and a follow-up essay found that a harness component added for one model became dead weight on the next. Critique what the essay does and does not show, and describe an experiment that would show which parts of the harness are load-bearing for a given model.
What a strong answer covers
- No quantitative results: no completion rate, no count of features truly working, no comparison with a plain compaction loop or with human-written specs.
- The success signal is mostly the agent's own feature list and tests, so it is not an independent measure; a held-out end-to-end test suite written separately is needed.
- One domain (full-stack web apps) and one model generation; the essay itself lists other domains and single- versus multi-agent designs as open.
- Staleness: the follow-up says context resets fixed context anxiety on Sonnet 4.5 but were unnecessary on Opus 4.5, and Opus 4.6 no longer needed sprint decomposition, so conclusions are tied to a model.
- Experiment: remove one component at a time, run several seeds per arm, score with an independent test suite, and repeat the whole grid on at least two model versions.
- What if…
Design a component ablation of this harness. List the arms, the metrics that separate the essay's four failure modes (declaring victory early, leaving bugs or undocumented progress, marking features done without testing, rediscovering how to run the app), and the controls needed so that the result can be trusted.
What a strong answer covers
- Arms: full harness; minus feature list; minus progress log; minus git commits; minus init.sh and smoke test; minus browser end-to-end testing; minus the one-feature rule; plus a plain compaction loop as baseline.
- Metrics: features truly passing on a held-out end-to-end suite; false-pass rate (flag true but held-out test fails); sessions until the agent stops versus features remaining; regressions found at session start; tokens or time spent before the first edit in each session.
- Each failure mode maps to one component, so a well-designed ablation should show the matching metric degrade when that component is removed.
- Controls: same spec and model, same total token or session budget, several seeds, and graders the agent cannot see or edit.
- Repeat on more than one model, since the follow-up essays show components can stop being load-bearing as models improve.
- Design
Adapt this harness to a deep-research agent answering hard BrowseComp-Plus questions over its fixed corpus, where a single question can need more searching than one context window holds. Specify what the initializer writes, what each research session reads and writes, the equivalent of the end-to-end test, the stop rule, and how you would evaluate whether the harness helps.
What a strong answer covers
- Initializer: decompose the question into a JSON list of constraints or sub-questions, each with a resolved flag set to false, plus an empty evidence log and a fixed search and get-document tool setup.
- Each session reads the log and the constraint list, works on one unresolved constraint, records supporting document ids and short notes, and flips only that constraint's flag.
- End-to-end check: at session start, re-check the current candidate answer against all resolved constraints using the cited documents, to catch earlier errors before new work.
- Stop rule: answer only when every constraint is resolved with cited evidence (or a budget limit is reached), instead of letting the agent decide it is done.
- Evaluate against a single agent with compaction at equal token budget: accuracy, evidence recall against the corpus relevance judgments, false resolutions and tokens per correct answer.
- Connect
The harness forbids coding agents from removing or editing tests, enforced only by strongly worded instructions, while the later Managed Agents design keeps credentials out of the sandbox entirely. Connect this to reward hacking in RL-trained coding agents, and propose how to enforce the same constraint when training an agent with a test-based reward.
What a strong answer covers
- Editing or deleting tests is a classic way to raise a test-based reward without solving the task; work on reward hacking (for example ImpossibleBench) measures exactly this behaviour.
- A prompt instruction is a soft constraint that a capable or reward-pressured policy may ignore; the JSON-only-passes rule reduces but does not remove the risk.
- Managed Agents shows the structural alternative: put what must not be touched outside the agent's reach, as it does with credentials held in a vault.
- For training, run the reward tests from a copy outside the sandbox, make spec files read-only, and score on held-out tests the policy never sees.
- Also log and penalise writes to test or spec files, and audit trajectories, since hacks that pass the tests can still appear.