Why Is Claude Opus 5.5 Built for Long-Running AI Agents? 2026 Context, Compaction, and JSON State
Released 22 September 2026, Claude Opus 5.5 is aimed at long-running agentic coding and knowledge work: a 1M-token context window, 128K output cap, plus server-side Compaction and Context editing (for example clear_tool_uses_20250919). Finishing a long job is not about a longer system prompt—it is about what your host JSON state remembers, how tool results write back, and whether unattended loops stop on progress text.
Before you read
| Layer | Opus 5.5 / Anthropic | Host JSON |
|---|---|---|
| Context | 1M tokens default; Compaction for long threads | order_id, checklist, compaction_generation |
| Tool results | Server can clear old tool_result blocks | last_tool_use_id, awaiting, business facts |
| Continuation | Full messages[] or compaction block swap | run_id, effort, open checklist items |
| Unattended runs | end_turn may be progress, not done | Auto-continue cap + completion rule |
| vs OpenAI | Messages + compaction beta | Not Agents session_id (see that post) |
Facts through 2026-11-03: Anthropic Opus 5.5, context windows, Compaction, Context editing, prompting Opus 5.5. A-1042 and toolu_01H8 are fictional.
Long tasks need window management plus host state—not a longer prompt
Opus 5.5 fits long-running agents because Anthropic ships operational API pieces, not just raw capability:
- 1M default window holds many tool_use / tool_result turns; near the limit, Compaction summarizes older turns on the server while recent turns can stay verbatim.
- Heavy tool use can enable
clear_tool_uses_20250919to drop oldest tool results by token threshold; keep full history locally—edits apply server-side before the model sees them. - The host must own checklist and order ids. Compaction drops detail;
A-1042, approvals, and pending tool ids belong in your JSON state, not only in chat.
Messages and tool_use basics: Opus 5.5 basics. Where Harness keeps state: Harness state. OpenAI durable Sessions are different objects—see OpenAI long Session; this post does not rewrite that article.
Host state, tool write-back, Compaction, clearing tools
1. Host JSON state (business ledger). Stored apart from model messages; survives compaction:
{
"run_id": "run_a1042_01",
"model": "claude-opus-5-5",
"effort": "medium",
"order_id": "A-1042",
"checklist": [
{ "id": "lookup", "status": "done" },
{ "id": "compare_invoice", "status": "in_progress" },
{ "id": "notify_ui", "status": "open" }
],
"last_tool_use_id": "toolu_01H8",
"awaiting": "tool_result",
"compaction_generation": 2
}
2. tool_use → tool_result in Messages. Same shape across hours; align on tool_use_id:
{
"model": "claude-opus-5-5",
"max_tokens": 16000,
"messages": [
{ "role": "user", "content": "Finish the A-1042 invoice compare. Use tools." },
{
"role": "assistant",
"content": [{
"type": "tool_use",
"id": "toolu_01H8",
"name": "lookup_order",
"input": { "order_id": "A-1042" }
}]
},
{
"role": "user",
"content": [{
"type": "tool_result",
"tool_use_id": "toolu_01H8",
"content": "{\"order_id\":\"A-1042\",\"status\":\"packed\"}"
}]
}
],
"tools": [{
"name": "lookup_order",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string", "pattern": "^[A-Z]-\\d{4}$" }
},
"required": ["order_id"],
"additionalProperties": false
}
}]
}
3. On-demand Compaction (beta compact-2026-09-04). Host chooses when to request a summary block replacing earlier messages:
{
"model": "claude-opus-5-5",
"max_tokens": 8192,
"betas": ["compact-2026-09-04"],
"compaction": {
"type": "on_demand",
"keep_recent_turns": 6
},
"messages": []
}
4. Context editing to clear old tool results. For coding agents that read large files or search often:
{
"model": "claude-opus-5-5",
"max_tokens": 16000,
"context_management": {
"edits": [{
"type": "clear_tool_uses_20250919",
"trigger": { "type": "input_tokens", "value": 120000 },
"keep": { "type": "tool_uses", "value": 8 }
}]
},
"messages": []
}
Anthropic compresses the window—it does not remember your order id
Long-task failures usually mix window policy with business state. Split duties:
| Data | Anthropic / API | Host must persist |
|---|---|---|
| Full audit trail | Client messages[] (unedited) | Optional WORM log; do not trust compact summary alone |
| Context the model sees | Compaction + context_management edits | Checklist, order_id, permission decisions |
| Tool side effects | Model emits tool_use.input only | Execute + Schema gate + tool_result body |
| Task completion | stop_reason may be progress end_turn | All checklist done or explicit blocker |
If you also run OpenAI, Session / previous_response_id differ; dual-stack map: Opus vs Astra.
Five steps to finish an Opus 5.5 long task
Run fictional order A-1042 in staging before production:
- Create run_id + checklist JSON. Separate from messages; update status each turn.
- Fix effort and log it. Opus 5.5 defaults to medium; tune with your evals for latency/cost.
- Tool loop on id alignment only. tool_use.id → execute → tool_result.tool_use_id; store last_tool_use_id in state.
- Near the window, Compaction or clear_tool_uses. After compact, confirm order_id still in state.
- Unattended: treat end_turn as progress. If checklist items stay open, send a short user continue; cap auto-continues at 2–3 per task.
All five steps are JSON objects; skip one and you are betting the window never fills.
Lay state beside messages
Typical bugs: lost order id after compact, wrong tool_result id, treating progress text as success.
- Use format on messages and state; Schema validation on tool input and checklist schemas.
- Use JSONPath on state for order_id and checklist statuses; match last tool args.
- JSON Diff messages before/after Compaction; if the id drifts, check summary before blaming the model.
- Confirm awaiting and last_tool_use_id match the last content block.
- JSONSort runs locally—do not upload real repos or keys.
You are wired correctly when state alone can rebuild task progress.
Common mistakes
- Treating 1M as “no state needed.” The window still fills; Compaction drops detail.
- Keeping only compact summary as history. Audit/replay needs full messages or equivalent event logs.
- Syncing client state to server edits. Edits apply server-side; locally keep full history.
- Stopping unattended loops on end_turn. Opus 5.5 often reports progress first; continue via checklist.
- Mapping OpenAI session_id onto Messages. Different objects—see the OpenAI long-running post.
- Uncheck large JSON inside tool_result. Still Schema-gate; format then truncate display fields if needed.
FAQ
Do I still need my own summarizer on Opus 5.5?
Usually no. Server Compaction covers most cases; use context editing or client Compact only for special trimming.
Does clear_tool_uses delete my local logs?
No. It only affects context sent to the model; your DB/WORM should still store full tool results.
What about thinking blocks after Compaction?
Depends on beta path and threshold compaction. Read the Compatibility table before rewriting history or re-inserting recent turns.
Must long tasks use effort high?
No. Default is medium; Anthropic testing often shows medium matching older high on coding evals. Tune with your own benchmarks.
How does this relate to OpenAI Agents long-running?
Pick by stack: Anthropic hosts use Messages + this state pattern; OpenAI hosted loops use Agents Session. Both can coexist—do not mix session_id with tool_use_id semantics.
Conclusion
Claude Opus 5.5 fits long-running agents because 1M context plus server Compaction/context editing makes “runs for hours” an API concern; hosts still need JSON state for checklist, order ids, and tool alignment.
The model only fills JSON; compression policy and “is the task actually done” stay host decisions. Prove you can rebuild A-1042 after compact before automating.
Further reading
- Claude Opus 5.5 and tool JSON Messages, effort, tool_use
- OpenAI Agents API long-running Session, compact, subagents (contrast)
- Coding Agent Harness and JSON state Model / Harness / Tools / State
- Opus 5.5 vs GPT-6 Astra Dual-stack JSON field map
- All posts More on JSON and AI development
Changelog: First published