Currently Available: Need a skilled Software Developer for your next project?
Categories
Coding Agents

How to Find and Stop Idle or Orphaned Claude Code Processes on Linux and macOS

When Claude Code closes or crashes, a command it started may keep running. The process left behind might be the Claude Code command-line tool or a Claude process started by an IDE. It might also be a child command, such as a test runner, file watcher, or development server. Child commands often do not include claude in their names.

An idle process is doing little or no work right now; an orphaned process has outlived its parent. Neither condition alone means the process is safe to stop. A process ID, or PID, identifies one running process. Check its command, parent, and activity before sending a signal. Start with SIGTERM, a request to exit cleanly, and use SIGKILL, which forces an immediate stop, only if a verified unwanted process remains.

Find likely Claude Code processes

On Linux, list matching process IDs and their full command lines with:

pgrep -af claude

For more context, run this command. Its output includes the parent ID, the process group (related processes that can be signaled together), CPU and memory use, elapsed time, and terminal:

ps -eo pid,ppid,pgid,%cpu,%mem,etime,stat,tty,args --sort=-%cpu \
  | grep -i '[c]laude'

On macOS, use:

ps -axo pid,ppid,pgid,%cpu,%mem,etime,stat,tty,command \
  | grep -i '[c]laude'

The [c]laude pattern keeps grep from matching its own command line. The Linux pgrep utility searches full command lines when you use -f. The commands above find only processes whose command lines contain claude. A Python job, shell, or server that Claude Code launched may not contain claude in its command line.

Check who owns a candidate process

Before stopping a candidate, inspect its PID. Replace PID with the number from the listing:

ps -p PID -o pid,ppid,pgid,%cpu,%mem,etime,stat,tty,command

The PPID is the ID of the process that started this one. If a parent exits while a child keeps running, the operating system adopts the child. On Linux, the new parent is commonly init or a system manager; on macOS, it is launchd. A PPID of 1 supports the possibility that a process is orphaned, but it does not show that the process is unwanted. A detached server or other background job can be intentional.

Read the command and arguments alongside the parent and terminal columns. A live terminal, IDE, or desktop session may still own the process. Elapsed time also needs context: a long-running development server can be expected, and low CPU use does not prove that a process is stale. On Linux, pstree -ap PID, if installed, can show the process’s child processes. On either system, lsof -p PID, if available, can show files the process has open and help identify its project or task.

A process marked Z or defunct has already exited but its parent has not collected its exit status. Sending another signal generally does not make it exit again; the parent must reap it.

Stop a confirmed unwanted process

Send SIGTERM to the specific PID first:

kill -TERM PID

Then check whether that PID is still running:

ps -p PID -o pid,ppid,stat,etime,command

If it remains, inspect the command again before acting. PIDs can be reused after a process exits, so confirm that the number still refers to the unwanted process. If it does, and SIGTERM has not worked, use SIGKILL as a last resort:

kill -KILL PID

SIGTERM gives software a chance to clean up. SIGKILL does not. Individual user reports describe Claude Code-related processes that did not stop with SIGTERM, including reports involving a macOS terminal closure and background jobs started with shell &. These reports show that the cases have occurred; they do not establish how often they happen or that every Claude Code setup behaves the same way.

Avoid broad commands such as pkill -f claude, killall, or kill -9 as a first step. A name match can catch an active session or more than one process. If a confirmed unwanted process has child processes, inspect those children and stop the specific targets. A process group, identified by its PGID, contains related processes that can sometimes be signaled together; do not signal a whole group unless you have verified that it contains only the unwanted work.

Check Claude Code’s background-task controls

Claude Code’s interactive-mode documentation explains how to control background commands. Use those controls when the unwanted work appears in the current session’s tracked task list.

A shell command followed by & runs in the background, but Claude Code does not necessarily track it as one of its tasks. One reported macOS case described shell-backgrounded jobs that did not appear in the session’s task list and kept running after the session ended. If Claude Code has crashed or lost track of a command, use the operating system’s process listing and inspect the specific PID before stopping it.

Reports also describe background tasks surviving a Linux crash and IDE-related child processes on macOS. Each report concerns a particular setup or incident. Neither process age nor low CPU use identifies a safe target on its own. An IDE launch alone does not identify one either.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *