DEV Community

decker
decker

Posted on • Edited on • Originally published at blog.https

Day 3 with Claude Code: How I Stopped Losing My Work to Compaction (Real Workflow)

The Problem No One Warns You About

You are 90 minutes into a complex refactoring session with Claude Code. Everything is clicking. You have established the patterns, worked through the edge cases, and you are close to done.

Then compaction hits.

Claude summarizes the session, loses half the context, and comes back confused about decisions you made an hour ago. In the worst case, it starts re-doing work you already finished — or worse, undoing it.

I lost 3 hours of work this way on three separate occasions before I built a proper workflow around it.

What Compaction Actually Destroys

Context loss during compaction is not random. It consistently wipes:

  • Decisions and rejections — things you told Claude NOT to do get forgotten
  • Established patterns — coding conventions you negotiated session-specific
  • In-flight work — tasks that were 80% done but not committed
  • File relationships — which modules touch which, discovered through exploration

The summary Claude generates is optimistic. It captures tasks but not reasoning. It knows what you were doing, not why or what to avoid.

The Workflow That Actually Works

After lots of trial and error, here is what I do now:

Before Any Long Session

Create a SESSION.md in the project root:

# Session Context

## Active Goal
One sentence: what are we trying to accomplish

## Key Decisions Made
- Decision 1 and the reason
- Decision 2 and the reason

## What NOT To Do
- Approach we rejected and why

## Current State
Files changed, state of in-progress work
Enter fullscreen mode Exit fullscreen mode

This file acts as compaction insurance — Claude loads it fresh each time.

During the Session

Update SESSION.md every 20-30 minutes. Takes 2 minutes. Saves hours.

Before Compaction Triggers

When you see the context getting long, manually run:

/compact "Please include in your summary: all rejected approaches, all active decisions with reasoning, all files currently being modified, and the exact current state of any in-progress task"
Enter fullscreen mode Exit fullscreen mode

Custom compact prompts dramatically improve summary quality.

After Compaction

Do NOT immediately continue the task. Ask:

What is the current state of what we are working on, and what decisions have we made so far?
Enter fullscreen mode Exit fullscreen mode

If the answer is wrong or incomplete, correct it before proceeding.

The Session Snapshot Approach

For critical work sessions, I use Mantra to take full session snapshots — essentially a "save state" for your Claude Code sessions. Before any risky operation or natural breakpoint, Mantra captures the full conversation state so you can restore it exactly.

Think of it like the quicksave function in a video game. You do not realize how much you need it until you lose 2 hours of progress.

The tool stores snapshots locally, works across Claude Code, Cursor, Gemini CLI, and Codex, and lets you browse snapshots visually to see what was in context at any point. Free to download at https://mantra.gonewx.com?utm_source=devto&utm_medium=article&utm_campaign=devto-article-launch.

The Bigger Picture

Claude Code is powerful enough that losing a session hurts. That is actually a sign that you are using it for real, complex work.

The developers doing the most ambitious work with AI coding tools are the ones who have built session management workflows. The ones still losing work to compaction have not yet built the habit.

Start with the SESSION.md approach — it costs nothing and works immediately. Add session snapshots when your work gets to the level where you cannot afford to lose it.

What session management strategies are you using?


Building Mantra — a session time machine for AI coding tools. Free download for macOS.


What Mantra Actually Does (Three Things)

After day three of fighting compaction manually, I wanted something that handled it at the tool level. Mantra does three specific things:

▶ Replay — Click any message in your session history and the code jumps back to exactly that state. The TimberLine scrubber works like a video timeline — drag to any point in your conversation and you're there. No more digging through git logs trying to reconstruct what the AI had in mind.

⚙️ Control — One MCP gateway that Claude Code, Cursor, Gemini CLI, and Codex all share automatically. Add a tool once, every AI assistant picks it up. Skills Hub keeps your prompt patterns consistent across projects without copy-pasting.

🔒 Secure — A local Rust engine scans your sessions for API keys, passwords, and tokens before you share anything. One-click redaction. Nothing leaves your machine.

No cloud. No sign-up. Free. → https://mantra.gonewx.com?utm_source=devto&utm_medium=article&utm_campaign=devto-article-launch

Top comments (0)