[BUG] Log stream error: bufio.Scanner: token too long

Resolved 💬 3 comments Opened Oct 1, 2025 by vedranjukic Closed Jan 6, 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?

When running Claude code in an non-interactive env with the following params

claude --dangerously-skip-permissions --print --output-format=stream-json --include-partial-messages --verbose

The Claude process sometimes breaks in the middle of the task execution with an error: Error reading STDOUT: bufio.Scanner: token too long

The error is not easy to reproduce and happens occasionally. The only thing I could figure out is that it happens more likely on subsequent runs of the same task (prompt).

What Should Happen?

The task log should continue until the task is completed.

Error Messages/Logs

[15:21:31] ⚙️  **System Ready**
[15:21:34] 🤖 I'll help you analyze and fix this issue. Let me start by understanding the codebase structure and locating the relevant code for command execution.
[15:21:43] 🏁 **Claude Finished**
[15:21:48] 🚀 **Task Started**
[15:21:48] 🚀 **Task Started**
[15:21:48] 🚀 **Task Started**
[15:21:51] 🚀 **Task Started**
[15:21:51] 🚀 **Task Started**
[15:21:52] ❌ Error reading STDOUT: bufio.Scanner: token too long
[15:21:58] ⚠️  Error: write EPIPE
[15:21:58] ⚠️      at afterWriteDispatched (node:internal/stream_base_commons:159:15)
[15:21:58] ⚠️      at writeGeneric (node:internal/stream_base_commons:150:3)
[15:21:58] ⚠️      at Socket._writeGeneric (node:net:966:11)
[15:21:58] ⚠️      at Socket._write (node:net:978:8)
[15:21:58] ⚠️      at writeOrBuffer (node:internal/streams/writable:570:12)
[15:21:58] ⚠️      at _write (node:internal/streams/writable:499:10)
[15:21:58] ⚠️      at Writable.write (node:internal/streams/writable:508:10)
[15:21:58] ⚠️      at lJ (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:719:14730)
[15:21:58] ⚠️      at wF1.write (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:3639:1114)
[15:21:58] ⚠️      at d4Q (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:3648:346) {
[15:21:58] ⚠️    errno: -32,
[15:21:58] ⚠️    code: 'EPIPE',
[15:21:58] ⚠️    syscall: 'write'
[15:21:58] ⚠️  }
[15:21:58] ⚠️  Error: write EPIPE
[15:21:58] ⚠️      at afterWriteDispatched (node:internal/stream_base_commons:159:15)
[15:21:58] ⚠️      at writeGeneric (node:internal/stream_base_commons:150:3)
[15:21:58] ⚠️      at Socket._writeGeneric (node:net:966:11)
[15:21:58] ⚠️      at Socket._write (node:net:978:8)
[15:21:58] ⚠️      at writeOrBuffer (node:internal/streams/writable:570:12)
[15:21:58] ⚠️      at _write (node:internal/streams/writable:499:10)
[15:21:58] ⚠️      at Writable.write (node:internal/streams/writable:508:10)
[15:21:58] ⚠️      at lJ (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:719:14730)
[15:21:58] ⚠️      at wF1.write (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:3639:1114)
[15:21:58] ⚠️      at d4Q (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:3648:346) {
[15:21:58] ⚠️    errno: -32,
[15:21:58] ⚠️    code: 'EPIPE',
[15:21:58] ⚠️    syscall: 'write'
[15:21:58] ⚠️  }
[15:21:58] ⚠️  Error: write EPIPE
[15:21:58] ⚠️      at afterWriteDispatched (node:internal/stream_base_commons:159:15)
[15:21:58] ⚠️      at writeGeneric (node:internal/stream_base_commons:150:3)
[15:21:58] ⚠️      at Socket._writeGeneric (node:net:966:11)
[15:21:58] ⚠️      at Socket._write (node:net:978:8)
[15:21:58] ⚠️      at writeOrBuffer (node:internal/streams/writable:570:12)
[15:21:58] ⚠️      at _write (node:internal/streams/writable:499:10)
[15:21:58] ⚠️      at Writable.write (node:internal/streams/writable:508:10)
[15:21:58] ⚠️      at lJ (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:719:14730)
[15:21:58] ⚠️      at wF1.write (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:3639:1114)
[15:21:58] ⚠️      at d4Q (file:///usr/local/share/nvm/versions/node/v24.8.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:3648:346) {
[15:21:58] ⚠️    errno: -32,
[15:21:58] ⚠️    code: 'EPIPE',
[15:21:58] ⚠️    syscall: 'write'
[15:21:58] ⚠️  }
[15:21:58] ❌ Claude execution failed: exit status 1

Steps to Reproduce

PROMPT="I need help fixing the issue {GITHUB_ISSUE_DESCRIPTION}
claude --dangerously-skip-permissions --print --output-format=stream-json --include-partial-messages --verbose $PROMPT

Claude Model

Sonnet (default)

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.0.1

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Non-interactive/CI environment

Additional Information

_No response_

View original on GitHub ↗

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