Cross-session recall
"That bug we hit with the auth middleware" returns the actual context, not a vague reference. memory_find queries the snapshots like any other record.
qdrant · sessionsAuto‑compaction is a graceful loss. When the context window fills, Claude Code summarizes the older turns — freeing tokens for the work ahead. The conversation continues; the record does not. File paths fade. Stack traces blur. The exact phrasing of a correction becomes the gist of one. PreCompact is the moment to slip a copy of the underlayer into something durable, before the page is overwritten.
The window fills. The summarizer runs. What survives is a synthetic gist of the prior turns; what does not is everything that was specifically said.
PostToolUse and Stop hooks already mirror per‑turn events into Qdrant — fine‑grained, but disconnected. End‑of‑session summaries land safely. The middle of long sessions, where the most context lives, is where memory drops a layer.
Lost in transit: absolute paths, verbatim errors, long command output, the exact phrasing of feedback, the chain of intermediate reasoning.
A single shell script wired to PreCompact. It receives the full pre‑compaction transcript on stdin, the last moment that detail still exists in raw form.
It pipes the payload through extract‑chat, distilling a 2–4k token narrative — goal, decisions, files touched, unresolved questions — and writes it to Qdrant under collection: sessions. The full JSON is archived to ~/.claude/compactions/ as a belt‑and‑suspenders second copy.
Wrapped in timeout 10s … || true, so a Qdrant hiccup never blocks the model's next response. Symmetric with Codex, Gemini, and OpenCode — all four read the same memory.
turn₁ ─┐ turn₂ ─┤ turn₃ ─┼──▶ [ summarizer ] ──▶ synthetic summary turn₄ ─┤ │ turn₅ ─┘ ▼ … continued context ▽ raw turns: discarded after summarize ▽ no side-channel to durable memory ▽ Qdrant sees per-tool events only
turn₁ ─┐ turn₂ ─┤ ┌── stdin ──▶ pre_compact.sh turn₃ ─┼──▶ [ summarizer ] ────────┐ turn₄ ─┤ │ turn₅ ─┘ ▼ continued context │ ├──▶ extract-chat ──▶ narrative ──▶ Qdrant └──▶ raw json ─────────────────▶ ~/.claude/compactions/ △ snapshot taken before lossy step △ searchable from any qmem-aware tool △ timeout 10s · non-blocking on failure
No new dependencies. One JSON entry. One shell script that mirrors the shape of the hooks already on disk.
{ "hooks": { // … existing PreToolUse, PostToolUse, Stop, SessionStart … "PreCompact": [ { "hooks": [ { "type": "command", "command": "/root/qdrant-memory-mcp/scripts/claude_pre_compact_hook.sh" } ] } ] } }
Fires once, immediately before the summarizer runs. The full transcript — every message, tool call, tool output — is delivered to the script's stdin as JSON.
Pipe through extract-chat to produce a 2–4k token narrative: user goal, key decisions, files touched, unresolved questions.
Write the narrative to Qdrant via memory_store_session_summary: collection sessions, topic session/{id}/compact-{ts}, type compaction_snapshot.
Mirror the raw JSON to ~/.claude/compactions/{session_id}-{ts}.json. Qdrant for search; flat file for full fidelity recovery.
"That bug we hit with the auth middleware" returns the actual context, not a vague reference. memory_find queries the snapshots like any other record.
qdrant · sessionsIf compaction drops a critical file path or error message, grep the flat-file archive. The exact bytes are there, indexed by session and timestamp.
~/.claude/compactions/Snapshots accumulate. Ask: which kinds of tasks compact most often? Which sessions ended with a failed build? The corpus answers.
retrospective · workflowCodex, Gemini CLI, OpenCode all share qmem-memory. Today's Claude snapshot is searchable from tomorrow's session in any of them.
cross-agentOne Qdrant write per compaction event — negligible. Storage grows linearly; prune snapshots older than ~90 days. The hook delays the model's next response for at most the timeout. Worst case is bounded; best case is a memory you didn't know you'd want, available the day you need it.
This page is a single static index.html. No build step, no framework. Drop the directory at Cloudflare Pages — or run the command below from the project root.
wrangler login./root/precompact-explainer/, run the deploy command.precompact-explainer project; subsequent runs publish a new deployment.wrangler pages project create then attach via the Cloudflare dashboard.