[BUG] RangeError: Invalid string length

Resolved 💬 12 comments Opened May 5, 2025 by amaruy Closed Jan 8, 2026

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [x] Other: Claude Code CLI
  • Claude CLI version: <!-- output of claude --version -->
  • Operating System: Ubuntu (likely Ubuntu server)
  • Terminal: Standard Ubuntu terminal

Bug Description

The Claude Code CLI is repeatedly throwing "RangeError: Invalid string length" errors when attempting to process output from a command.

Steps to Reproduce

  1. Create or use an existing prompt file (claude_prompt.txt)
  2. Run the Claude CLI command with output redirection:

``
claude -p --verbose --output-format stream-json --dangerously-skip-permissions @claude_prompt.txt >> "transcript.log"
``

  1. Observe multiple "RangeError: Invalid string length" errors in stderr

Expected Behavior

The command should execute successfully, processing the prompt file and writing output to the specified log file without errors.

Actual Behavior

The CLI repeatedly throws the same error approximately 30+ times:

RangeError: Invalid string length
    at Socket.<anonymous> (file:///home/ubuntu/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:550:2864)
    at Socket.emit (node:events:524:28)
    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)

The error consistently occurs at the same line in the code, suggesting a systematic issue with string length handling in the CLI application.

Additional Context

View original on GitHub ↗

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