The long-running agent problem

AI coding agents are now good enough to do real engineering work. They are not yet good at doing a lot of it in a row. A real project, or one large epic, is hundreds of hours of agent work spread over many separate contexts. Over that distance three things fall apart at once: the quality of the agent's reasoning, the faithfulness to what the human actually wanted, and the budget. This page is about that problem, what the field has tried, why it breaks, and a design we built and partly tested to get around it.

Context: we build a real product (a published mobile app) with Claude Code on a flat-rate Claude Max plan, plus OpenAI's Codex as a second reviewer. Everything here is grounded in public research, our own measured runs, and live tests. Estimates are labelled as estimates.

The shape of the problem

An agent does all its thinking inside a context window: the instructions, every file it read, every command output, and its own reasoning, all re-sent to the model on every single step. That window is the agent's working memory, and it behaves badly in three ways that compound:

It degrades as it fills

Reasoning quality drops as the window grows, long before it is full. A long task is a slow slide in quality, not a cliff.

It forgets when squeezed

When the window fills, it is summarized ("compaction"). Summaries keep instructions and lose the specifics: which files changed, which decisions were made and why.

It costs more every step

Each step re-reads the whole window. A long-lived agent's cost grows roughly with the square of its lifetime, even with prompt caching.

On top of the memory problem sit two more: verification (an agent's own "done" is not reliable) and coordination (splitting work across many agents creates new failure modes and multiplies cost). Finally there is the human: someone has to define "right" and judge the parts no test can.

What the evidence says

ForceEvidence
Context rotChroma tested 18 models: every one got worse as input grew, and a focused 300-token prompt beat the full 113k-token version. Du et al. (EMNLP 2025): length alone cost 13.9% to 85% accuracy even with perfect retrieval, well inside advertised windows. Laban et al. (2025): the same task spread over many turns lost 39%, and models "get lost and do not recover". Practitioners report degradation at 20-50% of a 1M window.
Lossy compactionFactory scored three vendors' compaction on 36,611 real messages: instruction-following survived (about 4.9 / 5), tracking which files were touched did not (about 2.2 / 5). Codex users report lost "recent decisions... rejected approaches" and repeated finished work after compaction.
Unit sizeMETR's time-horizon measurements: Claude Opus 4.6 completes 12-hour tasks at 50% reliability, but only about 1.2-hour tasks at 80%. Reliable work units are small: about one to two senior-developer hours.
Green is not rightMETR: 38% of agent pull requests passed their tests and 0% were mergeable as-is. ImpossibleBench: when Claude models cheat on an impossible task, over 79% of the time they do it by editing the tests; making tests read-only blocks it. TDFlow: with supplied human-written ground-truth tests, 88.8% on SWE-bench Lite and 94.3% on Verified; with agent-written tests, 69.8% on Verified. This comparison shows the importance of test quality, not the effect of locking alone.
Soft judgesAnthropic's own evaluator agent found bugs and then "talked itself into approving" them; OpenAI's coding agent "was willing to be bullied by the PR reviewer". Cognition (2026): a reviewer that shares no context with the writer catches about 2 bugs per PR, 58% of them severe.
CoordinationMAST (1,600+ traces, 7 frameworks): role-based multi-agent systems such as MetaGPT and ChatDev fail 41-87% of the time; the biggest cause is the specification (about 44%). Google/MIT: independent agents amplify errors 17.2x, a central coordinator 4.4x; on step-by-step tasks every multi-agent variant scored 39-70% worse than a single agent.
CostMulti-agent systems use about 15x the tokens of a chat (Anthropic), about 12x (Factory missions), about 7x (Claude Code agent teams). Nobody reports multi-agent saving tokens.

What others have tried, and where each breaks

ApproachWhoWhat worksWhere it breaks
Bigger context windowsEvery vendor (1M-token models)More fits before compactionRot starts long before the window is full, and every step still pays for everything held. A bigger window delays the problem and raises the bill.
Summarize and continueBuilt-in compaction in every agent toolKeeps a chat goingLossy by design: decisions and file state are exactly what gets dropped, and the summary can be confidently wrong.
Fresh-context loops ("Ralph")Geoffrey Huntley; RepoMirror (6 repos ported overnight, about 1,100 commits); many forksEvery iteration starts clean; state lives in files and git. Strong for ports and greenfield work with a clear oracle.Every iteration re-learns the codebase. Drifts on vague specs ("overbaking", invented features). Its author would not use it on an existing codebase; long runs there die on merge conflicts.
Long-running harnessesAnthropic (initializer + coding agent + feature list; later planner, generator, evaluator); OpenAI's 25-hour Codex runFresh sessions, a protected feature list, a separate evaluator. The best published pattern.Still re-learns per session. The evaluator goes soft. Built for one app from a short prompt, not for an existing product with a human's taste in the loop.
Role org chartsMetaGPT, ChatDev and similarClear division of labour on paper41-87% failure in the MAST study. Every hand-off between roles is a lossy summary; managers assume their reports know what they know.
Massive swarmsCursor (hundreds of agents, a browser in a week); Anthropic's 16-agent C compiler; Gas TownHuge throughput against a near-perfect oracle: a reference compiler, a conformance suiteTrillions of tokens, about $20k, or "thousands of dollars a month". Cursor deleted its middle layer. Day one of one Gas Town trial: "none of the PRs were good". No maintained consumer product shipped this way.
Agent teams / managed agentsClaude Code agent teams; hosted multi-agent APIsNative parallel agents with messagingAbout 7x tokens; the lead must stay alive; no nesting; built for parallel exploration, not long sequential builds.
Workflow enginesOur own earlier engine (a database-driven pipeline of agent steps)Deterministic routing; code owns the lifecycleNever completed a real sprint: 754-line prompt files, one run cancelled at $44 and 10.2M tokens, reviewers grading made-up transcripts. Hand-drawn control flow kept fighting the model.
One lead chat + helpersOur own practiceWorks: the lead hands each issue to a helper and stays leanExpensive: one epic took a flat-rate weekly quota from about 40% to 84% in roughly a day. We measured why (below).

What is wrong with the usual logic

"Context is storage"It is working memory. Anything that must survive (decisions, progress, the definition of done) belongs outside the agent: in the issue tracker, the docs and the tests.
"Fresh context fixes rot"It does, and then every fresh agent pays to re-learn the codebase. In our run a builder only reached "up to speed" at about 250k tokens of context.
"Resume the worker to keep its knowledge"Resuming can help with closely related follow-up work, but it also keeps the debugging history. A prepared seed lets later workers inherit the shared groundwork without inheriting another worker's whole implementation history.
"More agents, more speed"Throughput is capped by the quality of the checks and by coordination overhead. More roles add more lossy hand-offs.
"The reviewer will catch it"Only if the reviewer did not share the writer's context and cannot be argued with. Self-review and friendly review are weak.
"Formalize the process"Long procedures in prompts made our agents "slower and dumber" (one team saw the same with a 1,500-word prompt vs 103 words). Smart agents need goals, standards and hard limits, not scripts.
The reframeSeparate three things that every approach above mixes together. Knowledge (what an agent needs to know about the codebase) is stable and shareable, so learn it once and share it cheaply. Work (what an agent does on one task) should be fresh, small and disposable. Truth (what "done" means, what was decided, where we are) lives outside every agent, in the issue tracker, the docs and locked tests.

Measuring a real run

We ran one real epic (adding multiple languages to our app) with one lead chat handing work to helpers, then read every transcript from disk: 44 helpers and about 5,700 model calls over about 21 hours. Cost is in input-token equivalents at the API's price ratios (cache read 0.1x, cache write 1.25x, output 5x).

0.4%of cost was the lead chat. Keeping the lead out of the work does work.
~10%was builders getting up to speed before their first edit.
76%came from steps taken while a helper held over 300k tokens.
31%was full cache rewrites after a 5-15 minute pause.
37%was two long-lived middle-manager helpers.

Where the cost went, by how much the helper was holding

Share of total cost across 5,683 model calls. Every step re-reads the whole context.
Under 100k
100k - 300k
300k - 500k
Over 500k
  • Long-lived helpers were the cost, not startup: they ended at a median 316k and up to 816k tokens, after 200-375 steps each.
  • Short cache lifetimes were the second cost. Helper caches expired after 5 idle minutes; a long test run or a manager waiting on its builders meant re-writing the whole context. We moved helpers to a 1-hour cache.
  • The middle layer was the most expensive agent, because it did hands-on work, held 700-800k, and paid rewrites while waiting.

Replaying the real traces

The obvious fix, "cap each helper's context and restart fresh", seemed sound. We replayed all 26 builders' step-by-step histories under different rules before trusting it:

Builder cost under different rules (as it ran = 100)

Replay of the real traces, 1-hour cache in every case. Lower is better.
As it ran
Cap + fresh restart
Every builder a fork
Fork + re-fork past ~100k

Fresh restarts lose because getting up to speed is expensive (about 71k at startup, 65k of command and file output, the rest reasoning). Forks win because they start up to speed and read that knowledge from cache at a tenth of the price. That is what pointed us at forking a shared, primed knowledge base.

What we proved about forks

Test (Claude Code 2.1.289)Result
Do desktop-app chats support forks?No Fork mode is off in desktop sessions ("Agent type 'fork' not found"); one environment setting turns it on.
Can a regular helper fork itself?Yes With fork mode on, its fork returned a codeword only that helper knew. Forks cannot fork again.
A static seed: prime a session once, fork it many times (claude -p --resume <seed> --fork-session)Yes Every fork knew everything the seed knew and nothing from its siblings. The seed never changes.
Is starting a fork cheap?Yes Forks of a seed that had read a 39 KB report read 55.8k tokens from cache and wrote about 290 new ones, then answered without re-reading.
Refreshing the seed by teaching one fork the newsYes Forks of the refreshed seed knew both the original and the update (56.3k read from cache, about 300 written); forks of the old seed did not.

How the design emerged

Research

Build the oracle before the swarm

Every verified big swarm had a near-perfect judge to check against. Results track the quality of the checks, not the number of agents.

Dead ends

Runners, engines, org charts

A scheduled-task runner stalled on permissions; our old workflow engine had never finished a sprint; deep org charts are the most-studied way multi-agent systems fail.

Turning point

Stop formalizing

"We're trying to formalize something that may not need to be formalized."The product owner

A smart agent with a good brief already orchestrates itself. What survived were a few plain rules. Our first unattended rules ("ambiguity is a blocker, stop and ask") would have stopped the agent 45 minutes in; fewer, plainer rules won.

Measurement

The numbers, not opinions

The real run worked but was expensive; the transcripts showed why, and the replay overturned our first fix.

Design

Static seed, refresh, per-wave architect

The product owner proposed a primed seed that never changes, refreshed by teaching one fork, and argued for a project-manager agent per wave. Live tests confirmed the mechanics.