Memory leak when loading session with binary stdout data

Resolved 💬 3 comments Opened Jan 31, 2026 by bluwork Closed Jan 31, 2026

Summary

Claude Code enters an infinite memory consumption loop (~200MB/second) when loading a session that contains binary data (e.g., PDF) captured in a command's stdout.

Environment

  • Claude Code version: 2.1.27
  • OS: Linux
  • Platform: x86_64

Steps to Reproduce

  1. In a Claude Code session, run a command that outputs binary data to stdout (e.g., downloading a PDF without redirecting to file):

``bash
curl -s "http://example.com/file.pdf"
``

  1. End the session normally
  1. Start a new Claude Code session in the same project directory
  1. Send any prompt (e.g., "Hi")
  1. Observe memory consumption growing at ~200MB/second

Expected Behavior

Claude Code should handle binary output gracefully - either truncate it or not choke when loading sessions containing it.

Actual Behavior

  • The main claude process consumes memory indefinitely (~200MB/sec)
  • Process must be killed manually to prevent OOM

Root Cause

A session .jsonl file contained ~500KB of raw PDF binary in a toolUseResult.stdout field. On session load, processing this binary causes pathological memory behavior.

Workaround

Clear the project cache:

rm -rf ~/.claude/projects/{project-folder}/

Suggested Fixes

  1. Detect binary output (null bytes / non-UTF8) and truncate with [binary output truncated]
  2. Cap stdout/stderr capture size
  3. Handle binary content in session files without infinite loops

View original on GitHub ↗

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