RangeError: Maximum call stack size exceeded in endOfWORD() - CLI crashes with long outputs

Resolved 💬 5 comments Opened Oct 8, 2025 by jeffelix Closed Jan 7, 2026

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 CLI (v2.0.10) crashes with stack overflow when AI generates responses longer than ~15,000 characters due to infinite recursion in the
endOfWORD() function.

## Environment

  • Claude Code Version: 2.0.10
  • Node.js Version: v22.17.0
  • NPM Version: 10.9.2
  • OS: WSL2 - Ubuntu 24.04.2 LTS
  • Kernel: Linux 6.6.87.2-microsoft-standard-WSL2
  • Platform: x86_64
  • Terminal: xterm-256color

## Stack Trace
RangeError: Maximum call stack size exceeded
at U8.isOverWhitespace (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:820:399)
at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1741)
at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
[... infinite recursion continues ...]

## Steps to Reproduce

  1. Open Claude Code CLI (v2.0.10)
  2. Ask AI to analyze a large file line by line (e.g., "Read banca_global.py line by line - 610 lines")
  3. AI starts generating detailed analysis response
  4. When output reaches ~15,000-20,000 characters
  5. CLI attempts to render the text
  6. endOfWORD() function enters infinite recursion
  7. Stack overflow occurs → CLI crashes
  8. Terminal disconnects, all context lost

## Expected Behavior
CLI should render long responses without crashing, even with 50,000+ characters. Other terminal tools (vim, less, cat) handle massive outputs without
issues.

## Actual Behavior
CLI crashes and disconnects after ~15,000 characters of output, losing all conversation context and forcing restart.

## Impact
Severity: High
Frequency: Consistently reproducible

Problems Caused:

  • Loss of conversation context (hours of work lost)
  • Inability to analyze large files
  • Severely degraded user experience for professional code analysis
  • Need for manual workarounds

## Current Workaround
Instructing AI (via prompt engineering) to generate structured analysis instead of literal line-by-line citations, keeping output <15,000 characters
per response.

This works, but:

  • Depends on AI awareness of the bug
  • Not sustainable long-term
  • Limits product functionality

## Additional Information
I have a 15MB log file (91,961 lines) documenting 14+ consecutive crashes from this bug. Available for analysis if needed.

## Suggested Fix

  1. Add maximum recursion limit in endOfWORD()
  2. Implement fallback when recursion exceeds limit
  3. Optimize word-wrap algorithm for edge cases
  4. Add buffer protection before stack overflow
  5. Alternative: Implement automatic pagination for large outputs

I'm available to provide complete logs, reproducible test cases, and beta testing for potential fixes.

Thank you for looking into this! This bug significantly impacts usability for professional development workflows.

What Should Happen?

CLI should render AI responses of any length without crashing. Terminal should remain stable even when processing 50,000+ character outputs, similar
to how other terminal tools (vim, less, cat) handle large text without issues.

Error Messages/Logs

RangeError: Maximum call stack size exceeded
      at U8.isOverWhitespace (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:820:399)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1741)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
      at U8.endOfWORD (file:///home/jeffelix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:818:1834)
      [recursion continues infinitely until stack overflow]
  Script done.

Steps to Reproduce

  1. Open Claude Code CLI v2.0.10 in terminal
  2. Start a conversation with the AI
  3. Ask: "Please analyze this file line by line: banca_global.py (610 lines)"
  4. AI begins generating detailed line-by-line analysis
  5. When AI response reaches approximately 15,000-20,000 characters
  6. CLI attempts to render the output
  7. The endOfWORD() function in cli.js enters infinite recursion
  8. Stack overflow occurs
  9. Terminal crashes with "Maximum call stack size exceeded"
  10. All conversation context is lost, requiring CLI restart

Note: Bug occurs consistently when AI generates responses longer than ~15k characters, regardless of file type or content being analyzed.

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

Unknown - issue exists in current version

Claude Code Version

2.0.10 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

PowerShell

Additional Information

Selecione: Linux
E adicione no campo de texto:
WSL2 - Ubuntu 24.04.2 LTS (Kernel 6.6.87.2-microsoft-standard-WSL2)

View original on GitHub ↗

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