I run long Claude Code sessions, and I kept getting bitten by the same thing: the context window fills up, Claude Code compacts it (summarises history, drops detail), and the stuff that dies first is exactly what I needed, the decision I made 40 messages ago and *why*, and the thing I was about to do next. Worse, my setup didn't even recognise it was about to compact important context. It just happened, and afterwards the agent was working from a blurry reconstruction of its own past. So I set out to fix that specific failure: make the system notice the moment before it loses important context, and act on it. The lever is "PreCompact", the Claude Code hook event that fires right before compaction runs (both manual `/compact` and automatic). It's the last moment where the full, un-summarised state still exists and you can still run something. I use that moment to flush state to a file. The approach, in one line: treat the chat as a volatile buffer, and a plain `STATUS_LOG.md` file as the source of truth. A `PreCompact` hook fires a tiny script that signals "save now"; the model stops and appends a short, structured checkpoint (what's done / decisions + why / what's next) to that file before compaction eats it. Two triggers only: - The automatic hook. - Plus a manual `checkpoint` keyword. No context-% polling, no per-turn nagging. The whole thing is ~20 lines of config plus a 4-line Python script. It's been solid for me, but I want to know where it breaks before I lean on it harder, so I'm posting for opinions. Full writeup (hook JSON, the script, the checkpoint format, design constraints, and the limitations I already know about) is in the attached document. A few things I'd genuinely like feedback on: - Is "chat = volatile buffer, file = source of truth" the right mental model, or would a better native compaction summary solve this anyway? - Is there a trigger earlier/better than `PreCompact`? How do *you* survive compaction in long sessions? - Anyone enforcing the "actually write the checkpoint" step harder than a printed instruction — e.g. a follow-up hook that verifies the file actually grew?