Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Implement session forking functionality #130

@shuv1337

Description

@shuv1337

Problem/Context

The OpenCode TUI and Desktop/Web UI support session forking - the ability to create a new session that branches off from an existing session at a specific message. This feature is currently missing from the OpenCode Web application, limiting users' ability to explore alternative conversation paths or restart from specific points in their sessions.

Acceptance Criteria

  • Add forkSession API endpoint to opencode-http-api.ts
  • Add forkSession server function to opencode-server-fns.ts
  • Add forkSession method to openCodeService in opencode-client.ts
  • Add UI component/trigger for session forking (e.g., button on messages)
  • Handle navigation to newly forked session
  • Test forking at different message points in a session
  • Error handling for invalid session IDs or message IDs

Implementation Details

Backend API Integration

Based on the sst/opencode repository, the fork API is available at:

  • Endpoint: POST /session/:id/fork
  • Parameters:
    • sessionID (path param): The source session to fork
    • messageID (optional, body): The message to fork from (if not provided, forks from latest)

Reference Implementation (sst/opencode):

// Server endpoint: /session/:id/fork
export const fork = fn(
  z.object({
    sessionID: Identifier.schema("session"),
    messageID: Identifier.schema("message").optional(),
  }),
  async (input) => {
    const session = await createNext({
      directory: Instance.directory,
    })
    const msgs = await messages(input.sessionID)
    for (const msg of msgs) {
      if (input.messageID && msg.info.id >= input.messageID) break
      // Copy messages to new session
    }
    return session
  }
)

Files to Modify

  1. src/lib/opencode-http-api.ts - Add forkSession function
  2. src/lib/opencode-server-fns.ts - Add server function wrapper
  3. src/lib/opencode-client.ts - Add service method
  4. UI Components - Add fork button/trigger to message components

Integration Points

  • Fork button should be available on each message in the conversation
  • When forking from a specific message, only messages up to that point are copied
  • User should be automatically navigated to the new forked session
  • Consider adding a visual indicator that a session was forked from another

Reference Implementations

Tasks

  • Research existing message UI components to determine optimal fork trigger placement
  • Implement backend API integration for session forking
  • Add fork functionality to the OpenCode service layer
  • Design and implement UI components for session forking
  • Add proper error handling and user feedback
  • Test forking functionality across different scenarios
  • Update TypeScript types as needed
  • Consider adding session history/parentage tracking in UI

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions