Anthropic Effective Harnesses for Long-Running Agents

As AI agents are tasked with complex projects spanning hours or days, Anthropic introduced a two-fold solution—an Initializer Agent and a Coding Agent—to ensure agents maintain consistent progress across multiple, discrete context windows.

This harness addresses the core challenge that agents must work in sessions with no memory of previous work, a limitation that simple context compaction cannot overcome for large-scale software development.

The Challenge of Long-Running Agents

Simple context compaction is insufficient for enabling AI agents to complete production-quality projects across multiple context windows. The Claude Agent SDK, even when using advanced models like Opus 4.5, exhibits two primary failure modes when given only a high-level prompt.

Agent Failure Mode 1: Over-Scoping

The agent tends to attempt to complete too much work at once, aiming for a one-shot implementation. This often results in the model running out of context mid-implementation, leaving the next session starting with a half-implemented and undocumented feature. The subsequent agent must then spend substantial time guessing the prior state and attempting to restore basic functionality.

Agent Failure Mode 2: Premature Completion

Later in a project, an agent instance may review the existing progress and prematurely declare the entire job complete, even if significant features remain unfinished.

These failures necessitate a structured approach: first, establishing a foundational environment for all required features, and second, prompting each agent to make small, incremental progress while maintaining a clean, mergeable state at the end of every session.

The Two-Fold Agent Solution

Anthropic addressed these issues by implementing a specialized two-part harness structure:

Initializer Agent

The very first agent session utilizes a specialized prompt to set up the initial environment. This setup includes creating an init.sh script, generating a claude-progress.txt file to log agent actions, and performing an initial git commit that documents the added files. This foundation ensures the agent is set up to work step-by-step and feature-by-feature.

Coding Agent

Every subsequent session is handled by the Coding Agent, which is tasked with making incremental progress toward the goal. Crucially, this agent must leave the environment in a clean state after each session. A 'clean state' means the code is orderly, well-documented, and free of major bugs, making it appropriate for merging to a main branch.

Environment Management and Workflow Details

To enforce structure and prevent the agent from making large, unmanaged changes, specific prompting and artifact management techniques were employed.

Defining Feature Requirements

To combat the tendency to one-shot the app, the Initializer Agent is prompted to write a comprehensive file of feature requirements that expands upon the user’s initial prompt. For the claude.ai clone example, this resulted in over 200 features, all initially marked as “failing.” Coding agents are then instructed to edit this feature file only by changing the status of a passes field, using JSON format to minimize the risk of inappropriate overwrites.

Ensuring Incremental Progress

Once the initial environment is scaffolded, the Coding Agent is instructed to work on only one feature at a time. To maintain a clean state, the model is prompted to commit its progress to git using descriptive commit messages and to write summaries of its progress in a progress file. This use of git allows the model to revert bad code changes and recover working states.

Implementing Robust Testing

A major failure mode observed was the agent marking a feature as complete without proper end-to-end testing. While the model can perform unit tests, it often fails to recognize bugs that are not obvious from the code alone. Performance dramatically improved when Claude was provided with testing tools, such as the Puppeteer MCP server, which allowed the agent to test features end-to-end as a human user would. This enabled the agent to identify and fix bugs that were otherwise invisible.

Operationalizing Agent Sessions

To ensure every coding agent starts in a stable and informed state, a standardized series of steps is run at the beginning of each session:

  1. Directory Check: Run pwd to confirm the working directory.
  2. State Review: Read the git logs and progress files to quickly understand recent work.
  3. Task Selection: Read the features list file and select the highest-priority feature that is not yet complete.

This startup routine saves tokens and ensures that the agent first verifies the application's state—by running the local development server and performing a basic end-to-end test—before attempting to implement new features, preventing the exacerbation of existing bugs.

Future Research Directions

While this research provides a robust set of solutions for long-running agent harnesses, several open questions remain. It is currently unclear whether a single, general-purpose coding agent performs optimally across contexts, or if a multi-agent architecture would yield better performance. Specialized agents, such as a dedicated testing agent or a code cleanup agent, are hypothesized to improve sub-task performance across the software development lifecycle. Furthermore, the current demonstration is optimized for full-stack web app development, and future work will focus on generalizing these lessons to other long-running agentic tasks, such as scientific research or financial modeling.

Sources