Skip to content

Claude sessions pid matching#48

Merged
codeaholicguy merged 2 commits intomainfrom
feature-claude-sessions-pid-matching
Mar 27, 2026
Merged

Claude sessions pid matching#48
codeaholicguy merged 2 commits intomainfrom
feature-claude-sessions-pid-matching

Conversation

@codeaholicguy
Copy link
Copy Markdown
Owner

Summary

  • Claude Code (newer versions) writes ~/.claude/sessions/.json for each running process, containing { pid, sessionId, cwd, startedAt }. This PR updates ClaudeCodeAdapter to use these files as the primary matching source instead of the existing CWD-encoding + session file birthtime heuristic.
  • For each discovered Claude process, the adapter now attempts to read ~/.claude/sessions/.json directly. If found and valid, the sessionId is used to locate the JSONL file exactly.
  • Processes without a PID file (older Claude Code versions, or files not yet written) fall back to the existing legacy matching algorithm unchanged.
  • A stale-file guard (60 s tolerance between startedAt and proc.startTime) protects against PID reuse.

Why

The previous birthtime-based heuristic could produce incorrect matches when multiple Claude instances ran in the same working directory, or when session file creation time diverged from process start time. The new approach is exact and deterministic.

@codeaholicguy codeaholicguy merged commit a718e48 into main Mar 27, 2026
1 check passed
@codeaholicguy codeaholicguy deleted the feature-claude-sessions-pid-matching branch March 27, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant