Skip to content

[BUG] Resuming a session that is already running forks its transcript; the next resume silently drops one branch #97833

Open

Description

@vagran

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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:

  1. Create a session, then resume it in process A with a multi-step turn (three echo
    tool calls).
  2. Two seconds later, while A is mid-turn, resume the same session in process B with a
    turn that finishes after A's.
  3. 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 interrupted: the session ended], as a sibling of A's real result. So B does not just
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 off. Over the next four hours the second process wrote about 320 records on its branch.
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 needs claude on PATH and python3, and makes about
    four short Haiku calls.

repro.sh

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

Activity

  1. added
    bug
    on Sep 28, 2026
  2. added
    platform:linux
    platform:vscode
    has repro
    on Sep 28, 2026
  3. matiasbourgeois commented on Oct 4, 2026

    @matiasbourgeois

    Same root cause, hit today from the VS Code extension (2.1.283, Windows 11, Remote Control on), with two side effects that made it worse than a forked transcript:

    What happened

    1. A long-running session was mid-turn: an E2E suite running in a background shell, and it was building an artifact.
    2. I closed its VS Code tab. The claude.exe process kept running headless and kept writing to the .jsonl.
    3. I reopened the same conversation from the history. The extension did not attach to the live process; it started a second one on the same session. The original process received the artifact-watch-lifecycle notice "Another live session of this same conversation is running", so the harness knew.

    Side effects

    • Nothing of the live session was visible. The reopened tab showed a frozen conversation while the headless process kept working (tests, edits, an artifact). The only way to know what it was doing was to read the .jsonl from a third session and talk to it over cross-session messages.
    • Every prompt in the reopened tab failed with Prompt is too long. The conversation was very long; the second process loaded it whole and never auto-compacted. The Prompt is too long line also got written into the shared transcript, interleaved with the live process's turn.
    • A permission prompt was stranded. The headless process tried to publish an artifact, the harness asked for approval (a Read rule did not match the 8.3 short path C:\Users\BOURGE~1\...), and the prompt went to the closed tab, where nobody could answer it. The publish failed and the artifact stayed empty, with no visible error anywhere.

    Expected

    • Reopening a conversation whose process is still alive should attach to that process (or at least say it exists), instead of starting a second one.
    • A session with no attached UI should surface its permission prompts somewhere it can be answered (another tab, Remote Control), or fail them loudly.
    • When the reopened view cannot fit the context, it should compact or explain, rather than returning Prompt is too long on every message.
  4. added a commit that references this issue on Oct 6, 2026
  5. ZioFabry commented on Oct 26, 2026

    @ZioFabry

    Still reproducible on 2.1.310 (Linux, claude -p, model haiku), with a minimal repro:

    1. claude -p --session-id <uuid> "Reply only: ROOT"
    2. In parallel: claude -p --resume <uuid> "Remember the codeword MANGO. First write the numbers from 1 to 3000, one per line, then write MANGO-SAVED." and, a few seconds later, claude -p --resume <uuid> "Remember the codeword PEAR. Reply only: PEAR-SAVED". PEAR finishes first, MANGO last.
    3. claude -p --resume <uuid> "Which codewords did I ask you to remember? List all of them, or NONE." → MANGO only. PEAR's turn is silently gone.

    In a second run the call that started first but finished last won; the result follows the last writer, not the start order. No warning at step 2 or 3.

    Real-world impact: a supervisor that relaunched sessions after a container restart resumed a session that a stale second process had kept appending to (thousands of repeated local-command lines). The resume picked the stale branch, and after auto-compaction on that branch the active one was no longer reachable by any --resume.

    Asks: refuse or warn when resuming a session held by a live process (offer --fork-session, as the VS Code extension's "still open somewhere else" notice does; see #69364), and pick the leaf by an explicit pointer or the latest user turn rather than the last line written.

  6. asunghong commented on Nov 2, 2026

    @asunghong

    Still reproducible on 2.1.316 (macOS arm64) with two interactive terminals, no -p.

    1. Terminal A was running session X. In terminal B, claude --resume opened X with no warning. As far as I can tell, the existing refusal ("is running in the background") only applies when the other process is a background session, so two interactive terminals are never stopped. This is the gap described in --continue / --resume doesn't check the existing live-session registry before re-opening a session already running in another process #69364.
    2. Both terminals kept working for over a day and both looked normal. One .jsonl grew two branches, with thousands of rows on each side of the fork.
    3. Terminal B was restarted with --resume X. A had written last, by 39 seconds, so B came back on A's branch. B's day of work dropped out of the conversation with no warning. The rows were still in the file.
    4. Each later --resume X also opened A's branch and added another small branch to it. I found no interactive way to choose a branch; --resume-session-at is for print mode.

    How often: 4 of my 58 remaining transcripts have two branches written in the same period (counting only branches with 20 or more user and assistant rows). The oldest is from September.

    What recovered the lost branch: writing a new <uuid>.jsonl with every row except the other branch's subtree, keeping side rows because they hold parallel tool calls, and with sessionId rewritten. --resume <uuid> then continued from the last row of the lost branch.

    One note for a fix: with several config dirs sharing projects/, each CLAUDE_CONFIG_DIR has its own sessions/ registry, so a check needs to look across them.

  7. added
    stale
    on Nov 26, 2026
  8. removed
    stale
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corebugdata-losshas reproplatform:linuxplatform:vscode

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions