fix: handle missing assistant messages gracefully in transcript parser

When a user exits Claude Code before any assistant response is generated,
the summarize Stop hook would crash with:
"No message found for role 'assistant' in transcript"

This happened because extractLastMessage() threw an error when no message
of the requested role was found. The fix returns an empty string instead,
which the summarize handler already handles gracefully (it logs
hasLastAssistantMessage: false and continues).

This is consistent with the function's existing behavior - it already
returns '' in other edge cases (line 64).

Fixes sessions that exit early before assistant responds.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Dennis Hartrampf
2026-01-31 23:30:41 +01:00
committed by Alex Newman
parent 40e699209f
commit 75df2e52c1
+1 -1
View File
@@ -58,7 +58,7 @@ export function extractLastMessage(
// If we searched the whole transcript and didn't find any message of this role
if (!foundMatchingRole) {
throw new Error(`No message found for role '${role}' in transcript: ${transcriptPath}`);
return '';
}
return '';