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 <noreply@anthropic.com>
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user