[BUG] in text rendering/measurement code that doesn't properly handle edge cases in string segmentation
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.98
- Operating System: Windows 11, WSL2, Ubuntu 22.04 24.04.3 LTS
- Terminal: Bash 5.2.21(1)-release
Bug Description
Environment:
Tool: @anthropic-ai/claude-code CLI
Node versions tested: v22.18.0 and v20.19.4
OS: Linux (based on file paths)
Frequency: Multiple crashes per day
Error Description:
Consistent TypeError when the CLI attempts to render text in the terminal. The error occurs in the string width measurement function during text layout calculations.
Error Message:
ERROR Cannot read properties of undefined (reading 'codePointAt')
file:///.../node_modules/@anthropic-ai/claude-code/cli.js:809:28790
Stack Trace Pattern:
The error consistently occurs in:
B3 function (string width measurement)
SP2.stringIndexToDisplayWidth
SP2.getPositionFromOffset
During text rendering/wrapping operations
Key Details:
Error persists across Node.js versions (20 and 22)
Occurs during normal usage and when trying to use /bug command
The text segmentation appears to produce undefined values that the width measurement function cannot handle
Clean reinstall did not resolve the issue
Impact:
Tool is unusable due to frequent crashes
Cannot submit bugs through the /bug command as it triggers the same error
Blocking normal development workflow
Reproduction:
Crashes occur during regular usage. Even attempting to submit a bug report via /bug triggers the crash.
Attempted Solutions (all unsuccessful):
Downgraded from Node 22 to Node 20
Clean npm cache and reinstall
Fresh installation of claude-code
Steps to Reproduce
- Install claude-code CLI:
npm install -g @anthropic-ai/claude-code - Run claude-code in terminal with any command or prompt
- During normal interaction, the CLI crashes (occurs multiple times per day)
- Alternative: Try to submit a bug using
/bugcommand - this also triggers the crash
Expected Behavior
- The CLI should render text properly in the terminal and allow normal interaction
- The
/bugcommand should open a bug submission interface - Text rendering should handle all unicode/special characters gracefully
Actual Behavior
- CLI crashes with TypeError:
Cannot read properties of undefined (reading 'codePointAt') - Crash occurs in the string width measurement function (
B3) at line 809:28790 - The error happens during text layout/wrapping calculations
- Unable to use the tool for any meaningful work due to frequent crashes
- Cannot even submit bugs through the built-in
/bugcommand
Additional Context
Environment Details:
- OS: Linux (Ubuntu/Debian based on paths)
- Node.js versions tested: v22.18.0 and v20.19.4
- Installation path:
~/.nvm/versions/node/vXX/lib/node_modules/@anthropic-ai/claude-code/ - Frequency: Multiple crashes per day during regular usage
Full Stack Trace (Node v20.19.4):
ERROR Cannot read properties of undefined (reading 'codePointAt')
file:///home/user/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:809:28790
- B3 (file:///home/user/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:809:28790)
- SP2.stringIndexToDisplayWidth (file:///home/user/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:853:959)
- SP2.getPositionFromOffset (file:///home/user/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:857:1040)
- *5.getPosition (file:///home/user/.nvm/versions/node/v20.19.4/lib/node*modules/@anthropic-ai/claude-code/cli.js:853:208)
- *5.render (file:///home/user/.nvm/versions/node/v20.19.4/lib/node*modules/@anthropic-ai/claude-code/cli.js:847:2255)
- WT1 (file:///home/user/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:878:434)
Troubleshooting Already Attempted:
- ✗ Downgraded Node.js from v22 to v20
- ✗ Clean npm cache (
npm cache clean --force) - ✗ Complete reinstall of claude-code
- ✗ Fresh installation after removing all npm global packages
Analysis:
The issue appears to be in the text segmentation/measurement code where Intl.Segmenter or similar functionality produces undefined segments that the width calculation function cannot handle. The B3 function attempts to call codePointAt() on an undefined value during terminal text rendering.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗