Skip to content

[BUG] Infinite logging loop in debug files causes 200GB+ disk usage #16093

@EthanJStark

Description

@EthanJStark

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?

The .claude/debug directory contains a critical bug where the performance monitoring system enters an infinite recursive logging loop, creating debug log files that can grow to 20GB+ each and consume hundreds of gigabytes of disk space.

After 7 days of normal usage, my .claude/debug directory accumulated 42GB from just 481 conversations, compared to a coworker's 232MB from similar usage (180x difference). Investigation revealed 4 files containing 500+ million lines, 99% of which are recursive log messages.

Root Cause

The performance monitoring system logs operations that take >75ms. When debug log files grow large enough that writing to them becomes slow (>75ms), the logger logs the slow append operation:

[DEBUG] [SLOW OPERATION DETECTED] fs.appendFileSync (93.7ms)

This log write is itself slow, triggering another log entry, creating an infinite loop that only stops when:

  1. The disk fills completely (ENOSPC errors observed)
  2. The session ends
  3. The process crashes

Evidence

Files analyzed (last 7 days only):

Size Total Lines Recursive Logs % Recursive
20 GB 233,674,896 231,491,851 99.1%
12 GB 143,852,744 142,149,389 98.8%
9 GB 106,387,020 104,926,012 98.6%
1.7 GB 18,940,785 18,334,540 96.8%
~43 GB 502,855,445 496,901,792 98.8%

What Should Happen?

Debug logs should:

  • Not log their own logging operations (prevent recursive logging)
  • Have reasonable size limits with automatic rotation
  • Not enter infinite loops under any circumstances
  • Stop logging if write operations become slow (circuit breaker pattern)

Error Messages/Logs

**Sample log output from a poisoned file:**


2026-01-02T03:52:58.760Z [DEBUG] [SLOW OPERATION DETECTED] fs.appendFileSync (93.7ms)
2026-01-02T03:52:58.857Z [DEBUG] [SLOW OPERATION DETECTED] fs.appendFileSync (96.6ms)
2026-01-02T03:52:59.060Z [DEBUG] [SLOW OPERATION DETECTED] fs.appendFileSync (202.3ms)
2026-01-02T03:52:59.165Z [DEBUG] [SLOW OPERATION DETECTED] fs.appendFileSync (103.9ms)
2026-01-02T03:52:59.335Z [DEBUG] [SLOW OPERATION DETECTED] fs.appendFileSync (169.2ms)
...
[continues for millions of lines until...]
...
2026-01-02T03:53:12.316Z [ERROR] Failed to refresh marketplace: ENOSPC: no space left on device, write

Steps to Reproduce

Possible triggers:

  1. Running long Claude Code sessions (multiple hours)
  2. Debug logging is enabled (default)
  3. Disk I/O becomes slow (older SSD, disk nearly full, high system load)
  4. A debug log file crosses the ~500MB-1GB threshold where writes become slow

Once triggered, the loop compounds exponentially until disk is full.

To verify if you're affected:

# Check total size
du -sh ~/.claude/debug

# Find poisoned files (>1GB)
find ~/.claude/debug -type f -size +1G

# Detailed analysis
for file in ~/.claude/debug/*.txt; do
  size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null)
  if [ "$size" -gt 1000000000 ]; then
    lines=$(wc -l < "$file")
    slow=$(grep -c "SLOW OPERATION DETECTED.*appendFileSync" "$file" 2>/dev/null || echo 0)
    echo "$size bytes | $lines lines | $slow recursive logs | $(basename "$file")"
  fi
done

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.0.76

Platform

AWS Bedrock

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api:bedrockIssue relates to AWS Bedrockarea:corebugSomething isn't workinghas reproHas detailed reproduction stepsperf:memoryplatform:macosIssue specifically occurs on macOSstaleIssue is inactive

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions