CLI crash: task/object names matching JS prototype properties (e.g. 'constructor')

Resolved 💬 3 comments Opened Mar 31, 2026 by surajthomask Closed Apr 3, 2026

Bug Description

Claude Code CLI crashes with a toLowerCase error when internal object lookups collide with JavaScript prototype property names like constructor.

Error

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

File: /$bunfs/root/src/entrypoints/cli.js:1301:2087

Root Cause

Somewhere in the CLI, a plain JavaScript object ({}) is used for key-value storage/lookup. When a key matches a built-in Object.prototype property (e.g. constructor, toString, valueOf, hasOwnProperty, __proto__), the lookup returns the inherited prototype value (a Function) instead of undefined.

The pattern (r||"").toLowerCase() then crashes because:

  • r is the built-in constructor function (truthy → ||"" fallback skipped)
  • Functions don't have .toLowerCase()

Reproduction

The crash was triggered when Claude attempted to write a markdown file whose content/context involved the word "constructor" as an identifier in a way that hit the affected lookup path. The exact internal code path is in minified cli.js so hard to pinpoint further.

Suggested Fix

Replace plain object storage with Map, Object.create(null), or add Object.hasOwn() guards wherever user-supplied strings are used as object keys.

Environment

  • macOS (Darwin 25.3.0)
  • Claude Code CLI (latest as of 2026-03-31)

View original on GitHub ↗

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