Bug: /exit command leaves orphan child processes (memory leak)

Resolved 💬 2 comments Opened Jan 20, 2026 by edgelines Closed Jan 20, 2026

Description

The /exit command does not properly terminate child processes, causing them to become orphan processes that accumulate over time and consume significant memory.

Environment

  • OS: macOS Darwin 25.2.0
  • Claude Code Version: Latest (installed via ~/.local/bin/claude)
  • Shell: zsh/bash

Steps to Reproduce

  1. Start Claude Code session: claude
  2. Use the session normally
  3. Exit with /exit command
  4. Repeat steps 1-3 multiple times over several days
  5. Check processes: ps aux | grep claude | wc -l

Expected Behavior

All Claude-related processes should terminate when /exit is called.

Actual Behavior

  • Only the main process terminates
  • Child processes become orphans (PPID becomes 1)
  • Processes accumulate over days

Evidence from my system:

# After several days of normal usage with /exit:
$ ps aux | grep claude | wc -l
150+

# Memory consumption:
~10GB total from accumulated orphan processes (60-170MB each)

# Orphan process detection:
$ ps -o pid,ppid,command | grep claude
PID    PPID  COMMAND
34946  1     /Users/.../.local/bin/claude  # PPID=1 means orphaned

Impact

  • Memory leak: Each orphan process consumes 60-170MB
  • System slowdown: 150+ processes accumulated over ~5 days
  • User confusion: Users believe /exit properly terminates the session

Workaround

# Kill all Claude processes manually
pkill -f claude

# Then start a new session
claude

Suggested Fix

The /exit command should:

  1. Send termination signals to all child processes in the process group
  2. Wait for child processes to terminate before exiting
  3. Or use kill -- -$$ to kill the entire process group

Additional Context

Process tree shows child processes spawned by Claude Code are not receiving termination signals:

Main Claude Process (terminated by /exit)
├── Child Process 1 (orphaned, PPID→1)
├── Child Process 2 (orphaned, PPID→1)
└── Child Process N (orphaned, PPID→1)

View original on GitHub ↗

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