Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Session Restore

One-click restore of the exact set of Claude Code sessions that were open last time — reopened as Windows Terminal tabs, each automatically resumed with claude --resume.

Close your terminal (or have it crash), come back, double-click one shortcut, and every conversation is back where you left it.

Windows + Windows Terminal + PowerShell. Claude Code conversations are auto-saved by Claude itself; this tool just tracks which ones were open and reopens them.

Why

Claude Code already persists every conversation under ~/.claude/projects/, and claude --resume <id> reopens any one of them. What's missing is a record of which sessions were open so you can bring them all back at once. Terminals can't "freeze" running processes, but they don't need to — the conversations are on disk; you only need the list.

This tool keeps that list fresh and replays it.

How it works

 every 2 min (scheduled task)              on demand (desktop shortcut)
 ┌───────────────────────────┐             ┌──────────────────────────────┐
 │ claude-snapshot.ps1       │             │ claude-restore.ps1           │
 │  reads running claude     │  writes     │  reads snapshot, opens one   │
 │  processes' --resume <id> ├──> snapshot ─┤  WT tab per session:        │
 │  (+ registry for cwd)     │   .json     │  wt new-tab -d <cwd>         │
 │  writes ONLY if ≥1 open   │             │   ... claude --resume <id>   │
 └───────────────────────────┘             └──────────────────────────────┘
  • claude-snapshot.ps1 — every 2 minutes, records the currently-open interactive sessions to ~/claude-open-snapshot.json. It reads each running claude.exe process's command line (--resume <id>) so background tabs are captured immediately, and falls back to ~/.claude/sessions/<pid>.json for cwd and for freshly-started sessions. It only writes when at least one session is open, so closing everything never clobbers the last good list.
  • claude-restore.ps1 — reads the snapshot and opens one Windows Terminal tab per session, each running claude --resume <id> in that session's original working directory.

Install

git clone https://github.com/SnowSky1/claude-session-restore.git
cd claude-session-restore
powershell -ExecutionPolicy Bypass -File .\install.ps1

install.ps1 registers a scheduled task (snapshot every 2 min) and creates a "Restore Claude Sessions" desktop shortcut. It does not require admin.

Usage

  • Restore: double-click the Restore Claude Sessions desktop shortcut.
  • Preview without opening: powershell -File .\claude-restore.ps1 -DryRun
  • Freeze right now (e.g. just before shutdown): powershell -File .\claude-snapshot.ps1

Uninstall with powershell -ExecutionPolicy Bypass -File .\uninstall.ps1 (keeps your scripts and snapshot; only removes the task, shortcut, and generated launcher).

Notes

  • Restores conversations, not processes. A session that was running a dev server reopens in the right folder, but you restart the server yourself.
  • The list updates on a ~2-minute cadence, so a tab opened seconds before shutdown might miss the last snapshot. Run claude-snapshot.ps1 manually to capture immediately.
  • Junk/greeting sessions are restored too if they were genuinely open — the tool restores what was open, not what mattered. Close what you don't want and the next snapshot drops it.

Hard-won details

A few non-obvious things this handles, learned the hard way:

  • Snapshot from process command lines, not just the registry. Background WT tabs are slow to write ~/.claude/sessions/<pid>.json (ConPTY defers rendering), so a registry-only snapshot silently dropped them and they vanished on the next restore. Reading --resume <id> off the process command line captures every tab instantly.
  • Quoting for wt. PowerShell 5.1's Start-Process -ArgumentList <array> does not quote array elements that contain spaces, so a session titled e.g. agent guide demo broke the --title argument and Windows tried to launch the second word as a program (error 0x80070002). claude-restore.ps1 builds one quoted command string instead, quoting only values that need it and doubling trailing backslashes so a -d "D:\" doesn't turn \" into an escaped quote.
  • Never clobber on empty. The snapshot writer exits without writing when nothing is open, so a crash (or a clean shutdown) leaves the last good list intact.

License

MIT

About

一键恢复上次开着的全部 Claude Code 会话:后台每2分钟快照,崩溃或关机后双击桌面快捷方式,即把每个对话作为 Windows Terminal 标签页用 claude --resume 原样重开。示例:下班关掉终端,第二天双击「恢复Claude会话」,十几个会话连同各自目录全部回来。仅需 Windows + Windows Terminal。

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages