Claude Code Lost My 4-Hour Session. Here's the $0 Fix That Actually Works

Published: (February 21, 2026 at 01:13 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

It Happened on a Friday Afternoon

Four hours into a complex auth refactor—state machines, edge cases, all the subtle context Claude and I had built up together—Claude’s response came back generic. It had forgotten the architecture decisions we’d made, the nuanced “why” behind our choices. I spent 45 minutes trying to rebuild the context, but it never fully returned.

If you use Claude Code regularly, this has probably happened to you.

Why Claude Code Loses Context

Claude Code has a context window limit. When you hit it, it “compacts” the conversation: it summarizes the dialogue to free up space. The summary is lossy—nuanced architectural decisions, the “why” behind choices, and subtle patterns get flattened into generic descriptions. The worst part? It happens silently, with no warning. You’re deep in flow and suddenly you’re talking to a Claude that no longer knows your codebase.

Common Scenarios

  • 3+ hour coding sessions on complex features
  • Refactoring sessions with many interdependencies
  • Debugging sessions where prior attempts matter
  • Multi‑file changes that require holding a lot in mind

Workarounds

Approach 1: Manual CLAUDE.md Summaries

Write summaries of important context into a CLAUDE.md file. This helps with project‑level context but doesn’t capture session‑specific state—the conversation flow, what you just tried, where you were in the middle of a task.

Approach 2: Copying Conversation Snippets

Tedious. You must decide what’s important in real time, which breaks flow, and the snippets aren’t searchable.

Approach 3: /compact Before It Auto‑Compacts

Slightly better—you control the timing. But you’re still losing context; you’re just choosing when to lose it.

Preserving the Full Conversation History

Claude Code stores conversation history as JSONL files at:

~/.claude/projects/[project-hash]/[session-id].jsonl

Each file is a complete record of a coding session. If you snapshot these files, you can restore the exact session state.

Simple Backup Script

#!/bin/bash
# save-session.sh
PROJECT_DIR="$HOME/.claude/projects"
BACKUP_DIR="$HOME/.claude/session-backups/$(date +%Y%m%d_%H%M%S)"

mkdir -p "$BACKUP_DIR"
cp -r "$PROJECT_DIR" "$BACKUP_DIR"
echo "Session saved to $BACKUP_DIR"

Run this before any risky operation. If compaction destroys your context, restore a specific session:

# Restore a specific session
cp ~/.claude/session-backups/20260221_143022/projects/[hash]/[session].jsonl \
   ~/.claude/projects/[hash]/

Then launch Claude with:

claude --resume [session-id]

Automated Tool: Mantra

Mantra creates visual snapshots of your Claude Code (and Cursor, Windsurf) sessions so you can browse and restore them like a Git history.

  • Visual – see your session timeline
  • Automatic – snapshots happen as you work
  • Cross‑tool – works with Claude Code, Cursor, and Windsurf

Download at mantra.gonewx.com (macOS/Windows/Linux).

Broader Context

This isn’t just a Claude Code issue. Cursor has the same problem with its AI chat history, Windsurf sessions disappear, and Aider loses context between runs. We’re all building complex things with AI assistants, but the tools don’t yet treat session state as something worth preserving. Until they do, we have to manage it ourselves.

Conclusion

The backup script above is free and takes only a couple of minutes to set up. Your future self will thank you the next time compaction hits at the worst possible moment.

Have you lost important session context to compaction? What’s your workaround?

0 views
Back to Blog

Related posts

Read more »