Problem
The stop hook's background memory updater (scripts/hooks/background-memory-update) injects the wrong messages into the Sonnet prompt. It should extract the first user prompt and the last assistant output from the session transcript, but currently extracts the last user message instead of the first.
Root Cause
Line ~100-104 in background-memory-update:
last_user=$(grep '"type":"user"' "$transcript" 2>/dev/null \
| ... \
| tail -1) # ← BUG: gets last user message, should be head -1 for first
The assistant extraction (line ~106-110) correctly uses tail -1 to get the last assistant message.
Fix
Change tail -1 to head -1 on the user message extraction line. The intent is:
- First user message: captures what the session was about (the opening request)
- Last assistant message: captures what was accomplished (the final state)
Verification
- Test with a real session transcript to confirm the first user message is extracted
- Verify the assistant message extraction still gets the last one
- Check that WORKING-MEMORY.md updates reflect the session's opening topic, not a mid-session follow-up
References
Problem
The stop hook's background memory updater (
scripts/hooks/background-memory-update) injects the wrong messages into the Sonnet prompt. It should extract the first user prompt and the last assistant output from the session transcript, but currently extracts the last user message instead of the first.Root Cause
Line ~100-104 in
background-memory-update:The assistant extraction (line ~106-110) correctly uses
tail -1to get the last assistant message.Fix
Change
tail -1tohead -1on the user message extraction line. The intent is:Verification
References
scripts/hooks/background-memory-update:98-110