Guide · October 2026

Cleaning up leftover Claude Code processes

If you've ended your sessions but memory stays high or a port is still taken, a Claude Code process or a dev server Claude started may still be running.

Why they stick around

A session ending doesn't always mean its claude process exits. Even an idle one can hold a few hundred MB, and a handful of them push a 16 GB Mac into swap.

Dev servers Claude starts (vite, next dev and so on) run separately from the session, so they can keep holding their port after the turn ends or the app quits (issue #99845). Starting one on the same port again then fails with "port already in use".

Finding and stopping them yourself

Claude processes: ps -o pid,etime,rss,comm -p "$(pgrep -d, -x claude)" shows how long each has run (ELAPSED) and its memory (RSS, in KB). If one clearly belongs to a session you've ended, stop it with kill <PID>. Killing a session that's still working cuts that work off, so match them against your open terminals and app sessions first.

Dev servers: find the PID by port, e.g. lsof -nP -iTCP:5173 -sTCP:LISTEN (plain -iTCP lists every listening port). To stop its children too, run pkill -TERM -P <PID> and then kill <PID>. Avoid pkill -f with a short name: it can also kill unrelated apps whose path contains those letters (#100684).

With Lidnight

Lidnight knows from Claude Code hooks when a session has ended. If claude processes that have sat idle for over 20 minutes after their sessions ended add up to more than 300 MB, it tells you how many there are and how much memory they use. Clean up in the notification ends only those processes; it doesn't touch anything else, dev servers included (use the steps above for those). Sessions that are still working are never included. Mac won't sleep after Claude Code

Try Lidnight free

Apple Silicon Macs · macOS 13 or later. Every download includes a 7-day trial of everything in Pro, no payment details needed. Pro is a one-time payment (1 Mac $9.99 · 3 Macs $14.99, 50% off through Oct 31) with a 14-day refund.

Homebrew: brew install whereisdw/tap/lidnight