# Branching Thread block

> Branching AI chat thread with reply versions, cited sources and code artifacts

A standalone conversation under one minimal header: a tabbed thread switcher over pinned and recency lists, a favorite toggle and a fold for earlier turns, above replies that arrive as small documents with sections, bullets and code artifacts in markdown, yaml, json, typescript and sql, each one folding its working away behind a thought row and listing the sources its inline citations point back to, over a thread held as a tree so a regenerate or an edit adds a version on the fork rail instead of overwriting the turn.

- Type: Pro block
- Category: [AI Chat](https://reui.io/blocks/ai-agents/ai-chat.md)
- Page: https://reui.io/blocks/ai-agents/ai-chat/ai-chat-9
- MCP: `get_block("ai-chat-9")`
- Built with: Attachment, Badge, Bubble, Button, Code Block, Collapsible, Dropdown Menu, Empty, Field, Icon Stack, Input Group, Kbd, Marker, Message, Message Scroller, Popover, Spinner, Tabs, Tooltip
- Installs with a ReUI Pro or Ultimate license; setup: https://reui.io/docs/license-setup

## Best for

A thread held as a node tree, where a regenerate or an edit adds a version chip on its fork, with folded reasoning and numbered citations

## Agent notes

- Replace `THREAD_TREES` and `THREADS`; each `ChatNodeRecord` lists its `children`, and `DEFAULT_SELECTION` picks the version a fork opens on
- `composeReply` matches the prompt against `REPLY_LIBRARY` and `stepsFor` against `ACTIVITY_PLANS`; return your model's parts, sources and steps there
- Nothing persists: ratings set local `votes` and a `toast`, versions and the star live in `trees` and `favorites` state, and Copy link uses `THREAD_URL`

## When not to use

- A draft written straight into the document open beside the thread, with an Undo: use [Docked Assistant](https://reui.io/blocks/ai-agents/ai-chat/ai-chat-2.md) (`get_block("ai-chat-2")`)
- A greeting screen whose start rows attach a source, with an Instant to Deep effort picker: use [Prompt Starter Welcome](https://reui.io/blocks/ai-agents/ai-chat/ai-chat-3.md) (`get_block("ai-chat-3")`)

## Third-party libraries

- Sonner v2: [API reference](https://sonner.emilkowal.ski/toast), [docs](https://sonner.emilkowal.ski/getting-started)
- Shiki v4: [API reference](https://shiki.style/guide/install), [docs](https://shiki.style/guide/), through ReUI Code Block

## Install

```bash
npx shadcn@latest add @reui/ai-chat-9
```

## About AI Chat blocks

### When to use

- A full page assistant chat, new chat welcome screen or 2 model comparison inside an AI product
- A copilot docked beside the page it works on, or opened from a launcher in the page corner
- Answers that show the work behind them: sources read, tool steps, plans to approve and run cost

### When not to use

- The product layout around the chat: a sidebar of threads, workspaces and account menus: use the [App Shell blocks](https://reui.io/blocks/application/app-shell.md)
- A plain overlay chat panel opened from a button, with suggestion chips and a composer: use the [Sheet blocks](https://reui.io/blocks/application/sheet.md)
- A highlighted snippet with a filename header and copy button, outside any conversation: use [Code Block](https://reui.io/components/code-block.md) (`get_component("code-block")`)

### Agent notes

- Each `AiChat` root sizes itself to the viewport with `h-svh`, or `min-h-svh` in ai-chat-5; give it your layout's height inside an app shell
- Every reply is canned content from the block's data file, played back on `setTimeout` and `setInterval` timers; stream your model's output there instead

Every ReUI item has a twin like this one; the index is https://reui.io/llms.txt. Agents with the ReUI MCP (https://reui.io/docs/mcp) get the same guidance from the getters named above.
