claude-code - 💡(How to fix) Fix CLI crash: highlight.js toLowerCase TypeError during long sessions [1 comments, 2 participants]

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…
GitHub stats
anthropics/claude-code#45519Fetched 2026-04-09 08:03:31
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Error Message

ERROR  (r||"").toLowerCase is not a function. (In '(r||"").toLowerCase()', '(r||"").toLowerCase' is undefined)

/$bunfs/root/src/entrypoints/cli.js:1317:2087

The stack trace dumps ~860KB of minified highlight.js / CLI bundle source to stderr.

Root Cause

The error originates in the bundled highlight.js syntax highlighter. The variable r (expected to be a language string) is undefined or a non-string value, causing .toLowerCase() to throw. This likely happens when rendering a tool result containing unusual or large content (e.g., Metal shader source, long compiler diagnostics).

Code Example

ERROR  (r||"").toLowerCase is not a function. (In '(r||"").toLowerCase()', '(r||"").toLowerCase' is undefined)

/$bunfs/root/src/entrypoints/cli.js:1317:2087

---

(typeof r === 'string' ? r : '').toLowerCase()
RAW_BUFFERClick to expand / collapse

Bug description

Claude Code crashes during long/overnight sessions with a TypeError in the syntax highlighter. The crash terminates the session, making unattended overnight runs unreliable.

Error

ERROR  (r||"").toLowerCase is not a function. (In '(r||"").toLowerCase()', '(r||"").toLowerCase' is undefined)

/$bunfs/root/src/entrypoints/cli.js:1317:2087

The stack trace dumps ~860KB of minified highlight.js / CLI bundle source to stderr.

Root cause

The error originates in the bundled highlight.js syntax highlighter. The variable r (expected to be a language string) is undefined or a non-string value, causing .toLowerCase() to throw. This likely happens when rendering a tool result containing unusual or large content (e.g., Metal shader source, long compiler diagnostics).

Reproduction

  • Happens during long multi-agent sessions with heavy tool use (code search, compilation, Metal GPU kernel work)
  • Not deterministic — occurs after extended use, not immediately
  • Kills the entire CLI process, losing session state

Environment

  • Claude Code version: 2.1.97
  • Platform: macOS (Darwin 25.3.0), Apple Silicon M3 Ultra
  • Shell: zsh

Suggested fix

Wrap the toLowerCase() call in a type guard, e.g.:

(typeof r === 'string' ? r : '').toLowerCase()

Or catch errors in the highlight pass so rendering failures don't crash the entire CLI.

extent analysis

TL;DR

Wrap the toLowerCase() call in a type guard to prevent the TypeError from crashing the Claude Code session.

Guidance

  • Verify the issue by checking if the error occurs when rendering unusual or large content, such as Metal shader source or long compiler diagnostics.
  • Apply the suggested fix by wrapping the toLowerCase() call in a type guard, e.g., (typeof r === 'string' ? r : '').toLowerCase().
  • Consider catching errors in the highlight pass to prevent rendering failures from crashing the entire CLI.
  • Test the fix by running long multi-agent sessions with heavy tool use to ensure the error no longer occurs.

Example

// Before
(r || "").toLowerCase()

// After
(typeof r === 'string' ? r : '').toLowerCase()

Notes

This fix assumes that the r variable is expected to be a string, and that wrapping the toLowerCase() call in a type guard will prevent the TypeError. However, the root cause of the r variable being undefined or a non-string value may still need to be investigated.

Recommendation

Apply the workaround by wrapping the toLowerCase() call in a type guard, as this will prevent the TypeError from crashing the session and allow for further investigation into the root cause of the issue.

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