claude-code - 💡(How to fix) Fix [BUG] TypeError "undefined is not an object (evaluating 'H.replace')" replaces Bash tool output

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

I had Claude self-debug an error it ran into: error as their result instead of the command's real output: The error is surfaced to the model as tool_result content with is_error: true, caught the exception and substituted it for the result.

  • 3 tool calls returned the error, at 00:19:01, 00:21:27, 00:23:28 UTC
  • The error content is identical each time and carries is_error: true. when the exception fires (all three are sandboxed uv run commands producing
  • The model, receiving error junk instead of real output, then hallucinated None is recoverable. The session log persists only the error string, not a JS with an opaque error, which can lead the model to hallucinate success/failure (e.g. "internal error processing Bash output", not a bare TypeError). No JS error should happen. Undefined should be a function 😉

Error Messages/Logs

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

I had Claude self-debug an error it ran into:

Summary

During a normal session, three separate Bash tool calls returned a harness-level error as their result instead of the command's real output:

  undefined is not an object (evaluating 'H.replace')

This is a TypeError thrown inside Claude Code's bundled runtime while processing a tool result (H is a minified identifier; .replace() was called on undefined). The error is surfaced to the model as tool_result content with is_error: true, so the actual command output never reaches the model. The CLI did not crash — it caught the exception and substituted it for the result.

Environment

  • Claude Code: 2.1.157 (confirmed from the session log, not just current install)
  • Install: native installer (~/.local/share/claude/versions/2.1.157)
  • OS: macOS 26.3 (Darwin 25.3.0), arm64 (Apple Silicon)
  • Runtime present: node v24.14.1, bun 1.3.10

What actually happened (verified from the session transcript)

Session log: ~/.claude/projects/<proj>/11985998-…-723e052e6531.jsonl

  • 3 tool calls returned the error, at 00:19:01, 00:21:27, 00:23:28 UTC (2026-05-30), i.e. ~2 minutes apart, each a single sequential Bash call — NOT a parallel/batched call.
  • All three were uv run --no-sync … commands run under the macOS command sandbox:
    1. uv run --no-sync python -c "from xxx.yyy …"
    2. uv run --no-sync pytest tests/test_xxx.py -q
    3. cd … ; uv run --no-sync ruff check …
  • The error content is identical each time and carries is_error: true.
  • The CLI did not hard-crash at the OS level (no node/Claude entry in ~/Library/Logs/DiagnosticReports/), so the TypeError is caught internally in the tool-result handling path.

Repro signal (best guess — unconfirmed)

The common factor is a Bash call whose stdout/stderr is being post-processed when the exception fires (all three are sandboxed uv run commands producing multi-line output). H.replace suggests .replace() is called on a field of the tool result/output object that was undefined for these runs. A likely-relevant detail: these run through the macOS command sandbox, so the result object may carry sandbox/exit metadata that was absent or shaped differently here.

I could not reproduce on demand; it appears intermittent.

Collateral effects observed in-session

  • The model, receiving error junk instead of real output, then hallucinated downstream state (e.g. fabricated [main <sha>] … commit-confirmation lines). Verified these were hallucinations: git reflog shows HEAD never advanced past a5dd7447; no fabricated commit ever entered git, working tree is clean, and there are zero .orig/.rej files. (The prior session's report of "fabricated commits", "40 .orig/.rej files", and "parallel batch trigger" is NOT supported by the transcript — flagging so these aren't treated as reproducer facts.)

Backtrace availability

None is recoverable. The session log persists only the error string, not a JS stack. The native build is minified with no public sourcemaps, so H cannot be symbolicated externally. Debug logging was off (no recent files in ~/.claude/debug/).

To capture a real stack, the maintainers (or repro attempts) should run with debug logging enabled and reproduce a sandboxed Bash/uv run call:

  claude --debug
  # or set verbose/ANTHROPIC_LOG before launching

Impact

Silent and high-blast-radius: the real command output is discarded and replaced with an opaque error, which can lead the model to hallucinate success/failure state. A defensive fix would be to (a) guard the .replace() call site against undefined, and (b) make this failure mode unambiguous to the model (e.g. "internal error processing Bash output", not a bare TypeError).

What Should Happen?

No JS error should happen. Undefined should be a function 😉

Error Messages/Logs

Steps to Reproduce

I haven't reproduced it.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.157 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] TypeError "undefined is not an object (evaluating 'H.replace')" replaces Bash tool output