If you use Claude Code, MoltBot (Clawdbot), or any long-running AI agent, you've hit this: you're deep in a conversation, the context window fills up, compaction kicks in — and suddenly your agent greets you like a stranger.
"Welcome back! What can I help you with today?"
Mate, we were just talking.
Context compaction is necessary — models have finite context windows. When the conversation gets too long, the system summarises older messages and drops the originals. But the summary is often thin. Key details vanish. The agent loses track of what you were actively working on.
The result: your agent acts like it just woke up. It re-reads files it already read. It greets you again. It forgets the decision you made two messages ago.
When context is getting long, the agent writes a checkpoint file with what it's working on, the current thread, open questions, and last topic discussed. This is the agent writing a note to its future self — short, specific, actionable.
After compaction, the agent reads today's daily notes before greeting or acting. If the checkpoint file exists, it reads that too — pre-compact breadcrumbs. It does NOT greet the user like a new session. It writes a compact marker in daily notes and deletes the checkpoint after reading.
The agent learns to recognise compaction: a summary block but sparse memory of recent conversation, the summary mentioning "compacted" or "truncated", or general disorientation. That's compact, not a new day.
Copy this into your AGENTS.md, system prompt, or equivalent:
## Compact Recovery
Context compaction kills your working memory. These rules prevent you
from acting like it's a fresh day when it isn't.
### Before compact (when context feels long):
- Write memory/session-state.md with: what you're actively working on,
current thread, open questions, last topic discussed
- This is your checkpoint — future-you reads it to pick up seamlessly
### After compact (when you wake with a summary):
- Read today's daily notes FIRST before greeting or acting
- If memory/session-state.md exists, read it — that's your pre-compact
self leaving you breadcrumbs
- Do NOT greet the user like it's a new session — just continue naturally
- Write "⚡ COMPACTED at HH:MM" in today's daily notes so there's a record
- Delete or clear memory/session-state.md after reading it
### How to tell you were compacted:
- You have a <summary> block but sparse/no memory of recent conversation
- The summary says "compacted" or "truncated"
- You feel disoriented — that's compact, not a new day
It's the same thing humans do. You leave a post-it note before you leave your desk. When you come back, you read the note before doing anything else. The key insight is that the agent needs to write the checkpoint while it still has full context. After compaction, it's too late.