Long-Running Agent Harnesses (Claude SDK)
Bottom Line
Long-running agents fail because each session starts with amnesia. Anthropic’s pattern is a two-agent harness: an initializer for first run setup, then a coding agent that only makes incremental progress and leaves explicit artifacts for the next shift.
Key Takeaways
- ›Compaction keeps a single window alive; it does not solve multi-session memory.
- ›Frontier models still try to do too much in one session without harness constraints.
- ›Initializer agent owns environment bootstrap; coding agent owns incremental progress + handoff notes.
- ›Design for shift work: tests, progress files, and unfinished TODOs are the memory bus.
- ›Use this with Claude Agent SDK / Claude Code-style tool loops, not free-form chat.
Anthropic Engineering’s “Effective harnesses for long-running agents” is one of the clearest production blueprints for multi-hour / multi-day coding agents.
The problem in one metaphor
Picture a software team where every engineer starts a shift with zero memory of the previous shift. That is a multi-session agent with limited context windows. Compaction helps within a session; it does not replace a handoff protocol across sessions.
Two-agent pattern
| Role | When | Job |
|---|---|---|
| Initializer agent | First run | Set up environment, scaffolding, baselines |
| Coding agent | Every subsequent session | Incremental progress + leave clear artifacts for the next session |
Failure patterns Anthropic calls out
- Trying to do too much at once from a high-level prompt (e.g., “build a clone of claude.ai”)
- Assuming the next session will “just know” what is unfinished
- Relying on compaction as a substitute for durable project state
Implementation checklist for your harness
- Progress file — machine-readable status of milestones and remaining work
- Test gate — agent cannot mark a milestone done without automated checks
- Artifact contracts — paths and formats the next session is guaranteed to find
- Session budget — max steps/tool calls/dollars per session to prevent thrash
- Human interrupt points — especially for auth, production data, and security tools
# Pseudocode: session contract
if session.is_first:
run_initializer(setup_env=True, write_progress="PROGRESS.md")
else:
state = read_progress("PROGRESS.md")
run_coding_agent(goal=state.next_milestone, leave_artifacts=True)
assert tests_pass() or escalate_to_human()
Pair with agent evals
Anthropic’s companion thinking in “Demystifying evals for AI agents” applies directly: multi-turn, tool-using evals with environment state — not single-turn prompt quizzes — are how you know a harness change is real.