Claude Code --resume and Session Persistence in 2026: Picking Up Long Refactors Where You Left Off
This article was written with the assistance of AI, under human supervision and review.
Claude Code sessions accumulate context with every turn, and developers reflexively reach for claude --resume to restore that investment. The --resume flag picks up an existing session by ID and continues where it left off, preserving the full conversation history. Past a certain threshold, that preserved history becomes a liability. Session length is proportional to noise, not signal. Resuming a long session floods the model with stale environment data and buries the decisions that matter.
The broken pattern treats session duration as an asset and resumes by default. Claude reads every tool call, every file edit, every approval prompt from the entire conversation. A session that ran for three hours re-reads three hours of context on every new turn. The first 90 minutes were exploratory work that led nowhere, but the cache read cost persists. The agent struggles to locate the one decision from turn 47 that still applies, and subtly undoes a fix from earlier in the session because the correction is buried in 200 prior messages.
A long session accumulates stale context, floods the model on resume, and buries live decisions in noise
The correct pattern distinguishes session state from session conclusions. Resume when the session holds unfinished work you cannot rebuild: a goal still in progress, a plan awaiting approval, or a permission mode set deliberately. Start fresh when the session's value lies in what it concluded. Write a brief that extracts the decisions, the constraints, and the rationale, then launch a new session with that brief. The new session starts with signal and skips the noise.
A brief extracts decisions from the old session, starts a new session with clean context, and executes without stale noise
The brief-first pattern keeps session length bounded, reduces cache read costs, and surfaces the conclusions that matter. This post shows when to resume, when to start fresh, how to extract a brief, and the cost implications of session growth.
Key Takeaways
- Resume restores the full conversation, including stale context and dead-end exploration that inflates cache read costs.
- Session state (unfinished goals, pending approvals, permission modes) requires resume; session conclusions (decisions, constraints, rationale) do not.
- A brief extracts the conclusions from a long session and starts a new session with clean context, reducing noise and cost.
- Cache reads account for the majority of agentic work costs; every turn added to a session increases what future turns re-read.
- Session retention defaults to 30 days; transcripts older than
cleanupPeriodDaysare removed and cannot be resumed.
Understanding Claude Code Session Architecture
Claude Code stores sessions as JSONL transcripts under ~/.claude/projects/ (or $CLAUDE_CONFIG_DIR/projects/ when set). Each project directory holds one conversation per session ID. When you resume, Claude Code reads the entire transcript into the prompt and continues from the last message. The session lookup order searches the current project directory first, then other projects on the same machine, and finally falls back to a cross-directory ID match.
Claude Code locates the session file, reads the full transcript, and continues with the loaded context
A session that ended with error_max_turns or error_max_budget_usd can be resumed with higher limits, but the agent re-reads the entire history that led to the limit in the first place. The automatic session management APIs (ClaudeSDKClient in Python, continue: true in TypeScript) track the most recent session in the directory and resume it without manual ID handling. That convenience makes the resume-by-default trap easier to fall into.
Sessions survive machine sleep but not shutdown. A session interrupted by shutdown shows as failed if less than 48 hours have passed, or stopped if more. Attaching or replying to a stopped session resumes its saved conversation, provided transcript cleanup has not removed it. The default retention is 30 days. Past that point, the session row remains in agent view but the transcript is gone.
Claude Code session architecture
When Resume Makes Sense: State vs Conclusions
Resume when the session holds state you cannot easily rebuild. The state is the point. Start fresh when the session's value lies in what it concluded. The table shows the split:
| Situation | Action | Reason |
|---|---|---|
| Goal still in progress | Resume | The unfinished work is the state you need |
| Plan awaiting approval | Resume | The plan itself is the pending state |
| Background work didn't finish | Resume | The partial progress is not easily restated |
| Permission mode set deliberately | Resume | The mode is part of the session's setup |
| Session concluded with a decision | Start fresh with brief | The decision is a conclusion, not state |
| Exploratory work led to a constraint | Start fresh with brief | The constraint is a conclusion, not state |
| Session hit max turns on a refactor | Start fresh with brief | The transcript is now noise |
| Session ran for hours across topics | Start fresh with brief | The early turns are stale |
A decision point checks whether the session holds state or conclusions, then resumes or starts fresh accordingly
The state includes goals Claude is actively pursuing, plans awaiting your approval, permission modes you configured, and partial work that cannot be summarized. The conclusions include decisions Claude reached, constraints it discovered, and rationale it explained. Conclusions compress into a brief. State does not.
A session that ended with error_max_turns after a large refactor holds conclusions, not state. The refactor either succeeded or it didn't. The decisions that worked compress into a brief. Resuming re-reads the 300 turns that led to the limit, most of which were file reads and tool calls exploring options that didn't pan out. A new session with a brief starts with the decisions and skips the exploration.
The Brief-First Pattern: Replacing Long Sessions
A brief extracts what a session concluded and feeds that into a new session. The brief is a markdown file or a prompt. It holds the decisions, the constraints, and the rationale. The new session starts with that context and none of the stale tool output from the old session.
The pattern has three steps:
- Run the exploratory session to completion or until it reaches a natural pause
- Extract a brief of the conclusions (manually or by asking Claude to summarize)
- Start a new session with the brief as the initial prompt
The TypeScript example shows the pattern in SDK code. The first session runs a refactor and captures the session ID. The second session extracts a brief by resuming with a summary request. The third session starts fresh with that brief:
import { query } from "@anthropic-ai/claude-agent-sdk"; // Step 1: Run the exploratory session let exploratoryId: string | undefined; for await (const message of query({ prompt: "Refactor the auth module to use the new token format", options: { allowedTools: ["Read", "Edit", "Grep", "Glob"] } })) { if (message.type === "result") { exploratoryId = message.session_id; if (message.subtype === "success") { console.log("Refactor complete:", message.result); } } } // Step 2: Extract a brief let brief = ""; if (exploratoryId) { for await (const message of query({ prompt: "Summarize the decisions we made, the constraints we found, and why each change was necessary. Write it as a brief I can paste into a new session.", options: { resume: exploratoryId, allowedTools: [] } })) { if (message.type === "result" && message.subtype === "success") { brief = message.result; } } } // Step 3: Start fresh with the brief for await (const message of query({ prompt: `${brief}\n\nNow implement the remaining endpoints using these decisions.`, options: { allowedTools: ["Read", "Edit", "Write", "Grep", "Glob"] } })) { if (message.type === "result" && message.subtype === "success") { console.log("Implementation complete:", message.result); } } The brief holds the signal. The exploratory session's transcript held the signal plus 200 turns of noise. The new session starts with the signal and builds from there. The cache read cost on each turn is proportional to the brief's size, not the exploratory session's size.
An exploratory session runs to completion, extracts a brief of conclusions, and starts a new session with the brief as context
The brief can be a file you write by hand after reviewing the session, or a file Claude generates when you ask it to summarize. The manual version takes more time but produces a denser brief. The generated version is faster but sometimes includes unnecessary detail. Both work. The key is that the new session starts with conclusions, not history.
Session Management Strategies in Practice
The automatic session management APIs resume the most recent session in the directory by default. The TypeScript continue: true option and the Python continue_conversation=True option both behave this way. That default makes sense for a chat interface where every prompt is a continuation of the last. It makes less sense for agentic work where each session solves a distinct problem.
The Python example shows the difference between automatic continuation and manual session control:
// Automatic continuation: good for chat, risky for tasks import { query } from "@anthropic-ai/claude-agent-sdk"; for await (const message of query({ prompt: "Fix the validation bug in auth.ts", options: { continue: true, allowedTools: ["Read", "Edit"] } })) { if (message.type === "result" && message.subtype === "success") { console.log(message.result); } } // This continues the most recent session, which might be // a three-hour refactor from yesterday. The bug fix inherits // that session's stale context. // Manual session control: start fresh per task for await (const message of query({ prompt: "Fix the validation bug in auth.ts", options: { allowedTools: ["Read", "Edit"] } })) { if (message.type === "result" && message.subtype === "success") { console.log(message.result); } } // This starts a new session. The bug fix gets clean context. The manual approach starts a new session for each task unless you explicitly pass a resume ID. That makes session growth an intentional choice rather than a default. The automatic approach treats every prompt as a follow-up unless you explicitly start fresh. The manual approach is safer for production workflows where tasks are independent.
The fork option creates a new session that starts with a copy of the original's history. The original stays unchanged. Use fork to try a different direction while keeping the option to go back. Fork is not a substitute for the brief-first pattern. A forked session inherits the same stale context as a resumed session. The fork simply preserves the original session so you can return to it later.
Session management strategies
Cost Implications: Cache Reads and Context Growth
Anthropic's Opus 5.5 announcement states that cache reads account for the majority of agentic and coding work costs. Every turn you add to a session becomes part of what later turns re-read. The cache read cost is proportional to the session's total token count, not the new prompt's token count. A 500-token prompt sent to a 50,000-token session re-reads 50,000 cached tokens and adds 500 new tokens. The cache read cost dominates.
Each turn re-reads the full session, so cost grows with session size, not prompt size
The table compares the cache read cost of a 10-turn session, a 100-turn session, and a fresh session:
| Session size | Avg tokens per turn | Total session tokens | Cache reads per new turn | New prompt tokens | Total cost per turn |
|---|---|---|---|---|---|
| 10 turns | 2,000 | 20,000 | 20,000 | 500 | 20,500 tokens |
| 100 turns | 2,000 | 200,000 | 200,000 | 500 | 200,500 tokens |
| Fresh | 0 | 0 | 0 | 500 | 500 tokens |
The 100-turn session re-reads 400 times more tokens than the new prompt contains. The fresh session reads only the new prompt. The brief-first pattern keeps the session size bounded by extracting the conclusions and starting fresh before the session grows to 100 turns. A brief that compresses 100 turns of exploration into 2,000 tokens reduces the cache read cost by 99%.
The idle compaction feature compacts long conversations while the terminal session is idle, shortly before a one-hour prompt cache expires. Compaction is unavailable when feature-flag fetching is disabled, which includes sessions on third-party providers and sessions with DISABLE_GROWTHBOOK or CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC set. Even when available, compaction addresses cache expiry, not session bloat. A session that grew to 300 turns over three hours exceeds the cache window regardless of compaction.
Session Retention, Naming, and Deletion Workflow
Claude Code removes transcripts older than cleanupPeriodDays, which defaults to 30. A session removed by cleanup shows in agent view but cannot be resumed. The row says "This session's saved conversation is no longer on disk" when you try to open it. claude rm <id> deletes the row unless the session is running or its transcript still exists.
A session remains until it exceeds the cleanup period, then the transcript is removed and resume fails
The --name flag sets the session's display name in agent view when launching with --bg. The name appears in claude agents output and makes it easier to identify sessions later. The flag works only at launch. You cannot rename a session after it starts.
The backgrounded session dispatch workflow shows how --name combines with --bg:
// Launch a named background session $ claude --bg --name "auth-refactor" "Refactor auth module to new format" // Output: // backgrounded · 7c5dcf5d · auth-refactor // claude agents list sessions // claude attach 7c5dcf5d open in this terminal // claude logs 7c5dcf5d show recent output // claude stop 7c5dcf5d stop this session The session ID 7c5dcf5d is the short form. The full ID is a UUID. Both work with --resume. The name auth-refactor appears in agent view and makes the session easier to find when you have multiple sessions running. The name does not affect session lookup. --resume requires the ID, not the name.
The session stop and resume behavior differs depending on how long ago the session last made progress. A session that was waiting on input stays under "Needs input" after a machine restart. A session that was running shows as failed within 48 hours or stopped past 48 hours. Attaching or replying resumes the saved conversation, provided cleanup has not removed it.
Frequently Asked Questions
Does resuming a session cost more than starting fresh?
Yes. Resume re-reads the entire transcript on every turn, which shows up as cache read tokens. A 100-turn session re-reads 100 turns of context. A fresh session reads only the new prompt. The cache read cost is proportional to session size, not prompt size.
When should I use --fork instead of --resume?
Use fork when you want to try a different direction while preserving the original session. Fork creates a new session that starts with a copy of the original's history. The original stays unchanged. Fork is not a substitute for starting fresh. A forked session inherits the same stale context as a resumed session.
Can I resume a session from a different machine?
No, unless you mirror transcripts to shared storage with a SessionStore adapter. By default, sessions are stored locally under ~/.claude/projects/ and are only accessible from the same machine.
How long are sessions retained before cleanup?
Sessions are retained for cleanupPeriodDays, which defaults to 30 days. After that period, the transcript is removed and the session cannot be resumed. The session row remains in agent view but shows "This session's saved conversation is no longer on disk" when you try to open it.
What happens if I resume a session whose agent no longer exists?
The session continues with the default tools and its transcript opens with a warning naming the agent. Claude Code searches the session's own directory for the agent first, so a project-scoped agent still loads when the session is resumed from another directory, provided you've trusted that workspace.
Conclusion: Building a Sustainable Session Strategy
The brief-first pattern treats session length as a cost to manage, not an asset to preserve. Resume when the session holds unfinished work you cannot rebuild. Start fresh when the session's value lies in what it concluded. Write a brief that extracts the decisions, the constraints, and the rationale, then launch a new session with that brief. The new session starts with signal and skips the noise. Session growth is now an intentional choice tied to unfinished state, not a reflexive default.








