Skip to content
The AI Agent Factory

26.7 When to start a fresh session

Approved by
Panaversity ·
16 min read

In everyday life. A student works a long math problem on one sheet of paper. After an hour the sheet is full of crossed-out lines, and the student keeps copying a wrong number from the middle of it. Fixing the sheet again will not help. The student takes a clean sheet. That is safe on one condition: the question and the results that were checked are copied at the top of the new sheet first. With them, the clean sheet is faster. Without them, the student starts the whole problem again.

What you will learn. You practice this in Lab 26, Task 6, where the second run starts in a fresh session.

  • What are the criteria for starting a fresh session?
  • What makes a fresh session safe?
  • Who decides, when nobody is watching the run?
  • When is clearing or a summary the better move?

Why it matters. Starting again is the one fix that removes everything in the window at once. It is the strongest fix when what lives outside the window is ready, and the most expensive when it is not.

At work. On Monday, May 3, 2027, at 8:40 a.m., you have a failed check and Friday's conversation still saved. One choice is to send the failures back to that session, as Lab 23's loop does for the morning triage. But the trace shows why the invoices failed: the summary dropped "for each", so the session no longer holds the rule. A correction would be one more message in a history that the next summary replaces. You start a fresh session. On Friday that would have meant every invoice again, because no decision was written anywhere. After the rule and the progress file have a home, a fresh session reads both and continues from the next invoice.

What are the criteria for starting a fresh session?

There are three: a new task, rules that keep being broken, and a summary that has lost a rule. A fresh session still gets the instructions, the tools, and whatever your code or the worker reads in from outside. In a coding agent you start a fresh session with one command (/clear), as in 12.5. In your own loop it is a new, empty copy of the conversation. On a hosted platform it is a new session: "Each Managed Agents session starts with a fresh context by default."1

The exam guide names "criteria for starting a fresh session" as one of its techniques for a long session. These are the criteria, each with what shows it:

CriterionWhat shows it, with nobody watchingWhy a fresh session fits
A new taskThe request is not about the work the history holds"Every request sends the whole conversation", so the old task is read again, and paid for again, on every turn of the new one2
Rules that keep being brokenThe check by code fails again after two correctionsThe rule is in the window and is not being followed. More words in the same window add to the cause
A summary that has lost a ruleThe trace shows the first failure straight after a summary eventThe rule is no longer in the window. Chapter 24 named this failure context loss (24.7)

For the second criterion, Claude Code's own guidance gives a number: "after two failed corrections run /clear and write a better prompt instead of a third."2 Lab 23's loop has the same limit. It sends a failure back at most twice, then stops (23.16).

A full window is not a fourth criterion. It means the choice was made too late. If the model reaches the limit of its window while writing, the loop ends (26.2). A summary cannot rescue it, because a conversation "must still fit the model's context window, so compact before you outgrow it, not after."3 What is left is a fresh session, which is why what lives outside the window must be ready before the run and not after it.

What makes a fresh session safe?

The instructions and the progress file are enough to start again. Test it with one question before the run: could a new session, given only those two, finish the work and pass the check? If yes, a fresh session loses nothing but evidence, and the connector returns that again.

The rules arrive whole, because every request carries the instructions. The state of the work arrives if the last decision was written before the old session ended. The memory tool's pattern asks for exactly that: "Before a session ends, it updates the progress log".4 And the request arrives because the progress file opens with it, word for word (26.6).

This is 12.5's handover file, written a different way. Ana Morales, Brightline's AP analyst, asked for her notes at the end, because she was there to ask. A worker that nobody watches writes them as it goes, since nobody knows which turn will be its last.

Who decides, when nobody is watching the run?

The builder's code decides, from the check and the trace. Each criterion above is written as something code can read: a failed check, a count of corrections, a summary event followed by a failure.

Then the builder turns the reading into a rule for the outer loop, the code that starts each session and checks its result (23.16). The rule says that after two failed corrections, the loop stops sending messages to that session. It starts a fresh one from the instructions and the progress file.

When is clearing or a summary the better move?

When the session is still following its rules, and only its size is the problem. A fresh session has a price. It fetches all its evidence again, with a second call for each record, which may have changed since (26.3). Anything that was neither a rule in the instructions nor a line in the progress file is gone for good.

Figure 26.4 puts the three moves in order, by what each one needs outside the window.

Figure 26.4. Three ways to continue from a long session. Each is safe only for what already lives outside the window.

The size of the window does not decide the choice (26.1).

The operating rule: start a fresh session for a new task, after two failed corrections, or when a summary has lost a rule. Do it only when the instructions and the progress file are enough to start again.

Do this now. Ask your coding agent to test whether your own session could be started again. Copy this line:

Say whether a fresh session could finish this task from the project's instruction file and one handover file alone. List what it would be missing: each rule that was only said in this conversation, and each decision that is written nowhere. Then say which of three things is true now: this is a new task, a rule has been broken after two corrections, or a summary has dropped a rule. Change no file.

Check yourself

Question 1 / 8

0 answered

Which of these is one of the three criteria for starting a fresh session?

  1. Using agent memory, Claude Managed Agents, Anthropic.↑
  2. Best practices for Claude Code, Anthropic.↑↑2
  3. Compaction on demand, Anthropic.↑
  4. Memory tool, Anthropic.↑
Owner
Panaversity