Repository navigation
Description
Symptom
Right after /clear, the next user prompt is annotated with:
remember: your previous session was not captured. If you just installed or enabled the plugin, that is expected — capture starts now. Otherwise its hooks were not registered for that session; run /remember:doctor.
Capture was healthy. Observed 2026-07-27 23:08 in the DVSI project; at that moment .remember/now.md had been written 23:07:48 and today-2026-07-27.md 22:50:53. Nothing was missed.
Mechanism
scripts/session-start-hook.sh:139-148:
PREV_JSONL=$(ls -t "$(claude_projects_dir)/${PREV_SLUG}"/*.jsonl 2>/dev/null | tail -n +2 | head -1)
PREV_ID=$(basename "$PREV_JSONL" .jsonl)
SEEN_ID=$(cat "$CAPTURE_ALIVE" 2>/dev/null)
if [ -n "$PREV_ID" ] && [ "$SEEN_ID" != "$PREV_ID" ] && grep -q '"tool_use"' "$PREV_JSONL"; then
# warn
fiThe check assumes SessionStart means "a new session id started, so capture-alive still holds the previous one".
/clear does not mint a new session id. It fires SessionStart with source=clear while the transcript, the session id, and the .jsonl file all stay the same. Confirmed in the incident: the newest .jsonl (b0a76ca7…, 513K — far too large to be a just-created session) is the current session, and tmp/capture-alive already contained b0a76ca7… because that session had made tool calls before the clear. PREV_ID resolved to the genuinely older c1ab365b….
So on a /clear, SEEN_ID != PREV_ID is structurally guaranteed:
| before /clear | at SessionStart(source=clear) | |
|---|---|---|
| newest jsonl | current session | current session (unchanged) |
capture-alive |
current session id | current session id |
computed PREV_ID |
— | second-newest = an older session |
The comparison can never hold, whatever the capture state. Same reasoning applies to compact and fork — every same-session SessionStart source.
Root enabler
session-start-hook.sh never reads its stdin JSON, so it has access to neither source nor session_id. It cannot distinguish a same-session restart from a fresh start, and it cannot exclude the current session from the "previous session" computation. The PREV_ID heuristic (second-newest file) is a stand-in for a session id the hook could simply be told.
The comment at lines 110-132 is aware a plugin-enable is indistinguishable from a fresh start and deliberately accepts a one-off false positive there. This is a different case: recurring, once per /clear, forever.
Secondary defect
tmp/capture-alive stores a single id (post-tool-hook.sh:111-113, last-write-wins). It can answer "which session most recently made a tool call", not "was session X captured". Once X is superseded the evidence is gone, so even with the /clear case fixed the detector stays fragile — e.g. two rapid sessions, or any ordering where the file advances before SessionStart reads it.
Repro
- In a project with the plugin active, run some tool calls (so
capture-alive= current session id). /clear.- Send any prompt.
- Warning appears — attached to the user prompt, since SessionStart writes
tmp/capture-gap-notice(session-start-hook.sh:147) anduser-prompt-hook.sh:46emits it on the next turn.
Proposed fix
- Parse the SessionStart stdin JSON and run the gap check only for
sourceinstartup/resume. Kills this false positive on its own. - Also use
session_idfrom that JSON to exclude the current session when pickingPREV_JSONL, instead of relying on "second-newest by mtime". - Optional, for the secondary defect: make
capture-alivea short append-only ring of recent session ids and test membership rather than equality.
Tests
source=clear(andcompact,fork) withcapture-alive== current session id ⇒ no notice written.source=startup, previous session has"tool_use"and was never seen ⇒ notice written (existing behaviour preserved).source=startup, previous session captured ⇒ no notice.- Previous session with zero tool calls ⇒ no notice (existing guard).
Activity
ca-sringert commentedon Jul 27, 2026
Second repro of the secondary defect (recovery-saved session still flagged)
Confirming the "secondary defect" noted above independently of the
/clearcase — this one hits it via a genuinely distinct previous session, not a same-session restart.Session
d9dd5dcd-3bee-4e65-b3ba-180f87fd1211(72 lines, containstool_use) ended normally. It never crossedthresholds.delta_lines_trigger/cooldowns.save_secondsduring its own life, so it was never live-saved — it was captured entirely via the next session'sSessionStartrecovery block:tmp/last-save.jsonafterward:{"sessions": {..., "d9dd5dcd-3bee-4e65-b3ba-180f87fd1211": 72, ...}, "session": "d9dd5dcd-3bee-4e65-b3ba-180f87fd1211", "line": 72}72/72 lines — fully captured.
But
tmp/capture-aliveat that same moment still held an unrelated older session id (the last one that had a livePostToolUsefire), sincesave-session.sh's recovery path never touchescapture-alive— onlypost-tool-hook.shdoes. NextSessionStartcomputedPREV_ID=d9dd5dcd-..., compared againstcapture-alive, found a mismatch, sawtool_usein the transcript, and wrote the notice — despite the recovery block in that exact same hook run having just successfully saved it.So this isn't only a
/clear/resume/compact/forkproblem: it fires on any short session that ends before its own live-save thresholds are hit and gets picked up by the next session's recovery instead — which, per the thresholds discussion elsewhere in this repo (delta_lines_trigger: 50,save_seconds: 120), is probably the common case for short sessions, not an edge case.This seems to support prioritizing proposed fix §3 (make
capture-alivea membership-testable record of saved sessions, e.g. checked againstlast-save.json'ssessionsmap — the same source the recovery block's ownSAVED_QUERYalready trusts) rather than treating it as optional — §1/§2 alone (stdinsource/session_idfiltering) wouldn't catch this case, since a genuinely freshstartupalso triggers it.Plugin v0.8.9.
fix(post-tool): take the session id from stdin, not the newest transc…
fix(capture-gap): store capture evidence per session, not in one slot (…
perf(hooks): post-tool-hook 30 → 17 spawns per tool call (#230)
perf(hooks): post-tool-hook 30 → 17 spawns per tool call (#230) (#233)
fix(session-start): the previous session is identified, not counted to (
fix(session-start): stop re-injecting the whole recap at source=compa…
Fix CI on PR #1084: #1046 guard fixtures, prune-count assertion
Fix #1046, #1047, #1052: cross-store recovery, quadratic stdin extrac…