Curriculum › Agentic Architecture & Orchestration · 27% of the exam

Session state, resumption, and forking

What you’ll be able to do

  • Use —resume to continue a named investigation session across work sessions
  • Use fork_session to create independent exploration branches from a shared analysis baseline
  • Choose between resuming (prior context mostly valid) and a fresh session with an injected structured summary (prior tool results stale)
  • Tell a resumed session which specific files changed so it re-analyzes them instead of re-exploring everything

What you need to know

A session is accumulated context

Over a long investigation, a session builds up a lot: files read, searches run, tool results, hypotheses ruled out, conclusions reached. That accumulated context is valuable — rebuilding it costs time and tokens — but it's also a snapshot of the world at the moment each tool ran. Managing sessions well means knowing when to carry that context forward, when to branch it, and when to leave it behind.

Named resumption with —resume

Give long-running investigations a name and you can return to them across work sessions. --resume <session-name> continues that specific prior conversation, with its history intact, rather than starting a blank one or picking up whichever session ran last.

continuing a named investigation the next morning
$ claude --resume payments-timeout-investigation > Picking up from yesterday: continue tracing why the retry wrapper swallows the gateway timeout.

Resumption is the right choice when the prior context is mostly still valid: nothing important has changed, and the agent's earlier reads and conclusions still describe the code as it is.

When code has changed: say exactly what changed

The agent's earlier tool results don't update themselves. If you edited retry.py and gateway_client.py overnight, the resumed session still "remembers" the old versions and may reason from them confidently. So when you resume after modifications, tell the agent which files changed and what kind of change it was, and ask it to re-read those files:

before — resumed with no notice of changes
> Continue the investigation.
after — targeted re-analysis
> Since we last spoke I changed retry.py (backoff now caps at 3 attempts) and gateway_client.py (timeout raised to 10s). Re-read those two files, update any conclusions that depended on them, then continue.

This is targeted re-analysis: the agent refreshes what's stale and keeps everything else. The alternative — asking it to re-explore the whole codebase — throws away valid context to fix a problem in two files.

Fresh session with a structured summary

Sometimes most of the prior context is stale: a large refactor landed, files were moved or rewritten, and the old tool results now describe code that no longer exists. Resuming that session means the agent reasons over a history full of outdated reads, and the notes about which parts changed would be longer than what's still true.

In that case, starting a new session with a structured summary injected at the start is more reliable. Carry forward the durable conclusions — the goal, what was established, what was ruled out, open questions — and let the agent gather fresh tool results on the current code.

structured summary to start a fresh session
Goal: find why checkout requests time out under load. Established: timeouts occur only when the payment gateway retries; DB is not the cause. Ruled out: connection pool size, slow queries (checked before refactor). Changed since: payments module refactored into payments/client and payments/retry. Open: does the new retry path still swallow gateway timeouts? Start by reading payments/retry and payments/client.

The decision rule:

  • Resume when prior context is mostly valid — and name any specific files that changed.
  • Start fresh with an injected summary when prior tool results are largely stale.

fork_session: branches from a shared baseline

Sometimes you want to explore two different approaches from the same starting understanding — compare two testing strategies, or two refactoring approaches, after the agent has already analyzed the codebase. Doing them one after the other in the same session contaminates the comparison: the second approach starts with the first approach's edits, conclusions, and dead ends in its context.

fork_session creates an independent branch from the current session. Each fork starts with the shared analysis baseline and then diverges on its own. What one branch does or discovers after the fork doesn't appear in the other. You pay for the codebase analysis once and get clean, parallel explorations from it.

one analysis, two independent branches
base session: map billing module, dependencies, current test coverage ├─ fork A: strategy = unit tests around pure pricing functions └─ fork B: strategy = integration tests through the invoice API compare A and B results; neither saw the other's work

Key concept

Resume a named session when its context is still mostly valid, and tell it which files changed for targeted re-analysis. Start fresh with a structured summary when prior tool results are stale. Use fork_session to branch independent explorations from a shared baseline.

When a scenario has an agent confidently describing code that has since changed, the issue is stale context: either inform the resumed session about the specific changes, or start fresh with a summary if most of it is out of date.

Practice scenario

ScenarioA developer spent Monday in a session analyzing a legacy inventory service. On Tuesday a teammate merged a refactor that split the service into four new modules and deleted the old files. The developer resumes Monday's session and the agent keeps referencing functions that no longer exist. The developer also wants to compare two migration strategies built on the same understanding of the service.
Work it through, then open this

Most of Monday’s tool results are now stale — the files they describe are gone — so resuming is the wrong choice. Start a new session with a structured summary of the durable findings (goals, conclusions, open questions, what changed) and let the agent read the new modules. Once that fresh baseline analysis is done, use fork_session to create two independent branches, one per migration strategy, so each explores from the same baseline without inheriting the other’s work.

Build exercise — Resume, refresh, and fork

Intermediate · 30 min

What you’ll learn

  • Running named investigation sessions with —resume
  • Choosing between targeted re-analysis and a fresh summary-seeded session
  • Comparing approaches with fork_session
  1. Start a named investigation session on a small codebase, have the agent analyze a module, then end the session. Make a small edit to one file it read, and resume with --resume <session-name>, naming the changed file and what changed.

    • Why: Resumption keeps valid context; naming the change limits re-analysis to what’s actually stale.
    • You should see: The agent re-reading only the changed file and updating conclusions that depended on it.
  2. Now make a sweeping change (move or rewrite most files the agent read). Write a structured summary of the session’s durable conclusions and start a new session with it instead of resuming.

    • Why: When most tool results are stale, a fresh session with a summary is more reliable than a history full of outdated reads.
    • You should see: The agent working from current code without referencing deleted or moved files.
  3. From a session that has finished analyzing the codebase, use fork_session to create two branches, each pursuing a different testing or refactoring strategy.

    • Why: Forks share the baseline analysis but diverge independently, so the comparison is clean.
    • You should see: Two branches whose later work doesn’t reference each other.

Exam traps

Resuming a session after code changes without telling the agent what changed

The agent’s earlier tool results reflect the old code. Tell it which files changed so it re-analyzes them.

Resuming a session whose tool results are largely stale instead of starting fresh with a structured summary

When most of the history is outdated, a new session seeded with a summary of durable conclusions is more reliable.

Forcing a full re-exploration when only a few known files changed

Targeted re-analysis of the changed files keeps the valid context and costs far less.

Comparing two approaches one after the other in a single session, so the second inherits the first’s edits and reasoning

Use fork_session to give each approach its own independent branch from the shared baseline.

Starting every work session from scratch and rediscovering context that was still valid

If prior context is mostly valid, resume the named session rather than rebuilding it.

Expecting forked branches to stay in sync or share later discoveries with each other

Forks are independent after the branch point; each sees only the shared baseline and its own work.

Sources

Quick check

A coordinator needs results from three independent search subagents, each covering a different subtopic. Logs show it emits one Task call, waits for the result, then emits the next, so each request takes about three times as long as a single search. What change best addresses the latency?