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
- 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"
- End the session normally
- Start a new Claude Code session in the same project directory
- Send any prompt (e.g., "Hi")
- 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
claudeprocess 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
- Detect binary output (null bytes / non-UTF8) and truncate with
[binary output truncated] - Cap stdout/stderr capture size
- Handle binary content in session files without infinite loops
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗