[BUG] TUI crashes on `constructor.hpp` with `(r||"").toLowerCase is not a function`

Status Fixed / completed
Reported on v2.1.87
Maintainer reply None cached
Activity 5 comments · opened Mar 29, 2026 · closed Apr 10, 2026

Preflight Checklist

What's Wrong?

Claude Code's TUI crashes when it tries to create, write, or edit a file named constructor.hpp.

At first this looked workspace-specific, because I first encountered it in a few repositories. After further testing, I was able to narrow it down much more:

  • Files such as constructor2.hpp, constructor_copy.hpp, and tmp.hpp do not trigger the crash
  • A file named constructor.hpp does trigger the crash
  • This reproduces in different environments, not just one local workspace
  • The problem appears tied to the filename and the write/edit path in the TUI, rather than to the original repository contents

I can reproduce this even with a minimal file named constructor.hpp.

What Should Happen?

Claude Code should be able to create, write, and edit a file named constructor.hpp without crashing the TUI.

Error Messages/Logs

The key error at the beginning is:

```text id="1pab8y"
ERROR (r||"").toLowerCase is not a function. (In '(r||"").toLowerCase()', '(r||"").toLowerCase' is undefined)

/$bunfs/root/src/entrypoints/cli.js:1438:2089


Part of the stack trace near the end:

```text id="2m2jj0"
- g (/$bunfs/root/src/entrypoints/cli.js:1438:2089)
- nGK (/$bunfs/root/src/entrypoints/cli.js:1717:10107)
- render (/$bunfs/root/src/entrypoints/cli.js:1719:2254)
- Qz1 (/$bunfs/root/src/entrypoints/cli.js:1722:1456)
- <anonymous> (/$bunfs/root/src/entrypoints/cli.js:1722:2115)
- $D (/$bunfs/root/src/entrypoints/cli.js:452:20997)
- _z (/$bunfs/root/src/entrypoints/cli.js:452:39538)
- UH (/$bunfs/root/src/entrypoints/cli.js:452:36907)
- xH (/$bunfs/root/src/entrypoints/cli.js:452:36434)
- Hs (/$bunfs/root/src/entrypoints/cli.js:452:52627)

Steps to Reproduce

Minimal reproduction pattern:

  1. Start Claude Code in a fresh folder or fresh session.
  2. Ask Claude Code to create a file named constructor.hpp.
  3. Use minimal contents such as:

```cpp id="q3sd9a"
#pragma once
struct A {};


4. The TUI crashes during the write step.

I can also reproduce the crash when editing a file named `constructor.hpp`.

Control cases that do **not** crash:

1. Create or edit `constructor2.hpp` with the same minimal contents.
2. Create or edit `constructor_copy.hpp` with the same minimal contents.
3. Create or edit `tmp.hpp` with the same minimal contents.

These control cases work normally, which makes me suspect this is specifically related to the filename `constructor.hpp`.

### Claude Model

Opus

### Is this a regression?

Yes, this worked in a previous version.

### Last Working Version

*No response*

### Claude Code Version

2.1.87 (Claude Code)

### Platform

Anthropic API

### Operating System

Windows and Linux

### Terminal/Shell

WSL on Windows locally, and also reproduced in a separate Linux server environment

### Additional Information

Additional narrowing I did:

* Initially this looked repository-specific
* Moving the project to a new directory did not help
* Clearing caches did not help
* Deleting Claude Code's local project state did not help
* I checked for encoding issues, suspicious characters, BOM, zero-width characters, bidi control characters, and similar issues across the codebase and did not find anything
* I tested copies of the original file under different names, and those did not crash
* I tested the same filename in a different directory, and it still crashed
* I tested a minimal `constructor.hpp` file, and it still crashed

At this point, the issue seems strongly tied to the filename `constructor.hpp` during the TUI write/edit flow, rather than to file contents, encoding, inode identity, or a specific repository.

If helpful, I can provide more step-by-step reproduction notes.

View original on GitHub ↗

5 Comments

github-actions[bot] · 6 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/40452
  2. https://github.com/anthropics/claude-code/issues/40160
  3. https://github.com/anthropics/claude-code/issues/39542

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

hankhsu1996 · 6 months ago

I dug into this further and found a likely root cause.

This appears to be an inherited-property bug in the filename/stem-to-language lookup used during diff or syntax-highlighting.

For filenames like constructor.hpp, the stem constructor can resolve to the inherited Object.prototype.constructor when a plain object is used as a dictionary. That non-string value then flows into the language-detection path and eventually triggers:

(r||"").toLowerCase is not a function

This likely affects other inherited property names too, such as:

  • toString.*
  • valueOf.*
  • hasOwnProperty.*
  • __proto__.*

Suggested fix:

  • define the filename map with Object.create(null), or
  • guard so only string values are passed into the language-detection path
Kingmidas74 · 6 months ago

Also experiencing this on macOS (Darwin 25.2.0). The crash happens consistently when resuming after an interrupted response, especially in longer conversations with Go code.

Stack trace is identical:

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

Been hitting this for ~3 days. The workaround of giving specific instructions instead of "continue" sometimes helps, but it's not reliable.

gpersoon · 6 months ago

Seems to occur with any file that has the name constructor in it:

TUI crash: (r||"").toLowerCase is not a function when editing files named constructor.*

Summary

Claude Code crashes when rendering diffs for files whose basename (before the extension) matches an Object.prototype property name, most commonly constructor. The crash occurs in the syntax highlighting language detection code.

Version

  • Claude Code 2.1.90
  • Platform: Linux (WSL2)
  • Runtime: Bun

Steps to reproduce

  1. Create a file named constructor.py (or constructor.js, constructor.rs, etc.)
  2. Start Claude Code and ask it to edit that file
  3. Claude Code crashes during diff rendering

Minimal repro:

mkdir /tmp/repro && cd /tmp/repro
echo "x = 1" > constructor.py
claude  # then ask: "change x to 2 in constructor.py"

Error

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

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

 - g (/$bunfs/root/src/entrypoints/cli.js:1321:2087)
 - XsK (/$bunfs/root/src/entrypoints/cli.js:2760:6419)
 - render (/$bunfs/root/src/entrypoints/cli.js:2762:2254)

Root cause

The XsK function detects the syntax highlighting language from a file path. It uses a plain object YsK as a filename-to-language map:

YsK = {Dockerfile: "dockerfile", Makefile: "makefile", Rakefile: "ruby", Gemfile: "ruby", CMakeLists: "cmake"}

The lookup logic extracts the basename without extension and checks the map:

let q = path.basename(filePath),        // "constructor.py"
    _ = q.split(".")[0] ?? "",           // "constructor"
    f = YsK[q] ?? YsK[_];              // YsK["constructor"] → Object.prototype.constructor!

Since YsK is a plain {}, YsK["constructor"] resolves to Object.prototype.constructor (the built-in Object function) via prototype chain lookup. This is a truthy non-string value, so it passes the guard if (f && ...) and is forwarded to hljs.getLanguage(), which calls .toLowerCase() on it and crashes.

Affected filenames

Any file whose name before the first . matches an Object.prototype property:

  • constructor.py (most common in practice)
  • toString.js
  • valueOf.ts
  • hasOwnProperty.go
  • etc.

Suggested fix

Replace the plain object with Object.create(null) to prevent prototype chain lookups:

// Before
YsK = {Dockerfile: "dockerfile", Makefile: "makefile", ...}

// After
YsK = Object.assign(Object.create(null), {Dockerfile: "dockerfile", Makefile: "makefile", ...})

Or add a hasOwnProperty guard:

f = Object.hasOwn(YsK, q) ? YsK[q] : Object.hasOwn(YsK, _) ? YsK[_] : undefined;

Workaround

Disable syntax highlighting:

export CLAUDE_CODE_SYNTAX_HIGHLIGHT=off
github-actions[bot] · 6 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.