/assistant-ui:runtimefrom assistant-ui
Guides creation and use of assistant-ui runtimes: LocalRuntime, ExternalStoreRuntime, and protocol adapters. Covers state hooks, scope accessors, provider wiring, and troubleshooting common errors.
Ships in assistant-ui. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Always consult assistant-ui.com/llms.txt for the latest API.
A runtime is the state and action layer behind a chat UI: it owns messages, threads, branching, and run lifecycle, and every primitive and hook reads from it through a uniform AssistantClient. There are two ways to build one. LocalRuntime (useLocalRuntime) owns the message store for you; you implement one ChatModelAdapter.run function and branching, editing, and regeneration come for free. ExternalStoreRuntime (useExternalStoreRuntime) is the inverse: you own the messages, and UI features turn on based on which callbacks you supply. Framework adapters such as useChatRuntime (@assistant-ui/ai-sdk) and protocol runtimes such as useAssistantTransportRuntime are built on one of these two. Once mounted under AssistantRuntimeProvider, every runtime is read and driven the same way, through useAui, useAuiState, and useAuiEvent.
AssistantRuntime
├── ThreadListRuntime (threads)
│ └── ThreadListItemRuntime[] (threadListItem)
└── ThreadRuntime (thread)
├── ComposerRuntime (composer) new-message input
├── SuggestionRuntime[] (suggestion) follow-up prompts, via thread.suggestions
└── MessageRuntime[] (message)
├── ComposerRuntime (composer) edit-message input
├── MessagePartRuntime[] (part)
├── ChainOfThoughtRuntime (chainOfThought)
│ └── MessagePartRuntime[] (part)
└── AttachmentRuntime[] (attachment)
modelContext and tools resolve independently of the thread scope; see runtime-concepts.md and the tools skill. Every node in the tree is reachable from aui.<scope> (imperative) or s.<scope> inside a useAuiState selector (reactive), scoped automatically to where the calling component is rendered.
useAui() returns the current AssistantClient. It does not subscribe to state, so its identity only changes on a structural change (for example switching threads); use it in event handlers and imperative code.
import { useAui } from "@assistant-ui/react";
const aui = useAui();
aui.thread.append({ role: "user", content: [{ type: "text", text: "Hello!" }] });
aui.thread.cancelRun();
useAuiState(selector) subscribes to a slice of AssistantState and re-renders only when the selected value changes (compared with Object.is). The selector runs on every store update, so it must return a primitive or a stable reference, never a fresh object or array literal, and never the whole state (that throws).
import { useAuiState } from "@assistant-ui/react";
const isRunning = useAuiState((s) => s.thread.isRunning); // primitive: correct
const messages = useAuiState((s) => s.thread.messages); // stable array reference: correct
// Wrong: a new object literal every call re-renders on every store update
const bad = useAuiState((s) => ({ isRunning: s.thread.isRunning, text: s.composer.text }));
Call useAuiState once per value (or compose several calls); do not spread a scope into a new object to bundle values together.
useAuiEvent(nameOrSelector, callback) subscribes for the component's lifetime. The callback runs inside an effect-event shim, so the latest closure fires without a memoized reference.
import { useAuiEvent } from "@assistant-ui/react";
useAuiEvent("thread.modelContextUpdate", ({ threadId }) => {
console.log("Model context updated", threadId);
});
As of 0.15, aui.<scope> is a property, not a call; calling it (aui.thread()) still works but is deprecated. Methods on a scope keep their parentheses.
aui.thread.getState(); // property accessor
aui.threads.switchToNewThread();
aui.thread.composer().send(); // composer() is a method of the thread scope
aui.thread.message({ index: 0 }); // selector object, not a bare index
Selecting an unavailable scope no longer throws; aui.message is always truthy. Check availability before use with source, which is null when the scope is not mounted:
if (aui.message.source != null) {
aui.message.reload();
}
source, query, and name are reserved accessor properties and never resolve to scope methods.
AuiProvider mounts an AssistantClient for a subtree. Its config prop must be built with AuiConfig({...}), imported from @assistant-ui/react (raw object literals are a type error). At the top level config alone creates the subtree's client. Nested under a parent provider, extends is mandatory: extends={aui} extends the parent client, extends={null} isolates a fresh root (dev enforced). AssistantRuntimeProvider installs an AuiProvider internally and additionally accepts config to attach extra scopes (such as a toolkit) alongside the runtime's own scopes; use it instead of wiring AuiProvider by hand around a runtime.
import { AssistantRuntimeProvider, AuiConfig, AuiProvider, Tools, useAui } from "@assistant-ui/react";
// Runtime root: config attaches extra scopes next to the runtime's own
const config = AuiConfig({ tools: Tools({ toolkit }) });
<AssistantRuntimeProvider runtime={runtime} config={config}>{children}</AssistantRuntimeProvider>;
// Nested scope: extend the parent client
function MessageScope({ children }: { children: React.ReactNode }) {
const aui = useAui();
const nested = AuiConfig({ tools: Tools({ toolkit: extraToolkit }) });
return <AuiProvider extends={aui} config={nested}>{children}</AuiProvider>;
}
// Isolated root: detach from any parent client
const isolated = AuiConfig({});
<AuiProvider extends={null} config={isolated}>{children}</AuiProvider>;
A config is plain data: hoist it to module scope, build it inline per render, or memoize it, the provider never relies on config identity. ref on AuiProvider receives the resulting client after mount.
const aui = useAui();
const thread = aui.thread;
thread.append({ role: "user", content: [{ type: "text", text: "Hello" }] });
thread.startRun({ parentId: null });
thread.cancelRun();
const state = thread.getState(); // { messages, isRunning, capabilities, composer, ... }
const message = thread.message({ index: 0 }); // or { id: messageId }
message.reload();
message.switchToBranch({ position: "next" });
message.submitFeedback({ type: "positive" });
const editComposer = message.composer();
editComposer.beginEdit();
editComposer.setText("Updated");
editComposer.send();
Most events are deprecated in favor of deriving the same transition from useAuiState, which is correct on first render and replay in a way an event handler is not.
| Event | Status |
|---|---|
threads.selectionChanged | Current: fires once per main-thread switch with { threadId, previousThreadId }. Does not fire for the initially selected thread on mount |
thread.modelContextUpdate | Current: the model context lives in a provider, not in state, so there is no state-derivable equivalent |
composer.attachmentAddError | Current: reason is "no-adapter" | "not-accepted" | "adapter-error" |
composer.send, composer.attachmentAdd | Deprecated: observe composer text / attachments |
thread.runStart, thread.runEnd | Deprecated: observe s.thread.isRunning flipping |
thread.initialize | Deprecated: observe s.thread.messages becoming non-empty |
threadListItem.switchedTo, threadListItem.switchedAway | Deprecated: use threads.selectionChanged, filtering by id inside a per-item scope if needed |
The deprecated pair still fires and keeps working until the next major. threads.selectionChanged also fires in situations the old pair did not, such as switchToNewThread() and a deep-linked initial thread resolving after mount.
s.optional.<scope> resolves to undefined instead of throwing when a scope is not mounted, the safe way to read a scope from a component that renders both inside and outside it.
const partType = useAuiState((s) => s.optional.part?.type);
The imperative equivalent is aui.<scope>.source != null.
const capabilities = useAuiState((s) => s.thread.capabilities);
RuntimeCapabilities (from @assistant-ui/core): switchToBranch, switchBranchDuringRun, edit, reload, delete, cancel, refetchThread, unstable_copy, speech, dictation, voice, attachments, feedback, queue. Runtimes derive nearly all of these from what you supply (a callback, an adapter) rather than an explicit option; unstable_copy is the one flag ExternalStoreRuntime lets you force off via unstable_capabilities. refetchThread reports whether aui.threads.reloadMainThread() will refresh the open thread in place or fall back to remounting the runtime; see runtime-concepts.md.
"Cannot read property of undefined"
AssistantRuntimeProvider (or an AuiProvider whose config supplies the scope).s.optional.<scope> or guard on aui.<scope>.source != null.Infinite re-renders from useAuiState
A legacy hook import fails to resolve
useAssistantRuntime, useThreadRuntime, useThread, useMessage, useComposer, useMessagePart, useAttachment, useThreadListItem and friends were removed in 0.15. See state-hooks.md for the full mapping, or the update skill.State not updating
useAuiState rather than reading getState() in render; getState() is a one-time snapshot, not a subscription.Multiple threads or a conversation sidebar
threads.selectionChanged consumersThread and composer components that read this state for youAssistantCloud, managed persistence, and useChatRuntime({ cloud })references/adapters.md (opens in a new tab)references/external-store.md (opens in a new tab)references/local-runtime.md (opens in a new tab)references/runtime-concepts.md (opens in a new tab)references/state-hooks.md (opens in a new tab)references/types.md (opens in a new tab)references/voice.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
17 skills in this plugin
/assistant-uiOverview and router for assistant-ui, the React library for building AI chat interfaces from composable primitives and a styled elements catalog. Use for high-level, cross-cutting, or architecture questions: choosing packages, picking a runtime, or understanding the layers (elements, primitives, the aui client with AuiConfig and AuiProvider, the runtime, adapters) and the message model. Covers `@assistant-ui/react` 0.15.x, `@assistant-ui/ai-sdk` for AI SDK v7 (`useChatRuntime`), `@assistant-ui/core`, `@assistant-ui/store`, `assistant-stream`, `assistant-cloud`, the LangGraph, LangChain, Google ADK, A2A, AG-UI, Eve, OpenCode, and Pi adapters, the `@assistant-ui/react-native` and `@assistant-ui/react-ink` bindings, and the `useAui`, `useAuiState`, and `useAuiEvent` hooks. For a specific area route to a focused sibling instead: setup, elements, primitives, runtime, tools, generative-ui, streaming, cloud, thread-list, copilots, markdown, react-mcp, observability, react-native, ink, or update./cloudAdds AssistantCloud backed persistence, authorization, and telemetry to assistant-ui apps. Use when wiring cross-session thread and message history, multi-device chat, message feedback, file uploads, or auth: passing `cloud` to `useChatRuntime` from `@assistant-ui/ai-sdk`, `AISDKThreads({ cloud })` for `AuiConfig` hosts, or `cloud` on `useLangGraphRuntime`. Covers constructing `AssistantCloud` with `authToken` (JWT), `apiKey` plus `userId`/`workspaceId` (server-side only), or `anonymous`; Clerk, Auth0, Supabase, and Firebase integrations and a backend token endpoint; the `cloud.threads`, `cloud.files`, `cloud.runs`, and `cloud.telemetry` client surface; and a custom `ThreadHistoryAdapter` on `CloudMessagePersistence`. Route here for threads that do not persist, 401s against the cloud API, or feedback buttons that do not save. For the `<ThreadList />` sidebar UI use thread-list; for the general adapter contracts use runtime.npx claudepluginhub assistant-ui/skills --plugin assistant-uiOther plugins' skills for the same job