Skip to content

How to Increase the macOS Terminal Device Limit

Tags: ai • Categories: Software

Table of Contents

I ran into this error for the first time:

Your system cannot allocate any more pty devices.

Ghostty requires a pty device to launch a new terminal.
This error is usually due to having too many terminal
windows open or having another program that is using too
many pty devices.

Please free up some pty devices and try again.

You may run into the more obscure error:

[forkpty: Device not configured]
[Could not create a new process and open a pseudo-tty.]

I had to look it up to understand what a pty device was (basically, a terminal connection)! The default on macOS was ~500, so I had to really be convinced that I had 500 pty terminals running, but it looked like I did (coding CLIs spawn their own subshells, vscode at the time used a bash wrapper to spawn a zsh tmux session, etc).

Inspecting & Updating Pty Limits on macOS

Inspect the number of active ttys:

sudo lsof /dev/ptmx | wc -l

Get the current number of max ttys:

sysctl -n kern.tty.ptmx_max

You can update the max tty:

sudo sysctl -w kern.tty.ptmx_max=255

Or, use the max (until you restart):

sudo sysctl -w kern.tty.ptmx_max=999

Get a list of ttys and which process they are tied to:

sudo lsof /dev/ttys*

Use LaunchDaemon to Increase the Pty Limit on Startup

You can create a lauchdaemon to fix this on startup. I like this because it persists across restarts.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>mikebianco.pty</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/sbin/sysctl</string>
        <string>kern.tty.ptmx_max=999</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Here’s how to install and set it up to run:

sudo cp ./pty.plist /Library/LaunchDaemons/mikebianco.pty.plist
sudo launchctl bootstrap system /Library/LaunchDaemons/mikebianco.pty.plist

You could also update some /etc config but I’m pretty sure this gets wiped on macOS updates, so I prefer the plist solution.

Keep in Touch

Subscribe to my email list to keep in touch. I’ll send you new blog posts and other thoughts.