Skip to content

feat: detect orphaned sessions (terminal closed but Claude process alive) #94

@grimmerk

Description

@grimmerk

Problem

A session can be active (PID alive) and idle (hook status), but its parent terminal has been closed. CodeV shows it as green (idle), which is misleading — the user can't interact with it without reattaching.

How claude-control does it

Uses isOrphaned() — walks process tree (via ps -e) looking for known terminal apps (iTerm2, Terminal.app, Ghostty, etc.). If not found → ORPHANED. Checks every 30s. Uses ps process tree, not ~/.claude/sessions/*.json.

How CodeV can implement it

We already have the infra:

  1. detectTerminalApp(pid) walks the process tree and returns 'iterm2', 'ghostty', 'cmux', 'terminal', or 'unknown'
  2. Active sessions detected via ~/.claude/sessions/*.json (PR feat: rewrite detection with sessions/ PID files + cross-ref fallback #67)

Detection logic:

  • For each active session (PID alive from sessions/*.json):
    • Skip non-CLI sessions (entrypoint !== 'cli')
    • Call detectTerminalApp(pid)
    • If returns 'unknown' → session is orphaned

When to check:

  • On get-session-statuses call (startup + window focus)
  • Can reuse the detectTerminalApp calls already done for terminal badges

UI:

  • New dot state: grey or dimmed purple (static) with ORPHANED implied
  • Or show as a badge like claude-control does
  • Possible actions: kill orphaned process

Edge cases:

  • VS Code sessions (entrypoint: 'claude-vscode') — not orphaned even if no terminal found
  • SSH/remote sessions — process tree may not have a local terminal app

🤖 On behalf of @grimmerk — generated with Claude Code

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