[BUG] TypeError "undefined is not an object (evaluating 'H.replace')" replaces Bash tool output
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] 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:28UTC
(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:
uv run --no-sync python -c "from xxx.yyy …"uv run --no-sync pytest tests/test_xxx.py -qcd … ; 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_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗