Skip to content

Fork a thread from a specific message (#158) - #1565

Merged
currentbits merged 3 commits into
mainfrom
coder/fork-a-thread-from-a-specific-message-pr-9e2638
Oct 10, 2026
Merged

currentbits merged 3 commits into
mainfrom
coder/fork-a-thread-from-a-specific-message-pr-9e2638

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #158.

What

  • Fork from here on assistant messages: new thread with the transcript copied up to and including that message (hidden while a run is working). The existing handoffFrom provenance chip links back to the source.
  • Claude, native: the fork resumes the source CLI session forked and truncated at that message: --resume <src> --fork-session --resume-session-at <uuid>. Verified live on claude 2.1.283: new session id, truncated at the cut, source session untouched, works from another cwd, uuids preserved (fork-of-fork works).
  • Everyone else (other providers, hand-off to another provider, messages with no recorded uuid): fresh session seeded from the copied prefix via replayContext, the same path rewind uses.
  • Safety: if a native fork fails before it gets its own session id, the thread drops to the seeded path, so a retry never plain---resumes the source session. An armed fork also keeps its session id when its worktree materialises.

How

  • Runner stamps each Claude assistant text message with its CLI chain uuid (claudeUuid).
  • forkThread({ messageId }) validates before creating anything and arms forkSessionAt (one-shot, cleared by the forked session's init).

Caveats

  • --resume-session-at is a hidden CLI flag. If a release drops it, the fallback costs one failed turn.
  • Threads recorded before this change have no uuids, so they always use the seeded fallback.

Tests

  • electron/test/fork-handoff.test.js: service cases plus runner cases against a fake claude bin (exact argv, uuid stamp, cut cleared, failure fallback). 22/22 pass.
  • test/threadView.test.tsx: button forks with { messageId } and is hidden while working.

🤖 Generated with Claude Code

Fork at a message boundary: copy the transcript prefix into the new
thread. Claude threads resume a forked CLI session cut at that message
(--resume <src> --fork-session --resume-session-at <uuid>); other
providers, or messages without a recorded chain uuid, start a fresh
session seeded from the copied prefix. A native fork that fails before
getting its own session falls back to the seeded path so a retry never
resumes the source session. Adds a Fork from here action on assistant
messages.

Closes #158

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T07:53:05.722961Z bbc13a0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbc13a0e16

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +813 to +816
if (assistantMsgId && typeof ev.uuid === "string" && ev.uuid) {
store.updateMessage(threadId, assistantMsgId, {
claudeUuid: ev.uuid,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid using an event UUID for split assistant rows

When Claude emits one assistant event containing both text and a tool_use, this stamps the displayed text row with the UUID of the entire event, while ingestToolUse subsequently creates a separate tool row. Forking from that text row copies the transcript only through the text, but native --resume-session-at resumes after the whole underlying event, potentially including an unseen tool request without its later tool_result; the fork's actual context therefore differs from its displayed transcript and may begin with a dangling tool call. Use the seeded fallback for mixed-block events or associate the UUID only with a row representing the end of the complete event.

Useful? React with 👍 / 👎.

Comment thread electron/runner.js
Comment on lines +1395 to +1399
const failedThread = store.getThread(threadId);
const forkFallback =
failedThread && failedThread.forkSessionAt
? { sessionId: null, forkSessionAt: null, replayContext: true }
: {};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear stale fork markers before handling later failures

If a newly created Claude message fork is switched to Codex or another provider before its first run, setProvider clears the inherited sessionId but leaves forkSessionAt; a successful non-Claude run then records its own session without clearing that marker because only Claude's init handler does so. Any later, unrelated failure satisfies this predicate and discards the valid non-Claude session, forcing a lossy transcript replay on retry. Clear forkSessionAt whenever the native fork is invalidated, or constrain this fallback to a still-armed Claude source session.

Useful? React with 👍 / 👎.

Willem and others added 2 commits October 10, 2026 10:00
store.test.js pins the full thread shape, so it needs forkSessionAt.
threadView.test.tsx is at the 20s per-file cap on Windows CI; the
Fork from here tests move to their own file against MessageBlock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@currentbits
currentbits merged commit ecdfb2c into main Oct 10, 2026
5 of 6 checks passed
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.

Fork a thread from a specific message, preserving provider session where possible

1 participant