{"slug": "snapshot-your-terminal-state-restore-it-after-a-crash-claude-code-sessions", "title": "Snapshot your terminal state, restore it after a crash — Claude Code sessions included", "summary": "A developer built claude-sessions, a tool that snapshots terminal state every five minutes and restores it after a crash, including Claude Code sessions. The daemon records iTerm windows, tabs, working directories, and active Claude sessions, allowing recovery via a single command. The tool also includes a cross-project session picker that lists all Claude Code sessions from any directory.", "body_md": "Last time I built [ claude-sessions](https://github.com/DenverLifeSciences/claude-sessions): one picker to resume any Claude Code session across projects. But a machine crash takes more than Claude with it — it takes your whole terminal\n\nmacOS window restoration exists, but it fails this job twice:\n\n`claude`\n\nsessions don't come back.A snapshot daemon plus an *explicit* restore — no auto-restore, ever.\n\nEvery 5 minutes, a launchd job walks every iTerm window and tab via AppleScript, and for each tab resolves the tty → the processes on it (`ps`\n\n) → the working directory (`lsof -d cwd`\n\n) → and whether a `claude`\n\nprocess is running there, including **which session**: from its `--resume`\n\nargument, from the transcript file it holds open, or from the newest transcript for that directory. The result is a small JSON file.\n\nSnapshots accumulate as **history** — the last 100 *distinct* states, consecutive duplicates skipped, and an empty terminal never overwrites anything.\n\nAfter a crash:\n\n```\nclaude-sessions --restore-crash   # newest snapshot\nclaude-sessions --restore-pick    # or: fzf through history, pick the right one\n```\n\nEvery tab comes back — as tabs of the window you're standing in — `cd`\n\n'd to its old directory, with `claude --resume <session-id>`\n\nrerun wherever Claude was live. Intentional quit? Just don't run it. You are the crash detector; that's the feature.\n\n`~/.claude/bin`\n\n→ iCloud), the timer dies with `Operation not permitted`\n\n— macOS TCC silently denies background jobs access to `~/Library/Mobile Documents`\n\n. Point the plist at a local copy.Script, launchd template, and docs:\n\nA cross-project session picker for [Claude Code](https://claude.com/claude-code) CLI.\n\nYour machine crashes with seven Claude Code sessions open across five repos. `claude --resume`\n\nonly lists sessions for the directory you run it from — so recovery means remembering every repo you were in, `cd`\n\n-ing into each one, and picking from a list, seven times.\n\n`claude-sessions`\n\ninstead lists **every session from every project** in one [fzf](https://github.com/junegunn/fzf) picker, newest first. Hit Enter and the session opens in a new iTerm tab (or tmux window) running `claude --resume <id>`\n\nin the right directory — while the picker stays open for the next one.\n\n```\nenter   open session in a new tab (picker stays open)\nctrl-a  hide/show agent-teammate sessions (⛭)\nctrl-r  refresh the list\nesc     quit\n```\n\nEach line shows the session's age, project directory, git branch (when not main/master), and its opening message. A preview pane shows the last few user/assistant exchanges of the…", "url": "https://wpnews.pro/news/snapshot-your-terminal-state-restore-it-after-a-crash-claude-code-sessions", "canonical_source": "https://dev.to/daksh-gargas/snapshot-your-terminal-state-restore-it-after-a-crash-claude-code-sessions-included-32pj", "published_at": "2026-07-07 16:17:05+00:00", "updated_at": "2026-07-07 16:28:52.752634+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-tools"], "entities": ["Claude Code", "iTerm", "AppleScript", "fzf", "launchd", "tmux", "macOS", "DenverLifeSciences"], "alternates": {"html": "https://wpnews.pro/news/snapshot-your-terminal-state-restore-it-after-a-crash-claude-code-sessions", "markdown": "https://wpnews.pro/news/snapshot-your-terminal-state-restore-it-after-a-crash-claude-code-sessions.md", "text": "https://wpnews.pro/news/snapshot-your-terminal-state-restore-it-after-a-crash-claude-code-sessions.txt", "jsonld": "https://wpnews.pro/news/snapshot-your-terminal-state-restore-it-after-a-crash-claude-code-sessions.jsonld"}}