DEV Community

decker
decker

Posted on • Edited on

Claude Code Session Recovery: The Complete 2026 Guide

The Problem

Claude Code's compaction feature silently destroys session context. After 4 hours of work, a single compaction can wipe out all the architectural decisions and nuanced understanding you built up.

The Fix

Claude Code stores sessions at ~/.claude/projects/[hash]/[session-id].jsonl. Backing these up lets you restore exact session state.

#!/bin/bash
BACKUP_DIR="$HOME/.claude/session-backups/$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
cp -r ~/.claude/projects "$BACKUP_DIR"
echo "Saved to $BACKUP_DIR"
Enter fullscreen mode Exit fullscreen mode

Restore a Session

claude --resume [session-id]
Enter fullscreen mode Exit fullscreen mode

A Better Solution

Mantra automates this — visual session timeline, automatic snapshots, works with Claude Code, Cursor, Gemini CLI, and Codex.

Free download at mantra.gonewx.com.

Top comments (0)