CLI crashes with RangeError when background task generates large output
Description
Claude Code CLI v2.0.36 crashes with a RangeError: Invalid array length when a background bash task generates large amounts of output (600+ lines). The crash occurs in the rendering/display code when trying to show background task status.
Steps to Reproduce
- Start a background Python script that prints 600+ lines of output
- Use
BashOutputtool or try to view background task status - CLI crashes with RangeError
Example that triggers the bug
# Python script that prints 710 URLs before downloading
for i, link in enumerate(links, 1):
print(f"{i}. {link['name']}")
print(f" URL: {link['url']}")
When this runs as a background task and Claude tries to display the output, the CLI crashes.
Error Stack Trace
RangeError: Invalid array length
at d1A (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:199:5463)
at EYA.get (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:199:6664)
at LTA.renderer (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:201:818)
at LTA.onRender (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:220:5884)
at XR0.YR0.signal (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:94:1908)
at X (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:94:1315)
at Object.E (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:94:1601)
at Object.C [as onRender] (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:94:2103)
at resetAfterCommit (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:196:356)
at I4 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:100:39469)
Expected Behavior
CLI should gracefully handle large background task output, either by:
- Truncating output beyond a certain size
- Paginating the display
- Streaming output without storing it all in memory
Actual Behavior
CLI crashes and needs to be restarted. The crash occurs in LTA.renderer when the array buffer for displaying output becomes too large.
Environment
- Claude Code version: v2.0.36
- Platform: macOS (Darwin 24.5.0)
- Node.js installation: /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/
Workaround
Reduce the output from background scripts to avoid generating large amounts of output at once.
Impact
This makes it difficult to run long-running background tasks that need verbose logging or progress updates.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗