Skip to content

Subagent processes not cleaned up after session ends #1652

@jdongwoo

Description

@jdongwoo

Problem

After using claude-mem for a while, I noticed my machine slowing down significantly. Checked ps aux and found 14+ orphaned claude subagent processes still running in the background, some dating back 3 days.

All of them were children of the worker-service.cjs --daemon process (bun), each consuming 300-600MB of memory.

PID 1172  - started Monday (3 days ago)
PID 51407 - started Tuesday
PID 51593 - started Tuesday
...total 14 orphaned processes

Root cause (what I found)

The Stop hook flow queues /api/sessions/summarize but doesn't call session complete or delete. So from the daemon's perspective, the session stays "active" and the spawned claude subprocess just sits there waiting for more queue input forever.

The internal reaper also skips these because they're tied to "active" sessions.

Steps to reproduce

  1. Use claude-mem normally across multiple sessions
  2. Close terminal / end sessions
  3. After a day or two, run ps aux | grep claude
  4. Observe accumulated background claude processes under the worker-service daemon

Workaround

I set up a SessionEnd hook in ~/.claude/settings.json that kills background claude subagent processes older than 5 minutes on session end. Works fine as a band-aid but the daemon itself should handle cleanup.

Suggestion

  • Call session complete/delete after summarize finishes in the Stop flow
  • Add an idle TTL so stale sessions get cleaned up automatically
  • Reconcile orphaned child processes on daemon startup

Environment

  • claude-mem 9.0.12
  • macOS (Apple Silicon)
  • Claude Code CLI

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions