You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
post-tool-hook.sh infers SESSION_ID from the newest .jsonl by mtime, so under concurrent sessions it can vouch for the wrong one #212
scripts/post-tool-hook.sh derives the session it is recording for from the most recently modified transcript:
SESSION_ID=$(basename "$LATEST_JSONL" .jsonl)
It does not read the session_id that PostToolUse supplies on stdin. With two Claude Code sessions live in the same project, whichever transcript was touched last wins, so the hook can attribute a tool call to a session that did not make it.
Why it is worth filing now rather than later
This was a benign inaccuracy while tmp/capture-alive was a single last-write-wins slot: a wrong id there was transient, overwritten by the next tool call, and nothing read it as a durable claim.
#211 changes that. The capture-gap detector now membership-tests a per-session marker store (tmp/capture-alive.d/<session-id>), and those markers persist. A marker written under the wrong id is a durable false claim in both directions:
a marker created for session B while session A did the work vouches for B, so if B's hooks really were dead, the warning that exists to tell you so stays silent;
and A gets no marker from that call, though sources 2 and 3 (the legacy slot, last-save.json) will usually still cover it.
The false-negative direction is the one that matters, because the whole point of that warning is to report hooks not being registered — the one condition the user cannot otherwise detect. #211 deliberately weighted the design toward silence over crying wolf, which is right, and that makes the accuracy of the evidence more load-bearing than it was, not less.
Scope, and honestly assessed risk. LATEST_JSONL is not only used for the session id in that script — the line-count and throttle logic are derived from the same variable, so switching the id to a stdin-supplied one means deciding what LATEST_JSONL means for those, and that is a materially larger change than #206 called for. The agent flagged it rather than quietly doing it, which was the right call.
What closing this looks like
Read session_id from the PostToolUse stdin JSON and use it for the marker (and for anything else that is genuinely about this session's identity).
Work out what the line-count/throttle logic actually needs — most likely the transcript belonging to that same session id, not "the newest one" — and make that explicit rather than incidental.
Keep the existing path-component validation on the id before it is used as a filename; stdin is not more trustworthy than a basename.
Pin it: two transcripts in one project, the older one being the session the hook is invoked for, and assert the marker lands under the right id. That test fails today.
Note the harness trap from #210 when writing that pin — bootstrap-dirs.sh:112 redirects stderr to logs/hook-errors.log, so a failing script gives you an empty result.stderr and no clue.
Activity
fix(post-tool): take the session id from stdin, not the newest transc…
fix: give user-prompt-hook.sh and post-tool-hook.sh the #411 stdin cw…
fix: per-tool-call capture on Codex still forked save-session.sh into…