[BUG] Claude Code crashes when Edit tool renders code containing } braces - Chalk template literal parser in diff/edit display
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?
Claude Code crashes when the Edit tool attempts to render/display code changes for files containing closing braces }. This appears to be a recent regression - the same codebase was being actively developed without this issue until recently.
The crash does NOT occur during:
File search/glob operations ✅
Reading files (even files with many } characters) ✅
The crash DOES occur during:
Edit tool operations on files containing } ❌
What Should Happen?
Rendering closing braces should not cause a claude code crash.
Error Messages/Logs
ERROR undefined is not a constructor (evaluating 'new G($,I,L)')
/$bunfs/root/claude:1139:2360
or
ERROR undefined is not a constructor (evaluating 'new U($,A)')
/$bunfs/root/claude:1147:5029
Steps to Reproduce
- Open Claude Code in any project
- Ask Claude to edit any file containing a closing brace }
- Claude Code crashes when rendering the edit diff
What works: Reading files with } characters (Read tool succeeds)
What crashes: Editing files with } characters (Edit tool diff rendering fails)
Example
> Edit logger.php to add a comment to line 1
[Claude reads file successfully]
[Claude attempts Edit tool]
ERROR undefined is not a constructor (evaluating 'new G($,I,L)')
Root Cause
Chalk's tagged template literal parser crashes on unescaped closing braces:
const chalk = require('chalk');
chalk}; // CRASH: Found extraneous } in Chalk template literal
The Edit tool's diff rendering passes file content through Chalk templates without escaping } characters.
Test Script
const chalk = require('chalk');
const fs = require('fs');
const lines = fs.readFileSync(process.argv[2], 'utf8').split('\n');
lines.forEach((line, i) => {
try {
eval('chalk' + line.replace(//g, '\\') + '');
} catch (e) {
if (e.message.includes('extraneous') || e.message.includes('Chalk template')) {
console.log(Line ${i + 1}: ${line.substring(0, 60)});
}
}
});
Result: Any line containing } crashes.
Impact
Editing is broken for virtually all code files (PHP, JavaScript, C, Java, Go, etc.) - any language using braces for blocks.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
unsure - seems like a brand new issue, i use claude code a lot
Claude Code Version
2.0.72
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Windows Terminal
Additional Information
Issue #14180 reports crashes with Unicode filenames, also citing Chalk template parsing errors. This is the same underlying bug with a different trigger:
Aspect | #14180 | This Issue
----------------|-------------------------|---------------------------
Trigger | Unicode in filenames | } in code content
Operation | File operations | Edit tool diff rendering
Root cause | Chalk tagged template | Same
Error | undefined is not a... | Same
The #14180 author attributed the bug to Unicode handling, but our testing reveals the actual root cause: any content that doesn't conform to Chalk's {stylename text} syntax will crash the parser. Unicode characters likely create byte sequences that the parser misinterprets as malformed style syntax.
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗