claude-code - 💡(How to fix) Fix [BUG] Runaway file descriptor leak in Claude (v2.1.117) on large monorepo [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#51933Fetched 2026-04-23 07:41:01
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×5

Error Message

Error Messages/Logs

No specific Claude error message is shown; failure manifests as resource exhaustion.

Code Example

Monitoring file descriptors:

lsof -p <PID> | wc -l

Observed growth:

t=0s   → ~500
t=2s   → ~8000
t=5s   → ~40000
t=10s  → ~65582
t=??s  → ~130000 (before crash)

System impact:
- Hits ulimit -n
- Android Studio starts failing (file access errors)
- Terminal and OS become unstable

No specific Claude error message is shown; failure manifests as resource exhaustion.
RAW_BUFFERClick to expand / collapse

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 (v2.1.117) in code/cowork mode causes a runaway increase in open file descriptors when run in a large monorepo. The number of open files grows rapidly (tens of thousands within seconds) and does not stabilize, eventually reaching ~130,000 and exhausting system limits.

The behavior is independent of the user task (even trivial prompts trigger it) and suggests a file descriptor leak and/or uncontrolled file traversal loop. This leads to system-wide instability and crashes.

What Should Happen?

Claude should:

  • Open a bounded number of files
  • Reuse or cache file handles where possible
  • Properly close file descriptors after use
  • Stabilize resource usage after initial context loading

Even in large repositories, file descriptor usage should remain within reasonable limits and not grow indefinitely.

Error Messages/Logs

Monitoring file descriptors:

lsof -p <PID> | wc -l

Observed growth:

t=0s   → ~500
t=2s   → ~8000
t=5s   → ~40000
t=10s  → ~65582
t=??s  → ~130000 (before crash)

System impact:
- Hits ulimit -n
- Android Studio starts failing (file access errors)
- Terminal and OS become unstable

No specific Claude error message is shown; failure manifests as resource exhaustion.

Steps to Reproduce

  1. Open a large Android/Kotlin monorepo (multi-module)
  2. Run Claude from the repository root: claude
  3. Execute any simple task, e.g.: "summarize this repository" or "open README"
  4. In parallel, monitor file descriptors: lsof -p <CLAUDE_PID> | wc -l

Result:

  • File descriptors increase rapidly and continuously
  • No stabilization occurs
  • Eventually reaches tens of thousands (65k+) and up to ~130k before crash

Claude Model

Not sure / Multiple models

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.117

Claude Code Version

2.1.117

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

extent analysis

TL;DR

The most likely fix for the issue is to identify and address the file descriptor leak in the Claude Code, potentially by implementing proper file descriptor closure or reuse mechanisms.

Guidance

  • Investigate the Claude Code's file handling mechanisms to identify potential leaks or uncontrolled file traversal loops.
  • Monitor system resources and file descriptor usage to understand the growth pattern and identify potential bottlenecks.
  • Consider implementing a bounded limit on the number of open files or a caching mechanism to reuse file handles.
  • Review the code changes between the last working version and the current version to identify potential regressions.

Example

No specific code snippet can be provided without more information about the Claude Code's internal implementation. However, a general example of proper file descriptor closure in Python might look like:

with open('file.txt', 'r') as file:
    # Use the file
    pass  # file is automatically closed here

Notes

The issue seems to be specific to the Claude Code's interaction with large monorepos, and the exact cause may require further investigation into the code's internal workings.

Recommendation

Apply a workaround by implementing a file descriptor limit or a caching mechanism to mitigate the issue until a proper fix can be developed. This is because the issue is causing system-wide instability and crashes, and a temporary workaround can help prevent these problems while a more permanent solution is being developed.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING