[BUG] Resuming a session that is already running forks its transcript; the next resume silently drops one branch
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
Environment
- Claude Code 2.1.283 (reproduced with the CLI); first hit in the VS Code extension 2.1.280 → 2.1.282
- VS Code 1.134.0, Linux (Arch)
Summary
Nothing prevents two processes from resuming the same session at once. Each one appends
to the same ~/.claude/projects/<project>/<session>.jsonl, so the conversation forks
into two branches under one parent. The next resume follows the branch written last and
drops the other one from the conversation without any warning. The records are still in
the file, so the work can be recovered by hand, but the UI shows the session cut back to
the fork point.
Steps to reproduce
The attached repro.sh does this with claude -p in a temporary directory, using Haiku
and a few turns:
- Create a session, then resume it in process A with a multi-step turn (three
echo
tool calls).
- Two seconds later, while A is mid-turn, resume the same session in process B with a
turn that finishes after A's.
- After both exit, resume the session a third time and ask what it has seen.
Actual
A said: A-DONE
B said: B-DONE
C sees: B1
B2
fork under attachment f2b6e34d:
[{"type": "thinking", ... <- A's branch
[{"type": "text", "text": "No response requested."}] <- B's branch
Both A and B report success. The third resume sees only B's work, and A's A1 A2 A3 are
gone from its conversation.
In an earlier run of the same scenario, B loaded the session while A had a tool_use
waiting for its result. B wrote a result of its own for that call, [Tool call, as a sibling of A's real result. So B does not just
interrupted: the session ended]
branch: it also treats A's live turn as dead.
Expected
At least one of the following:
- Refuse, or warn, when resuming a session that another live process is writing
(a lock file or heartbeat next to the transcript), with an option to open it read-only
or to fork it into a new session ID.
- In the VS Code extension, focus the tab or window that already has the session open
instead of starting a second process. Today this check only covers tabs in the same
window.
- When a transcript has two branches that were written at the same time, do not pick one
silently: say so on resume, or offer the branches to choose from.
How it was hit in practice
In the VS Code extension, a session was open and running in one tab. The same session
was then opened again from a list of all sessions (a third-party session-list extension,
which calls claude-vscode.editor.open with the session ID). Eleven seconds after the
first process's last record, a second process resumed with Continue from where you left Over the next four hours the second process wrote about 320 records on its branch.
off.
The first process's branch held 27. After the extension updated to 2.1.282, the session
reopened on the 27-record branch. The session then looked trimmed back to the morning
fork, with four hours of work gone. It was recovered by hand from the .jsonl file.
A scan of about 170 local transcripts found three more forks with branches written in
overlapping periods. One of them came from a terminal claude process writing to a
session that was open in VS Code at the same time, so the problem does not need the
third-party extension.
Attachment
repro.sh: self-contained. It needsclaudeon PATH andpython3, and makes about
four short Haiku calls.
Claude Model
Opus 5.5
Is this a regression?
Probably not.
Last Working Version
_No response_
Claude Code Version
2.1.283 (Claude Code)
Platform
Anthropic API
Operating System
Other Linux
Terminal/Shell
Other
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗