DEV Community

decker
decker

Posted on • Edited on

I Lost 3 Hours of Claude Code Work to Compaction. Never Again.

Last Tuesday I was deep in a refactoring session with Claude Code. Three hours in, context hit 95%, auto-compaction kicked in, and my agent forgot everything about the migration plan we'd been building together.

Sound familiar? Based on the 200+ comments across GitHub issues like #7530 and #18866, I'm far from alone.

The Problem Nobody Talks About

AI coding assistants are stateless by design. Your "session" is really just a sliding window of tokens. When that window fills up:

  • Claude Code runs compaction — summarizing your conversation and often losing critical details
  • Cursor silently drops older context from its window
  • Windsurf resets after crashes with no recovery path

The result? Your AI partner forgets the architectural decisions you spent an hour establishing. The custom patterns it learned. The bug reproduction steps you carefully laid out.

What I Tried First

  1. Manual copy-paste to files — Works but breaks flow. You're now managing context instead of coding.
  2. Git commits as checkpoints — Only captures code state, not the conversation and reasoning.
  3. JSONL file backups — Found the raw files in ~/.claude/projects/, but they're unreadable blobs of JSON.
  4. Starting fresh sessions — Loses everything. Back to square one explaining your codebase.

What Actually Worked

I found Mantra, which takes a different approach: it watches your session files locally and creates automatic snapshots. Think of it as Time Machine for your AI coding sessions.

The key features that matter:

  • Auto-snapshots before compaction events — the exact moment you usually lose context
  • Visual timeline — browse session states like git log, but for conversations
  • Diff view — see exactly what compaction removed
  • One-click restore — roll back to any previous state
  • Works offline — everything stays on your machine, no cloud dependency

It supports Claude Code, Cursor, Gemini CLI, and Codex. Takes about 30 seconds to install.

My Workflow Now

  1. Start coding session normally
  2. Mantra snapshots automatically in the background
  3. When compaction hits (or a crash, or a bad edit), I open Mantra's timeline
  4. Find the snapshot right before things went wrong
  5. Restore and continue where I left off

No more lost context. No more re-explaining my codebase. No more "sorry, I don't have context about the migration plan we discussed earlier."

The Bigger Picture

The real problem is that AI coding tools treat sessions as disposable. But our work isn't disposable. Three hours of context-building with an AI agent has real value — it's accumulated understanding that took time and tokens to create.

Until AI tools build proper session persistence natively (and there are feature requests with growing support), external tools like Mantra fill a critical gap.

Try it: https://mantra.gonewx.com?utm_source=devto&utm_medium=article&utm_campaign=devto-article-launch — free, local-first, installs in 30 seconds.

Have you lost work to compaction or context window limits? I'd love to hear your story in the comments.

Top comments (0)