[BUG] ulimit -n unlimited causes lsof (and similar tools) to hang/spin at 100% CPU

Resolved 💬 2 comments Opened Mar 8, 2026 by kernoeb Closed Apr 5, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report
  • [x] I am using the latest version of Claude Code

What's Wrong?

Claude Code sets ulimit -n unlimited (file descriptors) in its Bash tool shell environment. This causes macOS lsof to spin at 100% CPU indefinitely, because lsof iterates over all possible file descriptors per process, and "unlimited" makes that number astronomically large.

The spawned lsof processes become orphaned CPU hogs (100% CPU each) that persist until manually killed.

What Should Happen?

lsof and other system tools should work normally within Claude Code's Bash tool. The FD soft limit should be set to a reasonable value (e.g. 1024 or 10240), or at least not unlimited.

Error Messages/Logs

# Inside Claude Code Bash tool:
$ ulimit -n
unlimited

$ timeout 5 /usr/sbin/lsof -h
# Hangs, exits with 124 (killed by timeout)

# Fix: setting a reasonable limit makes it work instantly
$ bash -c 'ulimit -n 1024; lsof -h'
# Works immediately

Steps to Reproduce

  1. Open Claude Code on macOS
  2. Run ulimit -n via the Bash tool → outputs unlimited
  3. Run lsof -h (or any lsof command) via the Bash tool → hangs forever at 100% CPU
  4. Reproduce outside Claude Code: ulimit -n unlimited && /usr/sbin/lsof -h → same hang

Claude Model

  • Opus

Is this a regression?

I don't know

Claude Code Version

2.1.71

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Other (Ghostty)

Additional Information

  • macOS 15.7.3 (Darwin 24.6.0), Apple Silicon (M1 Max)
  • The root cause is that macOS lsof scans all possible FDs up to the soft limit for each process. With unlimited, this becomes ~10 billion iterations per process, causing a CPU spin.
  • Workaround: bash -c 'ulimit -n 1024; lsof <args>'
  • Other tools that iterate over FD ranges may also be affected.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗