CLI crash: highlight.js toLowerCase TypeError during long sessions

Resolved 💬 4 comments Opened Apr 9, 2026 by alvgeppetto Closed Apr 18, 2026

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.

View original on GitHub ↗

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