Claude Code resume binding: newest-mtime resolver binds agents to other sessions' transcripts (incl. parent dirs) and marks them verified
Summary
For Claude Code agents, OpenCove finds a node's resume session by taking the newest *.jsonl transcript under the node's directory or any parent directory. It never checks that the transcript belongs to that node. The guess is then saved as resumeSessionIdVerified: true, and every agent that isn't stopped is revived on the next launch. So one restart can make many nodes resume someone else's conversation, several nodes can resume the same conversation at once, and nodes can be bound to session IDs whose transcript doesn't exist.
Observed on 0.2.0-nightly.20260509.1 (macOS, Claude Code 2.1.29x). The same code is unchanged on main (9126a04) and in v0.3.3.
The code path
- Newest-file guess, no ownership check.
findLatestClaudeResumeSessionIdInProjectDirectoryGroupkeeps every*.jsonlwithmtimeMs >= startedAtMs - 6000, takes the newest, and uses its filename as the session ID. It never opens the file. It doesn't compare the transcript's recordedcwdor first prompt, doesn't skip IDs already bound to another node, and doesn't treat several candidates as ambiguous. (The Codex path does validate both ID and cwd, andselectNearestAgentSessionIdalready returnsnullon a tie. The Claude path uses neither.) - Parent directories are searched.
resolveClaudeWorkspacePathCandidateschecks the cwd and then every parent up to/. If nothing qualifies in the node's own directory, any recently written transcript of an unrelated session in a parent directory wins. - Unset means verified.
isResumeSessionBindingVerifiedreturnstrueforclaude-codewhenresumeSessionIdVerifiedis undefined, andnormalizeResumeSessionBindingsaves that astrue. Once guessed, a wrong ID is never re-checked. - Everything not stopped is revived.
isRecoverableAgentWindowStatusisstatus !== 'stopped'. Soexitedandfailedagents are relaunched withclaude --resume <guessed id>on every app start, and quitting the PTY doesn't stop the node.
What it looked like
These are from one workspace whose Claude sessions run in per-session git worktrees under the workspace directory, a common way to isolate parallel agents. Those transcripts live in a child directory, which the parent-only search can't see.
- After one app restart, 13 of 15 revived agent nodes were bound to the wrong conversation. Each node's real transcript still existed, and was confirmed by matching its first user message to the node's prompt and its start time to the node's start (within 4–13 s).
- 3 nodes resumed the same transcript at the same time: three live
claude --resume <same-id>processes appending to one.jsonl. - 6 nodes were bound to an ID with no transcript on disk.
- A node created today was bound and marked verified, seconds after launch, to an unrelated, actively written session in a parent directory (a separate Claude Code session running in that directory). Restarting OpenCove would have made that node resume the other session.
- The PTY for an agent that fails at launch is recorded as
failedwith nolast_error, which makes this hard to diagnose.
Steps to reproduce
These are derived from the code path above and match what we saw; I haven't run them as a standalone test.
- In a terminal,
cd ~/oc-repro && claude, send one message, and keep chatting. Its transcript is written under the project folder for~/oc-repro. - In OpenCove, create a Claude Code agent whose directory is
~/oc-repro/app, whereapphas no Claude transcripts of its own within the 6 s window. That happens when the session runs in a subdirectory ofappor hasn't written its first transcript yet. - Read the node's
agent_json:resumeSessionIdis the terminal session's ID, withresumeSessionIdVerified: true. - Quit and reopen OpenCove. The node runs
claude --resume <terminal session id>and joins that conversation.
Variant (shared directory): two agents in the same directory, plus any other Claude session in that directory. After a restart, every unverified node resolves to whichever transcript was written last.
Expected
An agent resumes its own conversation or none. A guessed binding is never marked verified, and two nodes never share a session ID.
Suggested fixes (roughly in order of leverage)
- Don't guess at all. Generate a UUID when launching a new Claude Code agent, pass it with
claude --session-id <uuid>(the CLI supports this), and store it as the verified binding. - If discovery stays:
- Search the node's cwd only, not parent directories.
- Open the candidate and require its recorded
cwdto match, as the Codex path does. - Exclude IDs already bound to another node.
- Return
nullwhen more than one candidate qualifies, asselectNearestAgentSessionIdalready does.
- Treat an undefined
resumeSessionIdVerifiedas unverified, and only stamptrueafter validation. - When an agent launch fails, set
last_error, and consider not reviving a node whose last launch failed.
Environment
- OpenCove
0.2.0-nightly.20260509.1(code paths re-checked onmain@9126a04andv0.3.3) - macOS 26 (Darwin 25.3), Apple Silicon
- Claude Code 2.1.292–2.1.296
@domijin Could you update to the latest stable release first and check whether Claude agents still resume the wrong conversation after restarting OpenCove? Please also share the exact OpenCove version you test.