Desktop app leaks pseudo-terminals (ptys) until the system runs out (forkpty: Device not configured)

Resolved 💬 10 comments Opened Jun 9, 2026 by tanmayverma Closed Jun 22, 2026

Bug report — Claude desktop app leaks pseudo-terminals (ptys) until the system runs out

Summary

The Claude desktop app (/Applications/Claude.app) leaks pseudo-terminal (pty) file
descriptors over time. A single long-running app process accumulated 508 open ptys,
hitting the system cap (kern.tty.ptmx_max = 511). Once exhausted, no process on the
machine can allocate a new pty
— new Terminal tabs, claude CLI sessions, and even
sudo (which allocates its own pty) all fail with:

[forkpty: Device not configured]
[Could not create a new process and open a pseudo-tty.]
sudo: unable to allocate pty: Device not configured

This is a system-wide denial-of-service caused by one app: the user cannot open any new
terminal, and cannot even sudo to raise the cap, so the only recovery is force-quitting
and relaunching the app.

Environment

  • macOS / Darwin: 25.5.0
  • Claude desktop app: /Applications/Claude.app/Contents/MacOS/Claude (PID 43725; running since Mon Jun 8 02:43)
  • Embedded claude-code host: 2.1.165; claude CLI on PATH: 2.1.101
  • kern.tty.ptmx_max: 511 (system default)

Evidence

# total pty masters open system-wide  (== the cap)
$ lsof /dev/ptmx | tail -n +2 | wc -l
511

# who holds them — one app process holds 508
$ lsof /dev/ptmx | tail -n +2 | awk '{print $1,$2}' | sort | uniq -c | sort -rn | head
 508 Claude 43725
   2 Terminal 29952
   1 Xcode 583

$ ps -o pid,ppid,lstart,command -p 43725
43725  1  Mon Jun  8 02:43:17 2026  /Applications/Claude.app/Contents/MacOS/Claude

# allocation now fails for everyone
$ python3 -c "import pty; pty.openpty()"
OSError: out of pty devices

The 508 ptys are held directly by the main app process (PID 43725), not by child
processes, so they cannot be reclaimed without terminating/restarting the app.

Steps to reproduce (observed)

  1. Run the Claude desktop app for an extended session (~1 day) with active use

(multiple Claude Code conversations / tool calls that spawn pty-backed subprocesses).

  1. Over time the app's open-pty count climbs and is never released.
  2. Once it reaches kern.tty.ptmx_max (511 here), any new pty allocation fails

system-wide.

Impact

  • Cannot open new Terminal/iTerm tabs.
  • Cannot start new claude CLI sessions.
  • Cannot sudo (modern sudo allocates a pty), so the user cannot even raise

kern.tty.ptmx_max to work around it.

  • Only recovery is force-quitting and relaunching the app.

Expected

The app should close pty file descriptors when the associated
terminal/subprocess/session ends, keeping its open-pty count bounded.

Workarounds

  • Recovery: force-quit and relaunch Claude.app (releases all leaked ptys).
  • Mitigation (only if ptys are still available): sudo sysctl -w kern.tty.ptmx_max=2048

— but this fails once exhausted, because sudo itself needs a pty.

Notes

  • Suspected cause: pty-backed subprocesses (e.g. the Bash tool / terminal integration)

are spawned per tool-call or per-session and their master fds are not closed on exit.

  • A bounded-fd or explicit-close fix, plus possibly monitoring the app's open-pty

count, would prevent the system-wide lockout.

View original on GitHub ↗

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