Answer: Context is consumed by the system prompt, CLAUDE.md files, tool definitions, conversation history, and skill descriptions, with large tool outputs consuming significant context. When the context window approaches its limit, the SDK automatically compacts the conversation by summarizing older history to free space while keeping the most recent exchanges and key decisions intact. Status: Confirmed Entry: tool/claude-code/memory-and-context/context-window-and-compaction Revision: 2 Digest: sha256:89c0d43d7ae74ecc (changes whenever the content changes) Timeline: Created: 2026-11-13T03:02:36Z Last changed: 2026-11-18T12:12:09Z (compaction message type: — → compact_boundary) Last verified: 2026-11-20T12:16:15Z Next check: 2026-11-21T12:16:15Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of context consumers | the system prompt, tool definitions, conversation history, tool inputs, and tool outputs | [1] | 2026-11-20 large tool outputs | thousands of tokens in a single turn | [1] | 2026-11-20 compaction trigger | When the context window approaches its limit | [1] | 2026-11-20 compaction behavior | summarizes older history to free space, keeping your most recent exchanges and key decisions intact | [1] | 2026-11-20 compaction message type | compact_boundary | [1] | 2026-11-20 manual compaction command | /compact | [1] | 2026-11-20 Sources: [1] Anthropic. "How the agent loop works". https://code.claude.com/docs/en/agent-sdk/agent-loop.md Role: primary. Accessed: 2026-11-20T12:16:15Z Quote: "Everything accumulates: the system prompt, tool definitions, conversation history, tool inputs, and tool outputs." (Supports: context consumers) Quote: "Reading a big file or running a command with verbose output can use thousands of tokens in a single turn." (Supports: large tool outputs) Quote: "When the context window approaches its limit, the SDK automatically compacts the conversation" (Supports: compaction trigger) Quote: "it summarizes older history to free space, keeping your most recent exchanges and key decisions intact" (Supports: compaction behavior) Quote: "The SDK emits a message with `type: "system"` and `subtype: "compact_boundary"` in the stream when this happens" (Supports: compaction message type) Quote: "Send `/compact` as a prompt string to trigger compaction on demand." (Supports: manual compaction command) Published: 2026-11-20T02:53:15Z Snapshot SHA-256: 55a463c38057a4f24a8c6ffe8eb4984a5285d0e3eda21f982a81cc193bb4ad5b (captured 2026-11-20T12:16:13Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. Cross-check: not-available at 2026-11-20T12:16:15Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:16:15Z Last attempt: 2026-11-20T12:16:15Z Notes and limitations: Extracted automatically from a single official source (section "The context window"). Related: https://latestn.com/tool/claude-code/memory-and-context/context-window-full What happens when the Claude Code context window fills up? https://latestn.com/tool/claude-code/memory-and-context/disable-added-context-reminders How do I turn off the extra context reminders Claude Code adds outside the system prompt? https://latestn.com/tool/claude-code/memory-and-context/enable-disable-auto-memory How do I enable or disable auto memory in Claude Code? https://latestn.com/tool/claude-code/memory-and-context/check-session-context-usage How can I check my own Claude Code session's context usage? https://latestn.com/tool/claude-code/memory-and-context/choose-instruction-files How do I choose which CLAUDE.md or AGENTS.md instruction files Claude Code loads? https://latestn.com/tool/claude-code/memory-and-context/claude-md-load-locations-sdk Where does the Claude Code SDK load CLAUDE.md files from? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-18T12:12:09Z | changed | compaction message type: — → compact_boundary | [1] 2026-11-18T12:12:09Z | changed | compaction boundary message: compact_boundary → — | [1] 2026-11-13T03:02:36Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/memory-and-context/context-window-and-compaction/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-code/memory-and-context/context-window-and-compaction POST: https://latestn.com/dispute/tool/claude-code/memory-and-context/context-window-and-compaction with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/memory-and-context/context-window-and-compaction?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). What consumes context in the Claude Code agent loop and how does automatic compaction work? Revision 2, last verified 2026-11-20T12:16:15Z. https://latestn.com/tool/claude-code/memory-and-context/context-window-and-compaction (accessed 2026-11-21T09:59:18Z). @misc{LatestN_tool_claude_code_memory_and_context_context_window_and_compaction_r2, title = {What consumes context in the Claude Code agent loop and how does automatic compaction work?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/memory-and-context/context-window-and-compaction}}, note = {Revision 2; digest sha256:89c0d43d7ae74ecc; last verified 2026-11-20T12:16:15Z; accessed 2026-11-21T09:59:18Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-code/memory-and-context/context-window-and-compaction