Claude Code, long sessions
What actually survives a long Claude Code session
People search for this because the model forgot something. A path, a constraint, a decision from two hours ago. The instinct is to blame auto-compaction and reach for a prompt trick. But a long session drops context in four separate ways, and only one of them is a prompt problem. This is the honest map of all four.
Direct answer (verified 2026-05-14)
Claude Code keeps context through a long session only partly. As a session nears the limit it auto-compacts: per Anthropic’s docs, it clears older tool outputs first, then summarizes the conversation. Your requests and key code snippets are preserved; detailed instructions from early in the conversation can be lost. The full transcript stays on disk at ~/.claude/projects/<encoded-cwd>/<id>.jsonl, but the model only ever sees the post-compaction view. And compaction is just one of four ways a long session loses context. The other three are not prompt problems at all.
A long session fails four different ways
The common advice online treats “context surviving long sessions” as a single problem with a single class of fix: tune your prompts, run /compact, lean on CLAUDE.md, target 60 percent window utilization. That advice is fine, but it only addresses one failure mode. Here are all four, sorted by whether a prompt can touch them.
The window fills and Claude Code compacts
This is the one every guide writes about. As a session runs, the context window fills with conversation, file reads, tool output, CLAUDE.md, and system instructions. Before it reaches the hard limit, Claude Code auto-compacts. Per Anthropic's docs, it clears older tool outputs first, then summarizes the conversation if needed.
Your requests and key code snippets are preserved. Detailed instructions from early in the conversation can be lost. The transcript on disk is untouched; the model's working view is not.
- Survives
- The JSONL transcript on disk, your recent turns, key code snippets.
- Lost from the model’s view
- Older tool output, the specifics of early decisions, instructions you gave once at the start.
- The fix
- Prompt hygiene genuinely helps here: /compact with a focus, a Compact Instructions block in CLAUDE.md, and pushing investigation into subagents that get their own context. This is the only one of the four modes a prompt trick can address.
You quit the app or reboot the Mac
Anthropic's docs are blunt about this: each new session starts with a fresh context window, without the conversation history from previous sessions. The JSONL is still on disk, but a fresh claude invocation does not reattach to it.
You have to remember the session existed, cd back to the directory it was created in, and run claude --continue or claude --resume <id>. Multiply that by every chat you had open when you closed the lid.
- Survives
- The JSONL on disk, under its original directory.
- Lost from the model’s view
- The live session, until you manually resume each one in the right place.
- The fix
- No prompt trick reaches this. It needs a host that records every window and reopens them on launch.
A rate limit rolls the session ID mid-run
Less known, and the one that bites hardest. When the upstream connection restarts, after a rate limit, a credit reset, or a bridge restart, the session ID you would resume can change underneath you.
A plain claude --resume <old-id> then misses, because the SDK resolves transcripts by the pair (cwd, sessionId). The old ID no longer maps to anything, the lookup throws Resource not found, and the obvious recovery path is gone even though your work is sitting safely on disk.
- Survives
- The JSONL, written under the old session ID.
- Lost from the model’s view
- The obvious resume path, because the ID you would type is stale.
- The fix
- Persist the mapping between session and directory, then resume against what is actually on disk rather than the ID you last saw.
You close the window
The mildest of the four, but still a real loss. Close a chat window and the visible transcript disappears from view.
The JSONL is still on disk and recoverable from the /resume picker, but you have to know it exists and go dig it out. In a busy day across a dozen chats, that thread is effectively gone unless something keeps a list.
- Survives
- The JSONL, recoverable through the session picker.
- Lost from the model’s view
- The at-a-glance thread, until you find it again.
- The fix
- A host that keeps a live list of chats and reopens them turns this from a hunt into a click.
The scoreboard: one prompt problem, three host problems. If your whole strategy for keeping context alive is prompt hygiene, you have a fix for 25 percent of the ways a long session fails. The deeper treatment of mode 01 lives in the auto-compacting write-up; modes 02 and 03 get their own page in the persistent-sessions guide.
What a host can do that a prompt cannot
Fazm is a native macOS app that runs the real Claude Code agent loop through the Agent Client Protocol. It does not change the model, your subscription, or the tools. What it changes is what happens around the SDK’s events. Three concrete mechanisms close the three host-problem modes, and they are all in the open-source bridge, so you can read them.
A session map that survives restarts and ID rolls
The bridge writes one row per session to ~/.fazm/acp-sessions.json, capped to the 200 most recent (PERSISTED_MAX = 200 in acp-bridge/src/index.ts). Each row records the directory the session belongs to, so a resume after a reboot, or after a rate limit rolled the upstream ID, targets the session that is actually on disk instead of a stale ID you happened to remember.
// ~/.fazm/acp-sessions.json - one row per session, newest 200 kept
{
"sessionId": "a1b2c3d4-...-e5f6",
"sessionKey": "floating",
"cwd": "/Users/you/project",
"model": "claude-sonnet-4-6",
"updatedAt": 1715731200000
}On launch the app reopens every window with its conversation intact, so closing the lid stops being a recovery task. That is modes 02, 03, and 04 handled by a file, not a flag.
The compaction boundary, surfaced instead of swallowed
Mode 01 is not solvable: the SDK still owns when compaction fires. But it does not have to be silent. When Claude Code decides to compact, the SDK emits a compact_boundary system event carrying a pre_tokens count. The stock ACP agent drops that event. Fazm runs a patched entry point (acp-bridge/src/patched-acp-entry.mjs) that forwards it verbatim:
// patched-acp-entry.mjs forwards the system event the stock ACP agent drops
{
"sessionUpdate": "compact_boundary",
"trigger": "auto",
"preTokens": 161240 // example: tokens live the instant compaction fired
}A boundary that fires with preTokens near 200k means the summarizer is about to flatten close to the whole window into a paragraph. Seeing that number is the difference between deciding to fork now and finding out 40 turns later that the model forgot the file path you set at the start.
One-click fork, so you branch before the boundary
Every chat has a fork button. It calls the ACP session/fork RPC (exposed by @agentclientprotocol/claude-agent-acp as unstable_forkSession). The new branch starts at the end of the current conversation with the full prior context; the original stays intact and resumable. When you can see compaction coming, forking at a known-good point turns the boundary from an accident into a choice.
A three-hour session, raw versus wrapped
Three hours in, the window fills. Claude Code summarizes; the file path and the constraint you set in turn 4 drop out of the model's view with no warning. You quit for the day. Next morning it is four terminals, four cd commands, and four --resume flags just to find where you were.
- Compaction is silent: no token count, no marker
- A restart means manually resuming every session by ID
- A rate-limit ID roll breaks --resume entirely
- A closed window puts the transcript out of sight
Four moves to keep a long session whole
Put durable rules in CLAUDE.md, not the conversation
Instructions you give once in a chat can be dropped at compaction. CLAUDE.md reloads at the start of every session, so anything that must hold for the whole task belongs there.
Compact Instructions section to CLAUDE.md to steer what the summarizer keeps.Push investigation into subagents
Subagents get their own fresh context window and return only a summary to the main thread. Research, log spelunking, and codebase sweeps stop bloating the conversation that has to survive.
Watch the boundary instead of being surprised by it
Run /context in the CLI to see what is using space, or use a host that surfaces the compact_boundary event so the pre_tokens count is visible before the summary replaces your turns.
Fork at a known-good point
Before the window fills, branch the session. The clean prefix is preserved on the parent, and you run the next chunk of work on the fork. This is the only move that protects context the summarizer would otherwise flatten.
The distinction that trips people up
Three things get conflated under the word “context,” and keeping them separate explains every behavior on this page. The transcript on disk is the JSONL file. It is durable. It almost never goes away. The restored window is what a host shows you when you reopen the app: it can be the full thread or nothing, depending entirely on whether the host bothered to record it. The model’s live context is the only one the model can actually reason over, and after a compaction it is the summary plus your recent turns, not the originals.
“My context did not survive” almost always means the third one shrank while the first one was fine the whole time. The transcript persisting and the model still seeing your early decisions are two different guarantees. Most advice online optimizes the first and quietly hopes for the second.
Run long Claude Code sessions without losing the thread
Fifteen minutes on how Fazm wraps the real agent loop with persistent sessions, a visible compaction boundary, and one-click forking.
Common questions
Frequently asked questions
Does Claude Code keep context through long sessions?
Partly. Claude Code manages context automatically as a session approaches the limit. Per Anthropic's docs, it clears older tool outputs first, then summarizes the conversation if needed. Your requests and key code snippets are preserved, but detailed instructions from early in the conversation can be lost. The full transcript stays on disk in a JSONL file under ~/.claude/projects/, but the model only ever sees the post-compaction view, not the original turns.
What exactly does auto-compaction drop?
Older tool outputs go first, since they are the cheapest thing to shed and the least likely to be needed again. If that is not enough, Claude Code summarizes the conversation itself. The summary keeps the gist: your requests and key code snippets survive. What it tends to flatten is the specific stuff from early turns, like a file path you established once, a constraint you set in turn 4, or a decision the model made and never restated. None of this touches the JSONL transcript on disk. It only changes what is live in the model's context window.
Where is my session stored, and does it survive a restart?
Every message, tool use, and result is written to a plaintext JSONL file at ~/.claude/projects/<encoded-cwd>/<session-id>.jsonl. That file survives a quit or a reboot. What does not survive automatically is the live session: a fresh claude invocation starts with a clean context window and does not reattach. You reopen a prior session yourself with claude --continue (latest in the current directory) or claude --resume <id> (a specific one).
Why does --resume sometimes say the session is not found?
The Claude Agent SDK looks the transcript up by the pair (cwd, sessionId). If you run --resume from a different directory than the one the session was created in, the lookup misses and the SDK throws Resource not found. The same thing happens if the upstream session ID rolled, which can occur after a rate limit, a credit reset, or a bridge restart: the ID you would type is now stale. The fix is to resume from the original working directory, against the ID that is actually on disk.
Can I turn auto-compaction off?
Not from the upstream CLI today. There is no off switch. You can steer what survives a compaction (run /compact with a focus, or add a Compact Instructions section to CLAUDE.md), and you can fork the session at a known-good point before the window fills. A host built on the Agent Client Protocol can surface the compaction boundary so it is never silent, but it cannot remove the boundary. The SDK still owns when compaction fires.
How is forking different from resuming a session?
Resuming reopens the same session ID and appends new messages to the existing conversation. If that session had already auto-compacted, resume hands you back the post-compaction view. Forking copies the history into a new session ID and leaves the original untouched. Upstream you do this with --fork-session or /branch; in Fazm it is a one-click button per chat that calls the ACP session/fork RPC. The branch starts at the end of the current conversation with the full prior context, and the parent stays intact and resumable.
What is the pre_tokens number, and why does it matter?
When Claude Code decides to compact, the SDK emits a system event with subtype compact_boundary carrying a pre_tokens integer: the count of tokens that were live the instant the decision was made. A boundary that fires with pre_tokens near the model's window (Sonnet and Opus sit at 200k) means the summarizer is about to flatten close to that whole budget into a paragraph. Seeing the number is the difference between forking deliberately and discovering the loss when the model hallucinates a variable name 40 turns later.
Does wrapping Claude Code in a host like Fazm change the model or my subscription?
No. Fazm runs the real Claude Code agent loop through the Agent Client Protocol. Same model, same Claude Pro or Max plan, same tools, same prompts. The host only changes what happens around the SDK's events: whether the compaction boundary is visible, whether sessions reopen on launch, whether resume targets the right ID. The model on the other end of the socket is unchanged.
Keep reading
Claude Code persistent sessions: what survives a restart
The honest map of what the CLI persists out of the box and what a host has to wrap on top.
Claude Code auto-compacting token waste
The summary is cheap. The real cost is the re-establishment work after the boundary fires.
Claude Code context management: where the bytes go
Screenshots versus the accessibility tree, and why one path compacts four times as fast.
Comments (••)
Leave a comment to see what others are saying.Public and anonymous. No signup.