Skip to content

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

Closed as not planned
Closed as not planned

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

Activity

  1. github-actions commented on Jan 23, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] Session files grow to multi-GB due to normalizedMessages duplication in subagent progress entries #19040
    2. Session JSONL files grow to multi-GB size due to bloated "progress" entries #18905
    3. [BUG] Sessions >500MB not resumable despite frequent compacting #19963

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. Cireo commented on Jan 23, 2026

    @Cireo
    Author

    Found 3 possible duplicate issues:

    No (or extremely rare) subagents, no multi-GB files (memory), no compacting (only /clear)

  3. github-actions commented on Mar 6, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  4. github-actions commented on Mar 16, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  5. locked as resolved and limited conversation to collaborators on Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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