From 0c3fc7074e2efed089839e26d6deff6554856a43 Mon Sep 17 00:00:00 2001 From: Taro Kawakami Date: Sun, 19 Apr 2026 14:35:21 +0900 Subject: [PATCH] review: broaden CLAUDE_TRANSCRIPT_PATH fallback to cover missing/empty JSON fields Previously the env fallback ran only when JSON.parse threw. If stdin was valid JSON but omitted transcript_path or provided a non-string/empty value, the script dropped to the getSessionIdShort() fallback path, re-introducing the collision this PR targets. Validate the parsed transcript_path and apply the env-var fallback for any unusable value, not just malformed JSON. Matches coderabbit's outside-diff suggestion and keeps both input-source paths equivalent. Refs #1494 --- scripts/hooks/session-end.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/hooks/session-end.js b/scripts/hooks/session-end.js index 4ad08a4f..d7ed8f59 100644 --- a/scripts/hooks/session-end.js +++ b/scripts/hooks/session-end.js @@ -179,14 +179,22 @@ function mergeSessionHeader(content, today, currentTime, metadata) { } async function main() { - // Parse stdin JSON to get transcript_path + // Parse stdin JSON to get transcript_path; fall back to env var on missing, + // empty, or non-string values as well as on malformed JSON. let transcriptPath = null; try { const input = JSON.parse(stdinData); - transcriptPath = input.transcript_path; + if (input && typeof input.transcript_path === 'string' && input.transcript_path.length > 0) { + transcriptPath = input.transcript_path; + } } catch { - // Fallback: try env var for backwards compatibility - transcriptPath = process.env.CLAUDE_TRANSCRIPT_PATH; + // Malformed stdin: fall through to the env-var fallback below. + } + if (!transcriptPath) { + const envTranscriptPath = process.env.CLAUDE_TRANSCRIPT_PATH; + if (typeof envTranscriptPath === 'string' && envTranscriptPath.length > 0) { + transcriptPath = envTranscriptPath; + } } const sessionsDir = getSessionsDir();