[BUG] Claude creating file limit filesystem bug on long or many sessions
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When I'm working long time or in multiple sessions, after hours or a day, claude starts to crash the filesystem.
Claude is throwing errors like that
Error: Working directory "/Users/me/Documents/GIT/project/code" no longer
exists. Please restart Claude from an existing directory.
When I'm then starting a new session of the terminal and enter ls its throwing me ls: .: Operation not permitted. Same when I try to start other apps, like codex = Error: Operation not permitted (os error 1)
And when I try to start claude it throws me the error below.
Nothing from these hints helped when I typed in, even after sessions with Claude later on to fix this issue.
Interestingly, going into my home directory fixes ls as well as claude starting - then anything works fine.
System permissions to disc are given, as it works before smoothly.
iTerm as an alternative terminal works at the moment then.
Only solution that helped me so far is rebooting.
This happens every 2-3 days, so its not a rare thing. Closing all sessions, apps, windows, is a heavy flow breaker.
Thanks for help.
What Should Happen?
Claude should have access, claude should start.
Error Messages/Logs
me@macbook code% ls
ls: .: Operation not permitted
me@macbook code % claude
error: An unknown error occurred, possibly due to low max file descriptors (Unexpected)
Current limit: 10240
To fix this, try running:
ulimit -n 2147483646
If that still doesn't work, you may need to run:
sudo launchctl limit maxfiles 2147483646
Steps to Reproduce
- Work a day or two with Claude over long sessions
- It then appears somehow out of the sudden
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.63 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
22 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
It is NOT a duplicate.
Have to add,
codexhad the only solution that worked so far. After this incident, running these commands:Still, it shouldn't happen anyway.
Root Cause: File Descriptor Leak + macOS TCC Permission Revocation
This is a file descriptor (FD) exhaustion issue that triggers macOS TCC permission revocation as a side effect. Here's the chain:
The Sequence:
open()syscalls faills .failsEvidence:
Operation not permitted(EPERM) — this is TCC, not EACCEStccutil resetfixing it confirms TCC revocationDiagnosis Commands:
Immediate Fix (before reboot):
Preventive (raises FD limits):
Real Fix (needs Claude Code side):
The Node.js process needs proper FD hygiene — likely candidates:
child_process.spawn()withoutstdio: 'ignore'on unused streamskeepAlivepooling properlyfs.watch()) not being disposed---
RevolutionAI — macOS sandbox debugging
I would like to chime in and say I'm seeing the same here when using Cowork. It seems like the file descriptors are leaking in
com.apple.Virtualization.VirtualMachinewhich I believe is used by Claude Code and Cowork. I initially thought it was caused by Docker, but it seems to be isolated to Claude when it's working on files.One thing I did notice, was that when running the latest version of Docker and VirtioFS, I would also see the file descriptors
I'm also seeing that icons will start to become corrupted when file descriptors hit around 230.000 as well as TCC errors in the logs. I tried to reset TCC a few times and it seems to work, but it will go bad again when running Claude for a while.
Model: Sonnet 4.6
Version: 1.1.7714 (Claude desktop app for Mac) and 2.1.25 (claude code/CLI)
Quick chime-in: Using claude code
v2.1.92- ran into this issue today.resetting SystemPolicyDocumentsFolder approval seemed to fix the issue at the moment, but as @xXMrNidaXx pointed out, should not have happened in the first place.
Similar state in claude code
v2.1.107onmacOS 26.3.1- ran into this issue multiple times over the course of last 2 weeks.Also, the fix mentioned in the above comments does not work when working with Warp terminal. Were they given assuming that
claudewas started in the default terminal of the macOS?warp 遇到了
For Warp, the Warp bundle ID is
dev.warp.Warp-Stable(you can check withosascript -e 'id of app "Warp"'ormdls -name kMDItemCFBundleIdentifier /Applications/Warp.app)So it becomes:
Latest error pattern looks like that:
Same the same command can fix it for a specific amount of time, till it happens again.
I have the same error pattern. It is extremely annoying
2.1.145 (Claude Code) still has the issue, and I had to reboot macOS.
Adding a new severity tier to this thread: on macOS this leak now correlates with kernel panics, not just user-visible errors. Same root cause, much worse blast radius when multiple Claude Code instances run concurrently.
Environment
What happened — 4 reboots in 1 week, 2 distinct failure modes, 1 root cause
Mode A — kernel panic (×3) on 5/14, 5/16, 5/21 20:35:
launchd (PID 1) hits a libSystem-internal assert and exits → kernel panic → auto-restart. Survived a macOS version upgrade (26.2 → 26.5), which rules out OS-side bugs as the root cause.
Mode B — system-wide ENFILE freeze (×1) on 5/21 23:26 — the smoking gun:
That's
kern.maxfiles=491520exhausted, surfaced by Claude Code's own Bash tool. Full system became unresponsive; only recovery was long-pressing the power button (ResetCounter-*.diagshowsBoot faults: btn_seq_reset).The fd evidence (the part I think is new)
macOS
JetsamEvent-*.ipsfiles record per-process fd counts at memory-pressure events. From 7 hours before the 23:26 freeze:For scale, every other process at the same moment:
Normal apps are in the 100s. Claude Code single-process is at 51200, ~50–100× normal. The fd:rpage ratio on pid 99001 (12.8:1 vs a normal ~0.05:1) is the structural fingerprint of fd leak — the process holds 51200 kernel fd table entries while occupying only ~60 MB of physical memory.
Across a 12 h window the same PID 92811 held a steady 25600 fds at both 04:06 and 16:34 — fds are not being released over the life of the process, not just leaked at session end.
Why multi-instance is the cliff
A single long-running Claude Code that hits its RLIMIT_NOFILE only kills itself (#47909-style symptoms). Multiple concurrent instances each grow toward their per-process ceiling and collectively pressure
kern.maxfiles. Oncekern.num_filesis close to the system cap:open/dup/socket/kqueueworkload starts hitting allocation failures__abort_with_payload→initproc exited subcode 0xa→ kernel panic (Mode A)open(2)returns ENFILE and the machine freezes hard (Mode B)Both modes are downstream of the same Claude Code fd leak. Heavy users who run multiple agents/sessions in parallel will hit Mode B before Mode A.
Suggested fix priorities
ENOENT, "directory no longer exists", or generic spawn errors. A singlegetrlimit + getdtablesizecheck at error time would let the tool surface "fd exhaustion detected" instead.Diagnostic for anyone hitting this
Single Claude Code process > 5000 fds on a long session = on the leak path.
Request
This issue is blocking adoption for developers working with large monorepos. Since #51933 was previously closed just because the lack of activity, if it was really resolved this appears to be a regression introduced between 2.1.126 and 2.1.143.
Could the team:
Investigate what changed between these versions related to file handle management?
Consider re-opening #51933 or tracking this as a separate regression?
Add regression tests for large monorepo scenarios to prevent this from recurring?
Happy to provide additional diagnostics if helpful.
Reproduction Confirmed - Appears to be Regression from #51933
We're experiencing what appears to be a regression of the file descriptor leak issue reported in #51933, which was previously marked as resolved.
Environment
Observed Behavior
The file descriptor leak manifests in several ways:
ls: .: Operation not permittedafter Claude sessionsImpact
Reproduction Pattern
The issue appears to be triggered by:
/planmodeCurrent Workaround
Downgrading to version 2.1.126 resolves the issue completely:
issue persists on macOS, just got this for the first time, never happened before, probably related to the enw update
macOS上问题依然存在,
same problem in macos
To anyone face this issue, I also encountered with ghostty, the issue still there with recent versions, also I suspect my recent SSD failure is related as well, I had an external SSD connected to my Mac mini and it's broken after 2 weeks of heavy agent work within that SSD, maybe not just Claude, all the agents could contribute to the issue
Fix: TCC "Operation not permitted" after multi-agent runs (macOS)
Root Cause
This is not a file-descriptor leak — it's a TCC (Transparency, Consent, and Control) cache corruption issue.
When you run Claude Code with multiple agents for an extended period,
lsand other file operations on protected folders (Desktop, Documents, Downloads) start returningOperation not permitted. The cause:SystemPolicyDesktopFolder,SystemPolicyDocumentsFolder,SystemPolicyDownloadsFolder)tccutil resettemporarily fixes it because it flushes the TCC daemon's cache — but the issue recursWhy
tccutil reset SystemPolicyDesktopFolder com.apple.Terminalworks (even if you don't use Terminal)tccutil resettriggers a global TCC daemon cache flush. It doesn't matter that Terminal doesn't have those grants — the flush clears the corrupted cache entry for all apps, including Ghostty/iTerm2.The Fix (2 layers)
Layer 1: Remove redundant per-folder TCC grants (primary fix)
If your terminal app has Full Disk Access, the per-folder grants are redundant — and they're the thing that gets corrupted. Remove them:
FDA alone covers all file access. No per-folder grants = nothing to corrupt.
Verify FDA is still active in System Settings → Privacy & Security → Full Disk Access.
Layer 2: LaunchAgent auto-fix safety net (in case it recurs)
A LaunchAgent that runs every 5 minutes, checks the macOS unified log for TCC denial events for your terminal app, and if found, auto-flushes the TCC cache — same effect as running
tccutil resetmanually.~/bin/tcc-autofix.sh(replaceghostty/com.mitchellh.ghosttywith your terminal app):~/Library/LaunchAgents/com.user.tcc-autofix.plist(replace YOUR_USERNAME):Install:
Notes
ghostty/com.mitchellh.ghosttywith your terminal app (e.g.iTerm2/com.googlecode.iterm2,Terminal/com.apple.Terminal,WezTerm/com.github.wez.wezterm)~/Library/Logs/tcc-autofix.log(empty = no issues)Environment
That's a solid write up. It's weird though, because when I run the project (which has 200.000 files in it) through Claude Code and Docker Desktop (with this using VirtioFS), I see the file descriptors climb immediately at boot/start. If I switch Docker to using the older, and slower gRPC Fuse filesystem, my file descriptors are about halved by this operation.
It's true, that after I ran out of file descriptors, I usually see a lot of TCC "degradation", like corruption like you're pointing out.
EDIT: I've sorted the problem by moving the massive amounts of files out of the "working directory", and symlinked it in (as suggested by Claude itself). This has solved the issue for me in relation to Claude, but it still persists with Docker Desktop using VirtioFS.
I have a question, do you all use ccswitch in this case?
I'm so tired of the problem. I'm moving folders out of the icloud trap. Claude Code sessions on a folder that is not in the icloud trap do not suffer this problem.
I found moving things out of iCloud to be PAINFUL... so here's a script that will sync it, validate it, and create a symlink from the original location to the new for backward compatibility.
!! dependency:
--> install the latest rsync (6-19-2026)
--> brew install rsync
Script: sync_move_verify.sh
might be related https://www.reddit.com/r/OpenAI/comments/1ucf4px/openai_codex_has_a_bug_that_could_kill_your_ssd/ it could be the codex broken my external SSD after 2 months of heavy usage