anomalyco / anomalyco/opencode
Forked parent session opens original child session, so Back returns to original parent
@neriousy is already working on this.
Since Aug 13, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
When a session with a task/subagent child is forked, the forked parent still points at the original child session. Entering that child from the fork and clicking "back to parent" returns to the original parent session instead of the forked parent.
Reproduction
- Start a parent session
S1. - Have it call the
tasktool / a subagent, producing child sessionC. - Fork
S1, producingS2. - In
S2, click/open the task's child session. - In the child session, click the UI action to return to the parent/main session.
Expected behavior
The child reached from S2 should return to S2, or the fork should create/repoint a fork-local child session whose parentID is S2.
Actual behavior
The child returns to S1.
Root cause from code reading
The child session's parent link is written only when the task creates the subagent session:
packages/opencode/src/tool/task.ts:sessions.create({ parentID: ctx.sessionID, ... })
So if the task ran in S1, child C permanently has parentID = S1.
Session fork then copies only messages/parts into a new root session:
packages/opencode/src/session/session.ts:fork()creates a new session without aparentID, then copies messages and parts.- It does not clone child sessions.
- It does not rewrite copied task part metadata such as
metadata.sessionIdto point at a fork-local child.
The web UI's parent navigation reads the stored child parent directly:
packages/app/src/pages/session.tsx:openParentnavigates toinfo()?.parentID.packages/app/src/pages/session/composer/session-composer-region-controller.ts: child/back state also comes fromsync().session.get(id)?.parentID.
Because the child reached from the fork is still the original child C, C.parentID is still S1, so Back navigates to S1.
Notes
This is related to session hierarchy/forking, but I did not find an existing issue for this exact fork-local child lineage bug. Related but different issues/PRs:
- #16639 requests allowing
parentIDwhen forking sessions. - #15972 / #15993 / #23365 cover TUI nested subagent navigation, not web/app forked-parent child lineage.
A UI-only history workaround would make Back appear to work for one navigation path, but the underlying data would still be inconsistent after refresh/deep-link/multiple entry points. The durable fix seems to be in Session.fork: clone/re-fork task child sessions reachable from copied task parts and rewrite the copied task part metadata to point at those fork-local children with parentID = forkedSession.id.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.