From 75df2e52c1e977543032473ac001f6ee476a144c Mon Sep 17 00:00:00 2001 From: Dennis Hartrampf Date: Sat, 31 Jan 2026 23:30:41 +0100 Subject: [PATCH] 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 --- src/shared/transcript-parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/transcript-parser.ts b/src/shared/transcript-parser.ts index 8a70cca9..ebd2cef0 100644 --- a/src/shared/transcript-parser.ts +++ b/src/shared/transcript-parser.ts @@ -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 '';