Skip to content

[BUG] Memory Leak from Unbounded Session File Growth #20200

@Cireo

Description

@Cireo

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?

Version: Claude Code 2.1.17
OS: macOS 15.4.1 (24E263)
Platform: darwin

Claude added plenty of its own opinions in this report, I only cleared a few out.

Summary

Claude Code exhibits memory leak behavior where session files (.jsonl) grow unbounded over long conversations, causing processes to consume 5-6GB of RAM and experience severe performance degradation (multi-minute
delays between responses before tokens are seen to be consumed).

Evidence

  1. Excessive Memory Usage
  • Claude processes observed using 5.7GB RAM (one instance)
  • Current active sessions: 839MB-1.2GB each
  1. Massive Session Files
  • Projects directory: 604MB total
  • 19 session files over 5MB each
  • Largest session file: 195MB (1,193 snapshots)
  • Average snapshot size: ~164KB per entry
  • Multiple sessions: 57MB, 28MB, 26MB, 25MB, 24MB, 22MB (multiple), 21MB, etc.
  1. Performance Impact
  • Multi-minute delays with no token generation ("thinking" with no progress)
  • Pauses after command output completion lasting minutes
  • Performance improved only after high-memory process died/crashed

Expected Behavior

  • Session files should be pruned/rotated automatically when exceeding size thresholds
  • Memory usage should remain reasonable even for long conversations
  • /clear command should actually clean up session storage, not just the UI
  • Old session snapshots should be garbage collected

Actual Behavior

  • Session .jsonl files grow indefinitely with no automatic cleanup
  • Each snapshot stores ~164KB of data (seems excessive)
  • Memory usage scales with session file size
  • Processes eventually consume 5-6GB RAM and become unresponsive
  • /clear only clears conversation view, not underlying session data

Workaround

Close any running claude processes. Can also try removing files as below but don't have a reproduction to know whether this helped.

Delete large session files (loses history)

find ~/.claude/projects -name "*.jsonl" -size +10M -delete

Clean file history cache

rm -rf ~/.claude/file-history/*

Additional Context

  • Issue occurs across multiple projects (monorepo workflows)
  • Not related to heavy data processing - just normal CLI usage
  • Performance degradation is gradual over weeks of use
  • No visible indication to user that session files are growing out of control

What Should Happen?

Proposed Solutions

  1. Automatic session pruning: Delete or archive sessions older than N days
  2. Size-based rotation: When session file exceeds threshold (e.g., 5MB), start new session
  3. Snapshot optimization: Reduce snapshot size from 164KB to something more reasonable
  4. Memory management: Properly release memory after loading session files
  5. Manual cleanup command: Add /cleanup-sessions or similar

Error Messages/Logs

Steps to Reproduce

Steps to Reproduce

  1. Use Claude Code regularly over several weeks
  2. Have long-running conversations (with occasional /clear commands)
  3. Work across multiple projects
  4. Monitor memory usage: ps aux | grep claude
  5. Check session file sizes: find ~/.claude/projects -name "*.jsonl" -size +5M

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.17

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

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