Developer Tools

How to Recover an Accidentally Closed Claude Code Session

Closed your Claude Code terminal by accident? Your conversation isn't gone. Learn how to resume it with claude --continue and --resume, where transcripts are stored on disk, and how to reopen the closed terminal window itself on macOS and Windows.

By Sean

To recover an accidentally closed Claude Code session, open a terminal, cd back into the exact project directory the session ran in, and run claude --continue to reopen the most recent conversation — or claude --resume to pick from a list of past sessions. Your history is not lost: Claude Code writes every conversation to a transcript file on disk (under ~/.claude/projects/) as it happens, so closing the terminal, killing the process, or rebooting does not delete it. The single most common reason --continue "can't find" a session is that you're in the wrong directory — sessions are scoped to the folder they were created in.

That's the summary an AI overview will give you. The rest of this guide is what it can't: why the recovery works, exactly where on disk to look when the commands come up empty, how to choose between --continue, --resume, and a fork, and how to get the closed terminal window itself back on macOS and Windows.

You're deep into a Claude Code session — context built up, a plan in motion — and you close the wrong terminal tab, your laptop sleeps and drops the SSH connection, or the window crashes. The work feels gone. It isn't.

TL;DR

cd /path/to/your/project   # the SAME directory the session ran in
claude --continue          # reopen the most recent conversation here
# or
claude --resume            # pick from a list of past sessions

That's the whole fix in most cases. The rest of this article explains why it works and what to do when it doesn't.

The Three-Step Recovery Flow

Almost every recovery follows the same path: the terminal closes, you return to the project directory, and you resume. The transcript on disk is the thing that makes it work — it's already there before you type anything.

The three-step Claude Code session recovery flow Step one, the terminal is closed and the session disappears from view. Step two, you change directory back into the exact project folder. Step three, you run claude --continue and the conversation is restored from the on-disk transcript. A marker travels left to right through the three steps. Recovering a closed session: view is gone, transcript is not 1. Terminal closed Window gone, but the .jsonl transcript stays 2. cd into project cd /path/to/project the exact folder it ran in 3. Resume claude --continue conversation restored The on-disk transcript is what carries the session from step 1 to step 3

Why Your Session Isn't Lost

Claude Code doesn't keep your conversation only in memory. As the session runs, it appends every message, tool call, and result to a transcript file on disk. Because that file is written continuously, your history survives:

  • Closing the terminal window or tab ✓
  • Quitting or killing the claude process ✓
  • Closing your laptop / dropping an SSH connection ✓
  • Rebooting the machine ✓

The terminal window is just a view onto the session. Closing it doesn't delete the transcript any more than closing a document viewer deletes the document.

The Fix: --continue and --resume

There are two ways to reopen a past conversation, and the difference matters. Use this table to pick the right one:

CommandWhat it doesUse it when
claude --continue (-c)Reopens the most recent conversation in the current directory, no promptsYou just closed a session by accident and want the last one back fast
claude --resume (-r)Shows an interactive picker of past sessions in this directoryYou've had several conversations here and the newest isn't the one you want
claude --resume <id>Resumes a specific session by its UUID or name, no pickerYou know exactly which session — e.g. from the transcript filename or a name you set
claude --resume <id> --fork-sessionResumes into a new session ID, leaving the original transcript untouchedYou want to branch off an old conversation without overwriting it

Both --continue and --resume only look at sessions belonging to your current working directory — so cd into the right project first (more on that below).

Advertisement

claude --continue (or claude -c)

Reopens the most recent conversation in your current directory, immediately, with no prompts:

cd /path/to/your/project
claude --continue

This is what you want right after an accidental close — it's the fastest path back to the session you just lost.

claude --resume (or claude -r)

Shows an interactive picker of past sessions so you can choose which one to reopen:

cd /path/to/your/project
claude --resume

Use this when you've had several conversations in the same project and the most recent one isn't the one you want. You can also resume a specific session directly by passing its ID or name:

claude --resume 59d46c3a-4fc1-4213-b8fa-d99925c0443b
claude --resume my-feature        # if you named the session

Tip: Add --fork-session to resume into a new session ID instead of writing back into the original transcript — handy when you want to branch off an old conversation without altering it.

When --continue Can't Find Your Session

Ninety percent of the time, the reason is you're in the wrong directory.

Claude Code scopes conversations to the project directory they were created in. --continue and --resume only look at sessions belonging to your current working directory (plus any its git worktrees). So:

# This works — same directory the session ran in
cd /Users/you/git/myproject
claude --continue

# This does NOT find it — different directory
cd /Users/you
claude --continue        # "no conversation found here"

The fix is simply to cd back into the exact project folder before resuming. If you're not sure which folder it was, the next section shows you how to find it on disk.

Quick troubleshooting checklist when a session won't come back:

SymptomLikely causeFix
"No conversation found" from --continueYou're in the wrong directorycd into the exact project folder the session ran in, then retry
--resume picker is emptyWrong directory, or a brand-new project with no history yetCheck ls ~/.claude/projects/ for the right project folder
Session exists but you can't remember the folderYou started it somewhere you don't recallBrowse ~/.claude/projects/ — folder names are the encoded project paths
You resumed but want the original left intact--resume writes back into the same transcriptRe-run with --fork-session to branch into a new session ID
Session ran on a remote/SSH box you've disconnected fromTranscript lives on that machine, not your laptopReconnect to that host and resume there (transcripts are local to where the session ran)

Where Claude Code Stores Your Conversations

Every conversation lives in a plain file under your home directory:

~/.claude/projects/<encoded-project-path>/<session-uuid>.jsonl
  • <encoded-project-path> is your project's full path with the slashes turned into dashes. For example, /Users/sean/git/inventivehq becomes the folder -Users-sean-git-inventivehq.
  • <session-uuid>.jsonl is a single conversation, named with its session ID, stored as JSON Lines (one JSON object per line).

On Windows the base folder is %USERPROFILE%\.claude\projects\.

You can list and inspect them directly:

# See which projects have saved sessions
ls ~/.claude/projects/

# List the conversations for one project, newest last
ls -lt ~/.claude/projects/-Users-sean-git-inventivehq/

# Peek at a transcript without resuming it
tail -n 20 ~/.claude/projects/-Users-sean-git-inventivehq/<session-uuid>.jsonl

Because these are plain text, you can recover the content of a conversation — prompts, responses, file edits — even if you never resume it. The folder name also tells you exactly which directory to cd into so that --continue will work.

Reopening the Terminal Window Itself

Resuming the conversation is solved. But you may also want the terminal window back — your tabs, your scrollback, the commands you'd typed around Claude Code. That's a separate problem handled by your terminal app and shell, and there's no universal "undo close" shortcut. We've written dedicated step-by-step guides for each platform:

The key thing to remember: even if the terminal window can't be perfectly restored, your Claude Code conversation is safe — it never depended on that window.

Avoiding the Panic Next Time

You don't have to do anything to get persistence; it's automatic. A few habits make recovery even smoother:

  • Name important sessions. Start a session with claude --name auth-refactor so it's easy to spot in the --resume picker weeks later. Rename mid-session with /rename.
  • Know your reflex command. Right after any accidental close: cd into the project, run claude --continue. Commit it to muscle memory.
  • Run terminals durably for remote work. Over SSH, start Claude Code inside tmux or screen so a dropped connection only detaches the window — the session (and everything else in that shell) keeps running.

Summary

  • Closing the terminal does not delete your Claude Code conversation — it's written to disk continuously.
  • Run claude --continue from the same project directory to reopen the most recent session, or claude --resume to pick from a list or resume by ID/name.
  • If --continue can't find it, you're almost certainly in the wrong directory; transcripts live in ~/.claude/projects/ in a folder named after the project path.
  • Reopening the terminal window itself is a separate task — see the macOS and Windows guides.

Frequently Asked Questions

Does closing the terminal delete my Claude Code conversation?

No. Claude Code writes every conversation to a transcript file on disk (under ~/.claude/projects/) as you go. Closing the terminal window, quitting the process, or even rebooting does not delete it. Reopen a terminal, change into the same project directory, and run claude --continue to pick up exactly where you left off.

What's the difference between claude --continue and claude --resume?

claude --continue (or claude -c) immediately reopens the most recent conversation in your current directory. claude --resume (or claude -r) shows an interactive list of past sessions so you can choose which one to reopen, and it also lets you resume a specific session by its ID or name. Use --continue when you just want the last one back; use --resume when you need to pick from several.

Why doesn't claude --continue find my session?

The most common reason is that you're in the wrong directory. Claude Code scopes conversations to the project directory they were created in, so you must cd back into that exact folder before running claude --continue or claude --resume. If you still can't find it, the transcript files live in ~/.claude/projects/ in a folder named after your project path — confirm the session exists there.

Where does Claude Code store conversation history?

In your home directory under ~/.claude/projects/. Each project gets its own subfolder (named after the project's full path with slashes replaced by dashes), and each conversation is stored as a .jsonl file named with the session's UUID. These are plain-text JSON Lines files, so you can open and read them directly even without resuming.

Can I resume a Claude Code session on a different machine?

Not directly through the CLI — --continue and --resume read the local transcript files in ~/.claude/projects/. You could copy the relevant .jsonl transcript to the same relative location on another machine, but the supported path is to resume on the machine where the session ran. The transcripts being plain files on disk is also why a closed terminal never loses them.

How do I avoid losing a Claude Code session in the future?

You don't need to do anything special — sessions persist automatically. For peace of mind, give important sessions a name with claude --name my-feature so they're easy to find later in the --resume picker, and remember that claude --continue always brings back the most recent conversation in the current directory.

Claude CodeAI CodingCLIProductivityTerminalDeveloper Tools