Learn · How-to

How to recover an accidentally closed Claude Code session.

The terminal closed, the agent was mid-task, and your stomach dropped. Good news: almost everything survives. Here is how to get it back, in Claude Code and in every other CLI agent.

By The Termi Protocol team · Updated July 13, 2026 · 7 min read
Direct answer

Closing the terminal does not delete a Claude Code session. The transcript is saved to disk as you work. Open a new terminal in the same project directory and run claude --continue to reopen the latest conversation, or claude --resume to pick from past sessions. Your file changes are already on disk; only running processes and pending approvals are lost.

Recovering the session in Claude Code

Claude Code writes the conversation to disk continuously, under ~/.claude/projects/, scoped to the project folder you launched it from. Recovery is three commands at most:

  1. Go back to the project. Open a terminal and cd into the same directory you were working in. Session history is looked up by path.
  2. Reopen the latest conversation. Run claude --continue (short form claude -c). The full history loads and the agent remembers everything that was said.
  3. Or pick an older one. Run claude --resume for an interactive list of past sessions in that project. Inside a running session, the /resume command does the same. If you know the session id, claude --resume <id> jumps straight to it.

Two reassurances while your heart rate settles. First, the code is safe: every edit the agent made was written to your real files, so the work exists whether or not any window is open. Check git status to see it. Second, the project memory is safe: CLAUDE.md and Claude Code's saved memories live on disk, not in the window.

If the session went sideways before it closed and you want the code back too, Claude Code keeps checkpoints of file states: /rewind (or double Escape) steps the conversation and the code back to an earlier point.

What is actually lost

Being precise about the damage helps you fix it fast. A closed terminal costs you exactly three things:

  • Running processes. The dev server, watcher or long test run the agent started is gone. It will need to be restarted.
  • Pending approvals. If the agent was waiting for a yes on a command, that request died with the window. It will re-ask when it hits the step again.
  • Situational awareness. Yours, not the model's. The resumed transcript knows what happened; the question is whether you remember what you were in the middle of deciding.

The same rescue in other CLI agents

Every serious agent has grown some version of this, with different spellings. As of July 2026:

AgentResume latestPick a sessionWhere history lives
Claude Codeclaude --continueclaude --resume or /resume~/.claude/projects/
Codex CLIcodex resume --lastcodex resume~/.codex/sessions/
Gemini CLI/chat resume <tag>/chat list after /chat saveproject temp dir; /restore with --checkpointing
Aideraider --restore-chat-historyedit the history file.aider.chat.history.md in the repo
opencodeopencode --continuesession list in the TUIlocal app data
Copilot CLIcopilot --continuecopilot --resume~/.copilot/ (confirm with --help)

The pattern to internalize: transcripts are cheap to persist, so everyone persists them. The recovery gap is never the chat log. It is everything around it.

Re-anchoring the agent (and yourself)

After resuming, do not just type "continue". Long transcripts resume with their context intact but their momentum gone, and an agent prodded with "continue" will sometimes re-do or un-do finished work. Two minutes of re-anchoring pays for itself:

Summarize: what were you working on, what is done,
what was in progress, and what is the next single step?
Check git status before answering.

The git status nudge matters: it forces the agent to reconcile its memory of the work with what is actually on disk, which catches the "I thought I already wrote that file" class of confusion immediately.

Never lose a session again

  • Run the terminal inside tmux or screen. Free, and a closed window stops mattering: the session keeps running detached, agent and processes included.
  • Keep state outside the conversation. A task list the agent maintains, notes in CLAUDE.md or AGENTS.md, and frequent git commits mean even a cold-started session re-onboards in seconds.
  • Checkpoint like you mean it. Commits before and during agent sessions turn any disaster into git checkout.
  • Or run the agents in a workspace built for this. This problem is one of the reasons The Termi Protocol exists: agents live at desks in a persistent room, so closing the app loses nothing. Task boards, checkpoints, each agent's project memory and full session history are saved and restored, interrupted work is flagged for recovery when you return, and even an agent you removed can be recovered from the trash with its memory intact.
Recovering a removed AI coding agent in The Termi Protocol, with its saved memory, tasks and history intact
Recovery as a feature: an agent restored with its memory, tasks and history intact.

Close the app. Keep the work.

Termi persists every agent's tasks, checkpoints, memory and history between sessions, for Claude Code, Codex, Gemini CLI and any CLI agent. Reopen the room and pick up exactly where you left off.

Session recovery FAQ

Does closing the terminal delete my Claude Code session?
No. The conversation transcript is written to disk as you work, so a closed window, a crashed terminal or a reboot does not erase it. Reopen a terminal in the same project directory and run claude --continue to pick up the latest session.
Where does Claude Code store session history?
Locally, under ~/.claude/projects/, in a folder derived from the project path, as JSONL transcript files. That is what --continue and --resume read from, and it never leaves your machine.
Does Claude Code resume the session after a usage limit is reached?
Yes. Hitting a rate or usage limit pauses you, not the session: the transcript stays on disk exactly like a closed window. When the limit window resets, claude --continue picks the conversation back up. If you cannot wait, hand the task to another agent; the repo, your notes and the task list carry the context across.
What is the difference between claude --continue and claude --resume?
claude --continue immediately reopens the most recent conversation for the current directory. claude --resume shows a picker of past sessions so you can choose one, and also accepts a specific session id.
Can I recover the code changes too, or just the chat?
The code changes were written to your files as the agent worked, so they survive independently of the window. To move the code itself backward or forward, use git or Claude Code's checkpoints via /rewind.
How do I resume a closed Codex CLI or Gemini CLI session?
Codex CLI: run codex resume for a session picker or codex resume --last for the most recent. Gemini CLI: save state with /chat save and restore it with /chat resume, plus --checkpointing and /restore for file states. Aider keeps .aider.chat.history.md and can reload it with --restore-chat-history.
What actually gets lost when the terminal closes?
Three things: processes the agent had running (dev servers, watchers), any approval it was waiting on, and the momentum of knowing exactly where the work stood. Transcripts and file changes survive; the running state does not.