Repository navigation
fix(claudecode): adopt the parent's Claude Code session on a fork child - #284
Merged
Anish Ramasekar (aramase) merged 1 commit intoNov 18, 2026
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A second fork can skip an execution with uncertain delivery and adopt an older transcript, bypassing the state-loss check and continuing from a stale conversation.
1 open issue
What changed in this PR
This PR addresses #255 by letting the Claude Code harness adopt a parent's session on memory-snapshot fork children, without changing the protocol or capabilities.
Changes:
- Adds parent-session matching and CLI flags to create an independent child session.
- Adds adoption, failure-path, nested-fork, and controller-over-wire tests.
- Documents fork requirements and the transcript filesystem constraint.
| File | Description |
|---|---|
| integrations/claudecode/turn.go | Carries and logs the fork source session ID. |
| integrations/claudecode/integration_test.go | Tests forked sessions through the controller and harness wire. |
| integrations/claudecode/fork_test.go | Covers adoption, refusals, retries, cancellation, and nested forks. |
| integrations/claudecode/fake_test.go | Models Claude Code's fork-session argument handling. |
| integrations/claudecode/claudecode.go | Implements parent matching, adoption state, and fork arguments. |
| integrations/claudecode/claudecode_test.go | Updates the cancellation test for the argument signature. |
| docs/harness-authoring.md | Describes memory-tier fork behavior and requirements. |
| changelog/unreleased/claudecode-fork.md | Records the fork support fix and constraints. |
Review effort: Balanced
Anish Ramasekar (aramase)
force-pushed
the
aramase/i/claudecode_fork_255
branch
from
November 17, 2026 16:32
6295b2f to
a157168
Compare
Anish Ramasekar (aramase)
force-pushed
the
aramase/i/claudecode_fork_255
branch
from
November 17, 2026 17:15
a157168 to
0832365
Compare
There was a problem hiding this comment.
🟡 Changes recommended
A critical race allows a parent transcript to advance before a child forks, copying conversation beyond the intended fork point; source reservations and deterministic regression coverage, including retries, are needed.
1 open issue
2 resolved since last review
Review effort: Balanced
Signed-off-by: Anish Ramasekar <anish.ramasekar@gmail.com>
Anish Ramasekar (aramase)
force-pushed
the
aramase/i/claudecode_fork_255
branch
from
November 17, 2026 18:26
0832365 to
373c744
Compare
Tom Gamble (gambtho)
approved these changes
Nov 18, 2026
Anish Ramasekar (aramase)
merged commit Nov 18, 2026
8077f2d
into
agent-primitives:main
21 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


A memory-tier fork clones the parent's compute, so the child's harness memory holds the parent's Claude Code session under the parent's UID and nothing under the child's. Every child turn then failed with
errStateLost. This fixes that inside the harness, with no proto, capability or spec change. Fixes #255.claude --resume <parent id> --fork-session --session-id <child id>. Later child turns resume the child's id. The parent's entry is only read.errStateLost.ForkSafestays false; it still means a fork by replay is not supported. The package doc,docs/harness-authoring.mdand a changelog fragment describe the new behavior.Tested:
go vet,gofmtandgo test -raceinintegrations/claudecode, including new fake-claude tests for adoption, the fail-closed cases, a new fork adopting again after the parent's next turn, child retries against an unchanged, advanced or busy parent, an unconfirmed parent, a fork of a fork, and the parent reservation (a paused child refusing the parent's turn, release on every exit path, retries, concurrent forks).TestForkOverWire:controller.Forkon a real parent journal, then the child under its own UID over harnesswire.--resume P --fork-session --session-id Creports C, leavesP.jsonlbyte-identical and writes a self-containedC.jsonl.--session-idwith--resumeand no--fork-session, a child id already in use, and a missing parent transcript each exit 1.