RangeError on Large Output

Resolved 💬 11 comments Opened Jul 28, 2025 by Laosson Closed Jan 4, 2026

Summary

Claude Code CLI crashes with RangeError: Invalid string length when examining databases that return large amounts of output data.

Environment

  • Claude Code CLI Version: Latest (based on Node.js v20.18.1)
  • Platform: Linux 6.14.0-24-generic
  • Node.js Version: v20.18.1

Bug Description

When running database examination commands that produce large output (particularly database status checks), Claude Code crashes with a JavaScript string length error instead of gracefully handling the large data.

Error Details

RangeError: Invalid string length
    at Socket.<anonymous> (file:///home/sadara/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:780:8787)
    at Socket.emit (node:events:530:35)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:561:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
    at Readable.push (node:internal/streams/readable:392:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:191:23)

Steps to Reproduce

  1. Have a Python script that queries databases and outputs large amounts of data
  2. Run the script through Claude Code CLI
  3. When the output exceeds JavaScript's maximum string length (~2^28 characters), the CLI crashes

Expected Behavior

Claude Code should handle large outputs gracefully by either:

  • Streaming the output in chunks
  • Truncating very large outputs with a warning
  • Implementing pagination for large datasets
  • Providing a configuration option for maximum output size

Actual Behavior

Claude Code crashes with RangeError: Invalid string length and terminates the session.

Impact

  • Severity: High
  • Frequency: Reproducible when working with database operations that return large datasets
  • Workaround: Manually limit output in user code (not ideal)

Technical Details

The error occurs in the CLI's output handling mechanism when trying to create a string that exceeds JavaScript's maximum string length limit. This appears to be in the socket data handling at line 780 of cli.js.

Suggested Fixes

  1. Implement streaming output: Instead of buffering all output into a single string, stream it in manageable chunks
  2. Add output size limits: Implement configurable limits on output size with graceful truncation
  3. Add pagination: For very large outputs, implement pagination or "show more" functionality
  4. Error handling: Catch RangeError exceptions and provide a user-friendly message instead of crashing

Files Affected

  • /home/sadara/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:780
  • Output handling/buffering mechanism in Claude Code CLI

Test Case

Create a Python script that outputs a very large string (>500MB) to reproduce the issue:

# This will crash Claude Code CLI
print("x" * (500 * 1024 * 1024))  # 500MB string

Additional Context

This issue was discovered while working with database management scripts that query multiple databases and return comprehensive status information. The crash log was saved to claude-crashlog.txt in the working directory.

Priority

This should be considered a high-priority bug as it affects the reliability of Claude Code when working with data-intensive applications, which is a common use case for development tools.

View original on GitHub ↗

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