This repository was archived by the owner on Dec 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Implement session forking functionality #130
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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
forkSessionAPI endpoint toopencode-http-api.ts - Add
forkSessionserver function toopencode-server-fns.ts - Add
forkSessionmethod toopenCodeServiceinopencode-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 forkmessageID(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
src/lib/opencode-http-api.ts- AddforkSessionfunctionsrc/lib/opencode-server-fns.ts- Add server function wrappersrc/lib/opencode-client.ts- Add service method- 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
- sst/opencode fork implementation: https://github.com/sst/opencode/blob/dev/packages/opencode/src/session/index.ts#L123
- Session fork API endpoint: https://github.com/sst/opencode/blob/dev/packages/opencode/src/server/server.ts#L538
- SDK types for fork: https://github.com/sst/opencode/blob/dev/packages/sdk/js/src/gen/types.gen.ts#L1756
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request