How the agent loop works changedagent-sdk/agent-loop
Nearest release: v2.1.334, published 6 hours before upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 2 Dec 2026 01:01 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 2 Dec 2026 01:07 UTC.
Upstream edited
Recorded here
Lines+1added
Lines−1removed
From line
259
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits33to this page, all time
The whole hunk
from line 259, old and new numbered
/
from line 259
259259
260260### Automatic compaction
261261
262When the context window approaches its limit, the SDK automatically compacts the conversation: it summarizes older history to free space, keeping your most recent exchanges and key decisions intact. The SDK emits a message with `type: "system"` and `subtype: "compact_boundary"` in the stream when this happens (in Python this is a `SystemMessage`; in TypeScript it is a separate `SDKCompactBoundaryMessage` type).
262When the conversation approaches the [auto-compact window](https://code.claude.com/docs/en/model-config.md#default-auto-compact-thresholds), the SDK automatically compacts it, summarizing older history to free space and keeping your most recent exchanges and key decisions intact. The SDK emits a message with `type: "system"` and `subtype: "compact_boundary"` in the stream when this happens. In Python this is a `SystemMessage`, and in TypeScript it is a separate `SDKCompactBoundaryMessage` type.
263263
264264Compaction replaces older messages with a summary, so specific instructions from early in the conversation may not be preserved. Persistent rules belong in CLAUDE.md (loaded via [`settingSources`](https://code.claude.com/docs/en/agent-sdk/claude-code-features)) rather than in the initial prompt, because CLAUDE.md content is re-injected on every request.
265265
No line in this hunk matches that.