# Branch fork

Forking a conversation drawn as it happens: a new lane bends out of the message's node and runs down to a fresh row.

Also called: fork animation, fork chat.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Branch a conversation. Branch from any message: a new lane bends out of its node and runs down to a fresh row, and the messages it leaves behind dim. Preview: https://chatcn.dev/preview/branch-fork-demo

Every message is a node on the thread's rail. Pick Branch on one and a new lane bends out of that node and runs down beside the rail to a new row; the messages it leaves behind dim to show they stay on the old line. Branch somewhere else and the lane grows from the new node instead. The new row takes any children, usually a composer.

## Installation

```bash
npx shadcn@latest add @chatcn-pro/branch-fork
```

## Usage

```tsx
import { BranchFork } from "@/components/ui/chatcn/pro/branch-fork"

<BranchFork messages={map} forkAt={forkAt} onFork={setForkAt} branchLabel="Try a SharedWorker">
  <Composer />
</BranchFork>
```

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `messages` | `{ id, role: "user" | "assistant", text }[]` | One line each: the thread as a map |
| `forkAt` | `string | null` | The message the branch grows from |
| `onFork` | `(id: string | null) => void` | Shows Branch on rows and Back to main |
| `branchLabel` | `string` | Default "New branch" |
| `children` | `ReactNode` | Under the branch label |

## Accessibility

- The map is an ordered list. Branch buttons show on hover and focus, always on touch.
- The new row is `inert` until a branch exists.

## Motion

- The lane draws with `stroke-dashoffset`, 520 ms ease in out; the new node pops at the end.
- Reduced motion: the lane and node appear at once.

Source: https://chatcn.dev/docs/components/branch-fork