useThread for AI SDK

Branching conversations for AI SDK.

Keep the useChat interface. Add a complete message tree, branch navigation, and concurrent responses that keep streaming when users move elsewhere.

Chat.tsx useChat compatible
- import { useChat }from "@ai-sdk/react";
+ import { useThread }from "@chatjs/thread/react";

- const chat = useChat({ transport });
+ const chat = useThread({ transport });

chat.messages; // selected path
chat.tree; // complete tree
npm package
$ bun add @chatjs/thread ai @ai-sdk/react

The package, not a mockup

Move through the tree while it streams.

Branch from any message, request parallel replies, switch paths mid-stream, and stop individual runs. The canvas reads directly from useThread state.

useThread playground

Real tree state with simulated local streams

0 active runs

Active conversation

messages = tree.getPath(cursorId)

5 path nodes ready
usermsg_01

Plan a production launch.

assistantmsg_02

Start with architecture, rollout, and observability as separate workstreams.

usermsg_03

Make the plan technical.

assistantmsg_04a

Use staged environments, immutable builds, and progressive traffic shifting.

Branch navigation for msg_04a1/2
usermsg_05a

Add the deployment sequence.

A strict extension

Your chat stays linear. Its history does not.

Existing message lists and composers keep using the selected path. Tree-specific state is additive and namespaced under chat.tree.

Same AI SDK surface

messages
sendMessage
setMessages
regenerate
stop
status + error
tools + approvals
ChatTransport

Cursor navigation

Select any message and expose its root-to-node path as chat.messages.

Message topology

Read parents, children, siblings, leaves, and complete tree snapshots.

Independent runs

Stream, stop, and resume responses without coupling them to the visible path.

Parallel responses

Start multiple assistant runs from one user message and follow only the one you choose.

Why it keeps working

One tree. One AI SDK lifecycle per response.

A single linear chat engine cannot safely own several branch streams. useThread isolates each response while routing every update into its own assistant node once streaming begins.

Resume per run Stop per run Navigate independently
01Tree

Canonical messages, parent-child edges, and the selected cursor.

02Active path

A useChat-compatible projection from the root to the cursor.

03Branch runs

One isolated AI SDK request lifecycle and abort controller per response.

04Transport

Your existing AI SDK ChatTransport, shared without a new wire protocol.

Headless by design

Own the experience. Choose how you integrate it.

Install the versioned package alongside AI SDK. Your conversation UI, branch controls, persistence, and server routes remain application-owned.

Read the architecture