Expand description
Live Claude Code process detection — confirms a worktree is actually
occupied by a running claude instance, not just a stale jsonl event log.
Background: crate::operations::claude_session flags a worktree as
“active” when its ~/.claude/projects/<encoded>/*.jsonl has an event
within the activity threshold. That signal alone is too coarse — when a
user exits Claude Code cleanly the jsonl tail keeps its recent timestamp
and gw delete keeps refusing for the full threshold window.
This module supplies a complementary signal: scan the live process table
for a real claude binary (identified by its txt mapping under
~/.local/share/claude/versions/ or the macOS Claude.app bundle) whose
cwd is the worktree, or that has an open file under
<worktree>/.claude/. argv[0] is intentionally not trusted because Claude
Code rewrites it to a version string at runtime.
The scan is cached in a OnceLock for the lifetime of the gw
invocation, so callers may invoke has_live_claude_in repeatedly without
re-shelling out to lsof / re-walking /proc.
Functions§
- has_
live_ claude_ in - Returns true iff a live
claudeprocess is occupyingworktree.