Skip to content

[BUG] Session files grow unboundedly, causing OOM crash on startup ("Aborted (core dumped)") #20367

@LorenzoNava99

Description

@LorenzoNava99

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Claude Code crashes with "Aborted (core dumped)" on startup when large session files exist in ~/.claude/projects/.

The process memory climbs continuously (visible in btop/htop) until it reaches ~20GB, then gets OOM-killed. This happens regardless of which directory you start Claude Code from, because the session index is loaded globally on startup.

Session .jsonl files can grow to multiple gigabytes with no size limit, rotation, or compaction. In my case:

  • One session file reached 2.1 GB
  • Another reached 1.7 GB

These were multi-agent sessions using subagents for batch processing. The parent session file logs all subagent outputs, causing exponential growth.

Workaround: Manually move the large .jsonl files out of ~/.claude/projects/ to restore functionality.

What Should Happen?

Session files should have a size limit with indexing - not implemented for single session tracking

Error Messages/Logs

Aborted (core dumped)

No stack trace or error message is shown - the process simply gets killed by the OOM killer after memory usage reaches system limits.

Steps to Reproduce

  1. Run a long multi-agent session using subagents (e.g., batch orchestration with 100+ subagent tasks)
  2. Let the session run until it becomes very long
  3. Try to restart Claude Code from any directory
  4. Observe memory usage climbing in htop/btop until OOM kill

To identify problematic files:

find ~/.claude -name "*.jsonl" -type f -exec du -h {} + 2>/dev/null | sort -rh | head -20

Workaround:

mkdir -p ~/claude-session-backup
mv ~/.claude/projects/*/LARGE_SESSION_ID.jsonl ~/claude-session-backup/

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.17 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Terminal.app (macOS)

Additional Information

Root cause analysis:

Session files are append-only JSONL with no size management. The structure is:

  • ~/.claude/projects/{project-path}/{session-id}.jsonl - main session log
  • ~/.claude/projects/{project-path}/{session-id}/subagents/ - subagent logs

When using multi-agent workflows, the parent session records ALL subagent output in its own .jsonl file, in addition to the subagent's own log. This causes rapid growth.

Suggested fixes (in order of impact):

  1. Immediate: Add a file size check on startup; skip or warn about sessions > 100MB
  2. Short-term: Implement session compaction (summarize old tool outputs, keep recent messages)
  3. Long-term: Stream session data instead of loading entirely into memory; implement log rotation

Attached: Screenshot showing session file sizes (2.1GB and 1.7GB files)

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions