Claude Code cannot keep every part of a long conversation in view at once. An AI's context window is the amount of information it can read and reference at any one time. As a conversation approaches that limit, Claude Code summarizes earlier material, and information that existed only in the conversation can be left out in the process. Yet Anthropic built this same tool to handle work that runs for hours. How does Claude Code keep going despite that constraint?
Looking at the documentation alongside the tool's actual behavior, the answer is not to keep piling every piece of information into the context window. It is to leave necessary information outside the conversation and reload it when needed. Compaction leaves a handoff for the next stretch of work, task tracking and memory preserve state outside the conversation, and sub-agents handle large exploratory tasks in separate workspaces.
In a September 2025 engineering post, Anthropic described long-running work as a task that requires more tokens than fit in the context window, so the AI cannot see the entire task at once. Better model performance does not remove that limit. Anthropic treated it not as an edge case but as a condition to design around, and proposed three approaches: compaction, structured note-taking, and sub-agent architectures.
I also tested how the designs described in the documentation work inside Claude Code. The experiments in this article were run on July 20 and 21, 2026, on Windows 11 with Claude Code v2.1.211, using claude -p for headless execution. The official documentation was reviewed during the same period.
Long-running work depends on both the AI and the harness
The AI model that produces answers and makes decisions inside Claude Code is not the same thing as Claude Code itself. The official documentation calls Claude Code an "agentic harness" around Claude. A harness is the surrounding system that equips a model with tools, context management, and an execution environment so it can do real work.
The work cycle is simple: gather context, act, and verify the result. As this cycle repeats and the context fills up, the harness intervenes. It first clears older tool outputs. If that still does not free enough space, it summarizes the conversation.
This is where the roles of model and harness diverge. Model capability determines how well the AI handles the information in front of it. The harness determines what stays in front of the model and what can be loaded again. Even a strong model cannot recover information that has been pushed out of the context window on its own. Long-running work depends on both. This distinction is not a direct quotation from the official documentation, but it is useful for understanding the three designs.
Anthropic's engineering post repeatedly uses Claude Code as an example when describing the three approaches. It explains that compaction can be implemented by passing the conversation transcript to a model for summarization, and cites Claude Code's to-do list and CLAUDE.md as examples of structured note-taking. Anthropic's official Cookbook says Claude Code uses several of these strategies in the product. These are not merely ideas on paper; they are part of how Claude Code continues long-running work today.
Compaction turns a conversation into a handoff
When I manually ran /compact, Claude Code replaced a 122,426-token conversation in its active context with a single summary. But this was not a short prose recap of what had happened. It was a document with a consistent structure, and the same structure appeared again in other experimental sessions.
The summary included a section titled "Pending Tasks." It grouped four tasks into one completed task and three unfinished ones. After compaction, I told Claude Code not to use tools and asked what remained. It correctly named all three unfinished tasks.
The ending was even more explicit. It pointed to the absolute path of the original session file in JSONL format, telling the next model where to read the full transcript, and instructed it to continue the last task as if there had been no interruption.
Compaction did not delete the conversation and start over. It behaved more like a handoff that lets the next worker continue: what happened, what was completed, what remains, and where to find the detailed record. The original conversation was not deleted either. It remained in the session file on disk and was removed only from the context the model saw at that moment.
This result came from a single manual compaction in a session that used Fable 5 as the parent model. The summary's structure and the point at which compaction happens are not guaranteed to remain the same. They may vary by version and model.
Keep indispensable state outside the conversation
The second design is simpler. If state must not disappear, do not keep it only in the conversation. Store it outside the conversation and reload it when necessary.
Tasks worked this way. The four tasks in the earlier experiment appeared to survive because they were represented well in the summary. But when I called the task-list tool (TaskList) immediately after compaction, all four tasks returned with their states intact. The session record also showed that Claude Code reloaded the task tool's schema—its definition of how to use the tool—after compaction. The task state itself lived outside the conversation transcript. If the summary is a handoff, the task list is a ledger preserved separately from it.
Memory followed the same principle. According to the official documentation, Claude Code's auto memory consists of notes that Claude writes for itself. At the start of each session, Claude Code loads the first 200 lines of the index file, MEMORY.md, up to 25 KB. To test this path, I planted a fabricated detail in MEMORY.md: a command called make zephyr-check. After compaction, I prohibited tool use and asked about it. Claude Code recalled the planted detail correctly.
That result alone could not show whether the memory survived because it was included in the summary or because it re-entered through a separate path. The /context screen distinguished the two. A comparison of the /context screens before and after compaction showed Messages falling from 100.4k tokens to 11k, while Memory files stayed unchanged at 1.2k. The memory had not been folded into the summary; it entered the context through a different channel. As the previous article showed, Claude Code also reloads CLAUDE.md from disk after compaction.
The official documentation's table of "what survives compaction" shows the same structure. It classifies the project's CLAUDE.md and auto memory as "reloaded from disk." By contrast, it says a rule scoped to a particular path stays out of context until Claude Code reads a file under that path again. The table does not list the task list separately. This experiment revealed one more behavior that the documentation's table does not cover.
The task and memory results were also observed once in the same session. They cannot be treated as guarantees about automatic compaction or other models. Still, keeping state outside the conversation works independently of how well the summary happens to be written.
Move large exploration tasks into another workspace
The third design prevents bulky information from entering the parent conversation's context in the first place. Claude Code can delegate large exploration tasks to a sub-agent. A sub-agent is another Claude that works in its own context, separate from the parent, and returns a summarized result.
When I asked an exploration sub-agent (Explore) to read two large files in full, it used about 96,300 tokens in its own context. It returned a 2,429-character report to the parent conversation, adding only about 1,440 tokens to the parent's context. It was like asking an assistant to search through several books and receiving only a one-page report on my desk.
These numbers came from one run of that particular task. The tokens a sub-agent uses and the length of its report will vary with the work it receives.
The sub-agent's full work record does not disappear. It is saved in a separate file at subagents/agent-<id>.jsonl under the session directory. Because this record is separate from the parent conversation, compacting the parent does not affect it. A sub-agent also compacts its own context when it fills up. The documentation describes this separation of contexts as one reason sub-agents support long-running sessions.
AI chooses what to summarize; structure protects state
The three designs do not preserve everything. What survives falls into two distinct layers.
CLAUDE.md and memory files are reloaded from disk. Task state is stored separately from the conversation, and a sub-agent's work record remains in its own file. This information is protected by the harness's structure. Its survival does not depend on whether the summary happened to capture it well.
Information that exists only in the conversation, on the other hand, is left to the AI that writes the summary. In the Haiku 4.5 experiment described in the previous article, automatic compaction omitted both an agreed-upon keyword and a decision that had existed only in the conversation. Whether a conversational detail survives is still a choice, not a guarantee.
These Fable 5 results came from a single manual-compaction experiment. They should not be generalized to automatic compaction or other models. Even so, the distinction is clear: what the AI chooses to summarize may vary, but a structure that preserves tasks and memory outside the conversation does not depend on the summary's contents.
Designing a harness means deciding where AI judgment is acceptable and where it is not. Let the AI write the handoff, but do not let indispensable state depend on that judgment. The official documentation explains that performance can decline as the context window fills because the AI may begin to miss earlier instructions. That is why all three designs—compacting, recording state elsewhere, and delegating work—point toward conserving context.
Keep the source on disk and use the conversation as a workspace
The three designs look like separate features, but they follow the same principle. Keep the source material on disk and use the conversation as a workspace that lays out the information needed right now.
Compaction clears the workspace while leaving a handoff and the location of the original record for the next stretch of work. Tasks and memory are recorded outside the conversation from the start and reloaded when needed. Sub-agents handle bulky exploration in separate workspaces and return only summaries to the parent.
The previous article recommended putting important information in files instead of leaving it only in the conversation. That is both a practical way to use Claude Code and a design principle Anthropic has built into the product. Keep indispensable plans and decisions in files, tasks, and memory, and delegate large explorations to sub-agents. Then the information that matters in long-running work rests on structural guarantees rather than the summarizer's choices.
The ability to sustain long-running work does not come from holding every piece of information inside the context. It comes from having a structure that can load the right information again.