> ## Documentation Index
> Fetch the complete documentation index at: https://v2.opencode.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Fork session

> Create a child session by copying projected history from the parent. When messageID is supplied, copy messages before that boundary.



## OpenAPI

````yaml /openapi.json post /api/session/{sessionID}/fork
openapi: 3.1.0
info:
  title: opencode HttpApi
  version: 0.0.1
  description: Experimental HttpApi surface for selected instance routes.
servers: []
security: []
tags:
  - name: health
  - name: server
  - name: location
  - name: agent
  - name: plugin
    description: Experimental plugin routes.
  - name: session
    description: Experimental session routes.
  - name: session
    description: Experimental message routes.
  - name: model
    description: Experimental model routes.
  - name: generate
    description: Experimental one-shot generation routes.
  - name: provider
    description: Experimental provider routes.
  - name: integration
    description: Integration discovery and authentication routes.
  - name: mcp
    description: MCP server and resource routes.
  - name: credential
  - name: project
    description: Location-scoped project routes.
  - name: form
    description: Session form routes.
  - name: permission
    description: Experimental permission routes.
  - name: filesystem
    description: Experimental location-scoped filesystem routes.
  - name: command
    description: Experimental command routes.
  - name: skill
    description: Experimental skill routes.
  - name: event
    description: Experimental event stream routes.
  - name: pty
    description: Experimental location-scoped PTY routes.
  - name: shell
    description: Experimental location-scoped shell command routes.
  - name: question
    description: Experimental session question routes.
  - name: reference
    description: Location-scoped project references.
  - name: projectCopy
    description: Project copy management routes.
  - name: vcs
    description: Location-scoped version control routes.
  - name: debug
paths:
  /api/session/{sessionID}/fork:
    post:
      tags:
        - session
      summary: Fork session
      description: >-
        Create a child session by copying projected history from the parent.
        When messageID is supplied, copy messages before that boundary.
      operationId: v2.session.fork
      parameters:
        - name: sessionID
          in: path
          schema:
            type: string
            allOf:
              - pattern: ^ses
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                messageID:
                  anyOf:
                    - type: string
                      allOf:
                        - pattern: ^msg_
                    - type: 'null'
              additionalProperties: false
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Session.Info'
                required:
                  - data
                additionalProperties: false
        '400':
          description: InvalidRequestError
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidRequestError'
        '401':
          description: UnauthorizedError
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedError'
        '404':
          description: SessionNotFoundError | MessageNotFoundError
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/MessageNotFoundError'
                  - $ref: '#/components/schemas/SessionNotFoundError'
                  - $ref: '#/components/schemas/SessionNotFoundError'
      security: []
components:
  schemas:
    Session.Info:
      type: object
      properties:
        id:
          type: string
          allOf:
            - pattern: ^ses
        parentID:
          type: string
          allOf:
            - pattern: ^ses
        fork:
          type: object
          properties:
            sessionID:
              type: string
              allOf:
                - pattern: ^ses
            messageID:
              type: string
              allOf:
                - pattern: ^msg_
          required:
            - sessionID
          additionalProperties: false
        projectID:
          type: string
        agent:
          type: string
        model:
          $ref: '#/components/schemas/Model.Ref'
        cost:
          $ref: '#/components/schemas/Money.USD'
        tokens:
          $ref: '#/components/schemas/TokenUsage.Info'
        time:
          type: object
          properties:
            created:
              type: number
            updated:
              type: number
            archived:
              type: number
          required:
            - created
            - updated
          additionalProperties: false
        title:
          type: string
        location:
          $ref: '#/components/schemas/Location.Ref'
        subpath:
          type: string
        revert:
          $ref: '#/components/schemas/Session.Revert'
      required:
        - id
        - projectID
        - cost
        - tokens
        - time
        - title
        - location
      additionalProperties: false
    InvalidRequestError:
      type: object
      properties:
        _tag:
          type: string
          enum:
            - InvalidRequestError
        message:
          type: string
        kind:
          anyOf:
            - type: string
            - type: 'null'
        field:
          anyOf:
            - type: string
            - type: 'null'
      required:
        - _tag
        - message
      additionalProperties: false
    UnauthorizedError:
      type: object
      properties:
        _tag:
          type: string
          enum:
            - UnauthorizedError
        message:
          type: string
      required:
        - _tag
        - message
      additionalProperties: false
    MessageNotFoundError:
      type: object
      properties:
        _tag:
          type: string
          enum:
            - MessageNotFoundError
        sessionID:
          type: string
        messageID:
          type: string
        message:
          type: string
      required:
        - _tag
        - sessionID
        - messageID
        - message
      additionalProperties: false
    SessionNotFoundError:
      type: object
      properties:
        _tag:
          type: string
          enum:
            - SessionNotFoundError
        sessionID:
          type: string
        message:
          type: string
      required:
        - _tag
        - sessionID
        - message
      additionalProperties: false
    Model.Ref:
      type: object
      properties:
        id:
          type: string
        providerID:
          type: string
        variant:
          type: string
      required:
        - id
        - providerID
      additionalProperties: false
    Money.USD:
      type: number
    TokenUsage.Info:
      type: object
      properties:
        input:
          type: number
        output:
          type: number
        reasoning:
          type: number
        cache:
          type: object
          properties:
            read:
              type: number
            write:
              type: number
          required:
            - read
            - write
          additionalProperties: false
      required:
        - input
        - output
        - reasoning
        - cache
      additionalProperties: false
    Location.Ref:
      type: object
      properties:
        directory:
          type: string
        workspaceID:
          type: string
          allOf:
            - pattern: ^wrk
      required:
        - directory
      additionalProperties: false
    Session.Revert:
      type: object
      properties:
        messageID:
          type: string
          allOf:
            - pattern: ^msg_
        partID:
          type: string
        snapshot:
          type: string
        files:
          type: array
          items:
            $ref: '#/components/schemas/FileDiff.Info'
      required:
        - messageID
      additionalProperties: false
    FileDiff.Info:
      type: object
      properties:
        file:
          type: string
        patch:
          type: string
        additions:
          type: integer
          allOf:
            - minimum: 0
        deletions:
          type: integer
          allOf:
            - minimum: 0
        status:
          type: string
          enum:
            - added
            - deleted
            - modified
      required:
        - file
        - patch
        - additions
        - deletions
        - status
      additionalProperties: false

````