From 1fac57535ea4f49b443244a8e1a11cdf00ca2972 Mon Sep 17 00:00:00 2001 From: Rajiv Sinclair Date: Thu, 12 Mar 2026 19:59:47 -0700 Subject: [PATCH] fix: gracefully handle missing transcript files in worktree sessions (#1326) When Claude Code runs in a worktree (via Agent tool with isolation: "worktree"), the transcript path points to the worktree's project directory. After the worktree is cleaned up, the Stop hook fires but the transcript file no longer exists, causing extractLastMessage() to throw. This error triggers Claude to respond, which fires another Stop hook, creating an infinite error loop. Changed throws to warn-and-return-empty so the summarize hook exits cleanly with exit 0 instead of cascading errors. Co-authored-by: Claude Opus 4.6 --- src/shared/transcript-parser.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shared/transcript-parser.ts b/src/shared/transcript-parser.ts index ebd2cef0..8a7482ab 100644 --- a/src/shared/transcript-parser.ts +++ b/src/shared/transcript-parser.ts @@ -13,12 +13,14 @@ export function extractLastMessage( stripSystemReminders: boolean = false ): string { if (!transcriptPath || !existsSync(transcriptPath)) { - throw new Error(`Transcript path missing or file does not exist: ${transcriptPath}`); + logger.warn('PARSER', `Transcript path missing or file does not exist: ${transcriptPath}`); + return ''; } const content = readFileSync(transcriptPath, 'utf-8').trim(); if (!content) { - throw new Error(`Transcript file exists but is empty: ${transcriptPath}`); + logger.warn('PARSER', `Transcript file exists but is empty: ${transcriptPath}`); + return ''; } const lines = content.split('\n');