Skip to content

Commit 3aa79cc

Browse files
Fix Claude SDK spawn errors and handle expired sessions (#70)
Two issues fixed: 1. MCP Warmup "spawn node ENOENT" error - warmupMcpCache() was missing pathToClaudeCodeExecutable option - SDK fell back to spawning via 'node' which isn't in PATH when launched from GUI - Now uses getBundledClaudeBinaryPath() like the chat function 2. Session expired crash handling - When resuming a session that no longer exists in Claude CLI storage, the process would crash with "No conversation found with session ID" - Now detects this error, clears the invalid sessionId from database, and shows user-friendly "Session expired" message - User can simply send their message again to start fresh
1 parent 8aa6e20 commit 3aa79cc

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/lib/trpc/routers/claude.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ export async function warmupMcpCache(): Promise<void> {
300300
env: buildClaudeEnv(),
301301
permissionMode: "bypassPermissions" as const,
302302
allowDangerouslySkipPermissions: true,
303+
// Use bundled binary to avoid "spawn node ENOENT" errors
304+
pathToClaudeCodeExecutable: getBundledClaudeBinaryPath(),
303305
}
304306
})
305307

@@ -1465,7 +1467,20 @@ ${prompt}
14651467
let errorContext = "Claude streaming error"
14661468
let errorCategory = "UNKNOWN"
14671469

1468-
if (err.message?.includes("exited with code")) {
1470+
// Check for session-not-found error in stderr
1471+
const isSessionNotFound = stderrOutput?.includes("No conversation found with session ID")
1472+
1473+
if (isSessionNotFound) {
1474+
// Clear the invalid session ID from database so next attempt starts fresh
1475+
console.log(`[claude] Session not found - clearing invalid sessionId from database`)
1476+
db.update(subChats)
1477+
.set({ sessionId: null })
1478+
.where(eq(subChats.id, input.subChatId))
1479+
.run()
1480+
1481+
errorContext = "Previous session expired. Please try again."
1482+
errorCategory = "SESSION_EXPIRED"
1483+
} else if (err.message?.includes("exited with code")) {
14691484
errorContext = "Claude Code process crashed"
14701485
errorCategory = "PROCESS_CRASH"
14711486
} else if (err.message?.includes("ENOENT")) {

src/renderer/features/agents/lib/ipc-chat-transport.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ const ERROR_TOAST_CONFIG: Record<
8282
description:
8383
"The Claude process exited unexpectedly. Try sending your message again or rollback.",
8484
},
85+
SESSION_EXPIRED: {
86+
title: "Session expired",
87+
description:
88+
"Your previous chat session expired. Send your message again to start fresh.",
89+
},
8590
EXECUTABLE_NOT_FOUND: {
8691
title: "Claude CLI not found",
8792
description:

0 commit comments

Comments
 (0)