The four levers of a long session
A session that runs long rests on just four levers: the cache, which reuses a stable prefix, clearing out stale tool outputs, compaction, which summarises the history, and partitioning, which delegates bulky work to isolated sub agents.
A Claude Code session that runs for several hours does not endlessly swell the same block of text sent to the model with every message. Four distinct mechanisms limit what that session drags along behind it: the cache, which reuses an identical start of conversation rather than recomputing it, clearing out tool outputs that have become useless, compaction, which replaces the history with a summary, and work delegated to sub agents, separate conversations that handle part of the task and return only their conclusion.
The cache, the sort, the summary, the delegation
The prompt cache retains the computation done on a start of conversation, called the prefix, for as long as that prefix stays identical down to the byte from one message to the next. As soon as anything changes at the very start of that prefix, everything that follows has to be recomputed. That is why position matters: general instructions and project context are best kept at the front, unmoving, while questions that change come afterwards.
Clearing out stale tool outputs, what this course calls masking, clears away the results of old calls that no longer serve the current reply, a real mechanism even though no public Anthropic documentation names it in exactly those words. Compaction, meanwhile, summarises the message history into shorter text once the conversation nears its limit, a topic covered in detail in compacting, clearing, reading just what is needed. Partitioning, lastly, hands off a portion of the work, a long search, reading several files, to a sub agent that works in its own conversation and returns only its conclusion, which avoids loading the main conversation with the detail of its search.
One single move is enough to activate the first lever
These four mechanisms do not all switch on in every session. A short conversation, that stays well clear of the context limit, triggers no compaction, and a task that requires no extensive search delegates nothing to a sub agent. The cache, by contrast, switches on from the second message of the same conversation, with no particular setting to configure, on one condition: that the start of the message stays identical.
Message 1: project instructions (identical every time) + question A
Message 2: same project instructions + question B
The second message reuses the computation already done on the project instructions, provided they have not moved by a single character between the two messages.
The four levers stacked
A colleague opens a Claude Code session in the morning and puts their general instructions in the first message. Over several hours, they then work through dozens of different questions on the same project, each sent as a new message within the same conversation.
Write, in one sentence, what this situation establishes, and in one sentence what it does not establish.
What this establishes: The first message forms a stable start of conversation that the cache can reuse as is for every new question asked within the same conversation.
What this does not establish: It does not establish that the session triggered a compaction or that part of the work was delegated to a sub agent, since both mechanisms depend on conditions not described here.
The three most common miscalibrations
- Too broad All four mechanisms, the cache, clearing stale outputs, compaction and partitioning, necessarily switched on at some point during this session.
- Too narrow Nothing can be said about this session until the exact number of questions asked is known.
- Off target The colleague dealt with several different topics in the same conversation over the course of their working day.
- A long session rests on four distinct mechanisms, the cache, clearing out stale tool outputs, compaction and delegation to sub agents, not on a single global setting.
- The prompt cache requires a start of conversation identical down to the byte to keep applying from one message to the next.
- Compaction summarises the message history once the conversation nears its limit, without changing any project files.
- A sub agent handles a portion of the work in its own conversation and returns only its conclusion to the main conversation.
- Putting the project's general instructions in the very first message is what lets the cache apply from the very next message.
Before your next long session in Claude Code, write your general instructions and the project's stable context in the very first message, then ask your follow up questions afterwards in the same conversation.
Every datable claim in this lesson links here to the public text behind it. A source that does not open proves nothing.
- Effective context engineering for AI agents consultée le 2026-09-02
- Context editing, clearing out stale tool outputs consultée le 2026-09-02
- Managing costs in Claude Code consultée le 2026-09-02