Expand description
Hard-tier in-use signal: detects active Claude Code sessions in a
worktree by inspecting ~/.claude/projects/<encoded>/*.jsonl event tails.
Encoding rule mirrors Claude Code’s own: replace / and . with -,
drop trailing slash. Verified empirically against ~/.claude/projects/
contents during design.
Structs§
- Active
Session - Information about one active Claude Code session in a worktree.
Functions§
- encode_
project_ dir - Encode an absolute filesystem path to the directory name Claude Code
uses under
~/.claude/projects/./and.become-. Trailing path separators are trimmed. - find_
active_ sessions - Return all sessions in
project_dirwhose newest event timestamp is withinthresholdof now AND whose newest eventcwd(if present) matchesworktree. Missing/unreadable directories return an empty vec — the caller treats this as “Claude not in use here.” - newest_
event_ cwd - Companion: extract the
cwdfield from the same newest event. Used in Task 4 for path-encoding-collision defense. ReturnsNoneif not present. - newest_
event_ timestamp - Read up to ~64 KiB from the end of
path, find the newest line that parses as JSON with atimestampfield, and return that timestamp. ReturnsNonefor empty files, files containing only metadata events withouttimestamp, or unreadable / unparseable files. - project_
dir_ for - Resolve the per-worktree Claude projects directory, e.g.
~/.claude/projects/-Users-dave-Projects-foo. ReturnsNoneif$HOMEis not set / cannot be resolved.