Skip to content

Claude CLI processes not terminating when terminal closes #20599

Closed as duplicate

Description

@Asclepius9

Description

Claude CLI processes continue running after the user closes or disconnects from the terminal, leading to significant memory accumulation over time.

Observed Behavior

  • User closes terminal tab, Ctrl+C, or terminal disconnects
  • Claude process continues running in background as orphan
  • Process holds onto memory (600MB-3GB per session)
  • Over days/weeks, multiple orphaned sessions accumulate

Evidence

On a system running for ~2 weeks, found 11 orphaned Claude sessions consuming ~10GB RAM:

PID: 1729372 | TTY: pts/27 | Started: Jan19 | Mem: 0.7%
PID: 1895002 | TTY: ? | Started: Jan20 | Mem: 0.4%
PID: 3047777 | TTY: ? | Started: Jan21 | Mem: 0.5%
PID: 3502757 | TTY: pts/12 | Started: Jan22 | Mem: 3.0%
PID: 3543434 | TTY: pts/13 | Started: Jan22 | Mem: 2.3%
PID: 3601287 | TTY: pts/21 | Started: Jan22 | Mem: 2.1%
PID: 3787540 | TTY: ? | Started: Jan23 | Mem: 1.6%
PID: 3955594 | TTY: pts/49 | Started: Jan22 | Mem: 1.4%
PID: 3959187 | TTY: pts/50 | Started: Jan22 | Mem: 2.4%
PID: 3960252 | TTY: pts/51 | Started: Jan22 | Mem: 0.9%
PID: 3963043 | TTY: ? | Started: Jan22 | Mem: 0.9%

Processes with TTY: ? had already lost their controlling terminal but were still running.

Expected Behavior

When the controlling terminal is closed or sends SIGHUP, the Claude process should:

  1. Detect the terminal disconnection
  2. Clean up resources
  3. Terminate gracefully

Environment

  • OS: Linux 6.14.0-37-generic
  • Claude CLI version: 2.1.17

Workaround

Users can manually clean up with:

pkill -f "claude"

Or check for orphaned processes:

pgrep -a claude

Suggested Fix

Implement proper signal handling for:

  • SIGHUP (terminal hangup)
  • SIGPIPE (broken pipe)
  • Monitor stdin/tty availability and exit if lost

Activity

  1. github-actions commented on Jan 24, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. Orphaned processes after terminal close cause runaway memory consumption (34GB+ per instance) #17391
    2. Orphan processes remain after closing terminal (iTerm/PyCharm) #20586
    3. Orphaned Claude processes when parent terminal is killed #20117

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. added
    duplicateThis issue or pull request already exists
    and removed
    bugSomething isn't working
    has reproHas detailed reproduction steps
    platform:linuxIssue specifically occurs on Linux
    on Jan 29, 2026
  3. github-actions commented on Jan 29, 2026

    @github-actions

    This issue has been automatically closed as a duplicate of #17391.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  4. github-actions commented on Feb 6, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  5. locked as resolved and limited conversation to collaborators on Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions