Repository navigation
Description
The problem
hooks/hooks.json registers SessionStart, UserPromptSubmit and PostToolUse. There is no hook on the way out, so the end of a session is saved only by luck.
Saving is driven by post-tool-hook.sh, gated on thresholds.delta_lines_trigger and cooldowns.save_seconds (120s). Whatever happens after the last save that clears those gates is never written. A session that ends in conversation rather than tool calls — a design discussion, a review, a decision — can lose its entire final stretch, which is often the part worth keeping.
features.recovery exists to soften this: the next session start looks for what the previous one missed. That is a repair positioned after the loss instead of before it, and it only helps if there is a next session in the same project.
The same gap hits the handoff. /remember is manual, so it is skipped exactly when it matters most — long sessions that end abruptly. Related: #341, where the handoff banner re-announces a stale note because nothing has replaced it.
Proposed change
Register a SessionEnd hook that unconditionally:
- flushes the current buffer to
now.md, ignoring the cooldown and the delta threshold — this is the last chance, not a routine tick; - writes the handoff note, so
/rememberbecomes an override rather than the only path; - exits 0 on every failure path, like the other hooks.
Open question — settle this first
When does SessionEnd actually fire? Specifically: /clear, a clean quit, a crash, a killed terminal, and a session that ends by hitting the usage cap.
This determines whether the change is worth building. If it only fires on a graceful exit, it fixes the polite case and misses the one that loses the most work — and the honest conclusion may be that recovery must stay regardless. Check the current hook reference before writing code; do not infer the behaviour from the name.
Also worth confirming whether the payload distinguishes the reason for ending, since a /clear and a crash may deserve different handling.
Acceptance
- Behaviour confirmed against the hook documentation and recorded in this issue before implementation starts.
- A test asserting the flush happens with the cooldown unexpired and the delta below threshold.
- Tests for empty input and a missing data dir, matching the existing hooks fail-soft contract.
- README and
docs/updated with the new hook in the table.
Activity
Add a SessionEnd hook that flushes what PostToolUse missed (#368)
release 0.22.0 — guards that were written next door