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 "@chat-js/thread/react";

- const chat = useChat();
+ const chat = useThread();

chat.messages; // selected path
chat.tree; // complete tree
npm package
$ bun add @chat-js/thread

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.

One conversation. Every possibility.

Real tree state with simulated local streams

Chat

Deployment follow-up

Viewing this path
You

Plan a production launch.

Assistant

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

Complete19 tok
You

Make the plan technical.

Assistant

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

Complete19 tok
Branch navigation for msg_04aBranch 1 / 2
YouSelected

Add the deployment sequence.

Continuing from Deployment follow-up

Local simulation · ≈ token counts are estimates, not provider usage

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 docs