Edit tool crashes with 'undefined is not an object (evaluating T.replaceAll)'

Resolved 💬 3 comments Opened Jan 9, 2026 by yonatangross Closed Feb 23, 2026

Description

The Edit tool intermittently crashes with a JavaScript runtime error when attempting to edit files. The error occurs before any file modification takes place.

Error Message

Error: undefined is not an object (evaluating 'T.replaceAll')

Reproduction Steps

  1. Read a bash script file (e.g., a hook script with ~250 lines)
  2. Attempt to use Edit tool to replace a multi-line block
  3. Error occurs consistently on retry attempts

Example That Triggered the Bug

File: .claude/hooks/skill/duplicate-code-detector.sh

Attempted edit (old_string):

        # Search for this name in other files
        DUPLICATES=$(echo "$CODE_FILES" | xargs grep -l "\b$NAME\b" 2>/dev/null | head -5 || true)

Attempted edit (new_string):

        # Search for this name in other files
        # SEC-FIX: Use xargs_grep_word for safe word-boundary matching
        DUPLICATES=$(echo "$CODE_FILES" | xargs_grep_word -l "$NAME" | head -5 || true)

The Edit tool failed 3 consecutive times with the same error on different edit attempts.

Workaround

Using the Write tool to replace the entire file content works successfully. The issue is specifically in the Edit tool's replaceAll code path.

Environment

  • OS: macOS (Darwin 25.2.0)
  • Claude Code: Latest version
  • Model: claude-opus-4-5-20251101

Analysis

The error undefined is not an object (evaluating 'T.replaceAll') indicates that in the Edit tool's JavaScript implementation, a variable T (likely holding file content or a match result) is undefined when .replaceAll() is called on it.

Possible causes:

  1. Special characters in the search string (regex metacharacters like \b, $, etc.)
  2. Multi-line content handling edge case
  3. File content encoding mismatch between Read and Edit operations

Expected Behavior

The Edit tool should either:

  1. Successfully perform the replacement, or
  2. Return a meaningful error message if the old_string is not found

Actual Behavior

JavaScript runtime crash with no actionable information for the user.

View original on GitHub ↗

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