Yesterday's session, hour two: Claude Code compacted, and a constraint from hour one — "the new endpoint must stay backwards-compatible with the v2 mobile client" — didn't survive the summary. The agent then cheerfully "simplified" the response shape. Tests passed. Only my grumpy habit of rereading the original ticket caught it before review.
This keeps happening in long sessions, so let's talk hygiene, because I think most of us manage context by superstition. My current rules, honestly assessed:
- Externalize constraints immediately. Anything that must survive the whole session goes in a
TASK.md the moment it's stated, and the session starts with "reread TASK.md after any compaction." This is the one rule I'm confident in — files are the only memory that survives compaction with fidelity. - /clear between tasks, always. Residue from task A measurably contaminates task B — old file paths, stale assumptions. A fresh session plus good instruction files beats a warm session's "momentum" every time I've actually compared.
- Session bankruptcy at the second confusion. First time the agent misremembers something, correct it. Second time, I declare bankruptcy: /clear, write a summary myself, restart. Continuing a confused session past that point has never once paid off for me. Never.
- The part I can't verify: people say "keep sessions under N tokens" but I have no visibility into what compaction actually discarded. I'm doing folk medicine here.
What are other people's actual triggers — time-based, task-based, vibes? And has anyone built tooling around the compaction boundary, like auto-appending a constraints file post-compaction?
Read-the-manual corner: Claude Code fires a
PreCompacthook before compaction. Mine snapshots the transcript to a file and appends a standing reminder — 'compaction occurred; reread TASK.md before proceeding' — so the reread rule doesn't depend on the summarizer's mood. It's not folk medicine if you automate the ritual.Second, blunter point: if you're compacting mid-task regularly, your tasks are too big for one session. The constraint that died at hour two shouldn't have needed to survive to hour two — decompose until sessions end before compaction starts, and hygiene mostly stops being a problem you have.
The PreCompact hook is exactly the tooling I was asking for and I'm mildly embarrassed it was in the docs the whole time. Wired it up this morning — will report back with whether constraint-survival improves or whether I just feel better.
Partial dissent on 'decompose until sessions end before compaction': some work is irreducibly exploratory — gnarly debugging sessions legitimately run long because the task IS the wandering. For those, hooks + external constraint files are the whole game. Decomposition advice lands better on build tasks than on investigation.