claude --resume crashes on Edit tool error results (missing null check in renderToolResultMessage)

Resolved 💬 3 comments Opened Mar 30, 2026 by LEON-gittech Closed Apr 2, 2026

Bug Description

claude --resume <session-id> crashes with Cannot read properties of undefined (reading 'startsWith') when the session file contains Edit tool results that returned error strings instead of the expected {filePath, structuredPatch, originalFile} object.

Steps to Reproduce

  1. Have a session where some Edit tool calls failed (e.g., "Error: File has not been read yet" or "Error: String to replace not found in file")
  2. Run claude --resume <session-id>
  3. CLI crashes during transcript rendering

Error Output

TypeError: Cannot read properties of undefined (reading 'startsWith')
    at Object.XEq [as renderToolResultMessage] (/home/user/.nvm/versions/node/v24.3.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:...)
    at hNI (/home/user/.nvm/versions/node/v24.3.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:...)
    at renderConversation (/home/user/.nvm/versions/node/v24.3.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:...)

Root Cause Analysis

The renderToolResultMessage function for the Edit tool (H0K in minified code) destructures the tool result as:

function renderToolResultMessage({filePath: H, structuredPatch: $, originalFile: q}, K, {style: _, verbose: f}) {
    let z = H.startsWith(/* ... */);
    // ...
}

When an Edit tool call fails, the toolUseResult field in the session JSONL contains a plain error string (e.g., "Error: File has not been read yet") instead of the expected object {filePath, structuredPatch, originalFile}. Destructuring a string yields undefined for all named properties, so H (filePath) is undefined, and H.startsWith() throws.

The Fix

The renderToolUseMessage for Edit (eZK in minified code) already has the correct guard:

function eZK({filePath: H, ...}) {
    if (!H) return null;  // ← This guard exists here
    // ...
}

The same null check should be added to renderToolResultMessage (H0K):

function renderToolResultMessage({filePath: H, structuredPatch: $, originalFile: q}, K, {style: _, verbose: f}) {
    if (!H) return null;  // ← Add this guard
    let z = H.startsWith(/* ... */);
    // ...
}

The caller already handles null returns correctly — there is an existing if (!q.toolUseResult) return null guard upstream, but it only catches null/undefined values, not error strings that are truthy.

Workaround

Manually patch the session JSONL file: find entries where toolUseResult is an error string (for Edit tool results) and set them to null. The upstream if (!q.toolUseResult) return null guard will then skip rendering these entries.

Environment

  • Claude Code: v2.1.86 and v2.1.87 (both affected)
  • Node.js: v24.3.0
  • OS: Linux (Ubuntu)

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗