[BUG] lsof zombie processes accumulate after CLI session exits
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?
Description
After Claude Code CLI sessions terminate (normally or abruptly), hundreds of
lsof processes remain running as orphans, gradually degrading system
performance.
Observed behavior
- 1016 orphaned lsof processes found on macOS after several CLI sessions
- All execute: lsof -a -d cwd -bwPln -Ffn -p <PID>
- The target PIDs no longer exist (dead CLI sessions)
- All processes are reparented to PID 1 (init) with state U (uninterruptible
wait)
- Associated temp file (/tmp/claude-XXXX-cwd) already deleted
- Processes accumulate across sessions and are never cleaned up
Root cause (likely)
Claude Code spawns lsof -a -d cwd to monitor the current working directory of
its Node.js process (likely part of the sandbox/security layer). When the
session ends, these child processes are not killed, possibly because:
- No SIGTERM/SIGCHLD handler cleans them up
- They are spawned detached or in a way that survives parent exit
- The temp file they depend on is deleted but the process keeps waiting
Impact
- Hundreds to thousands of zombie processes after a day of usage
- Noticeable macOS performance degradation (memory, process table bloat)
- Requires manual pkill -f "lsof -a -d cwd -bwPln" to recover
Environment
- macOS 15 (Darwin 25.3.0)
- Claude Code CLI (latest as of 2026-03-19)
What Should Happen?
Expected behavior
lsof watcher processes should be terminated when the parent CLI session exits. A signal handler or process group cleanup should ensure no orphans remain.
Error Messages/Logs
Steps to Reproduce
Steps to reproduce
- Open a Claude Code CLI session (claude in terminal)
- Work normally (run tools, execute bash commands, etc.)
- Terminate the session with Ctrl+C + Ctrl+C (double interrupt)
- Start a new session
- Repeat throughout the day, sometimes running multiple sessions in parallel
- After several sessions, check: ps aux | grep -c "lsof -a -d cwd" — count grows with each terminated session and never decreases
Notes
- Normal daily workflow: sequential and sometimes parallel CLI sessions, each terminated via double Ctrl+C
- The lsof processes survive session termination and are never cleaned up
- A full workday can easily produce 1000+ orphaned processes
- Only workaround is manual cleanup: pkill -f "lsof -a -d cwd -bwPln"
- I am currently on the last version, but I worked all week and claudes updates itself several times a day so I don't really know which version cause this trouble.
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.79
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Diagnostic output
$ claude --version
2.1.79 (Claude Code)
$ ps aux | grep -c "lsof -a -d cwd"
1016
$ ps -eo pid,ppid,stat,comm,args | grep "lsof -a -d cwd" | head -5
46511 1 U lsof lsof -a -d cwd -bwPln -Ffn -p 45679
46527 1 U lsof lsof -a -d cwd -bwPln -Ffn -p 45679
53740 1 U lsof lsof -a -d cwd -bwPln -Ffn -p 52730
53736 1 U lsof lsof -a -d cwd -bwPln -Ffn -p 52730
(... 1012 more)
# Target PIDs no longer exist:
$ ps -p 45679,52730
PID PPID COMM ARGS
(empty — both processes are dead)
# All processes are orphaned (PPID=1) and in U (uninterruptible) state
$ ps -eo stat | grep -c "^U"
1013This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗