# BranchPicker
URL: /docs/primitives/branch-picker
Navigate between message branches, which are alternative responses the user can flip through.
The BranchPicker primitive lets users navigate between message branches, which are alternative responses generated by editing a message or regenerating a reply. It's used alongside ActionBar inside message components.
```tsx
import {
BranchPickerPrimitive,
MessagePrimitive,
} from "@assistant-ui/react";
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
function AssistantMessage() {
return (
/
);
}
```
Quick Start \[#quick-start]
Minimal example:
```tsx
import { BranchPickerPrimitive } from "@assistant-ui/react";
←
/
→
```
`Root` renders a `
`, `Previous` and `Next` render `
` elements that auto-disable at boundaries. `Number` and `Count` render plain text (the current branch index and total count).
BranchPicker must be placed inside a `MessagePrimitive.Root` because it reads branch state from the nearest message context.
Runtime setup: primitives require runtime context. Wrap your UI in `AssistantRuntimeProvider` with a runtime (for example `useLocalRuntime(...)`). See [Pick a Runtime](/docs/runtimes/pick-a-runtime).
Core Concepts \[#core-concepts]
Branch Navigation \[#branch-navigation]
`Previous` and `Next` buttons automatically disable at boundaries. `Previous` is disabled on the first branch, and `Next` is disabled on the last. Both also disable while the thread is running if the runtime doesn't support `switchBranchDuringRun`.
Number & Count \[#number--count]
`Number` and `Count` are text-only primitives that render raw numbers with no wrapping element. Use a `` if you need to style them:
```tsx
/
```
hideWhenSingleBranch \[#hidewhensinglebranch]
The `hideWhenSingleBranch` prop on `Root` hides the entire picker when there's only one branch. This is a common production pattern to reduce visual clutter:
```tsx
←
/
→
```
Context Requirement \[#context-requirement]
BranchPicker reads branch state from the nearest message context. It must be placed inside a `MessagePrimitive.Root`, either directly or nested inside your message component.
Parts \[#parts]
Root \[#root]
Container with optional `hideWhenSingleBranch`. Renders a `` element unless `asChild` is set.
```tsx
←
/
→
```
Previous \[#previous]
Button that selects the previous branch. Renders a `
` element unless `asChild` is set.
```tsx
Previous
```
Next \[#next]
Button that selects the next branch. Renders a `` element unless `asChild` is set.
```tsx
Next
```
Number \[#number]
Displays the current branch number.
```tsx
```
Count \[#count]
Displays the total number of branches for the current message.
```tsx
```
Patterns \[#patterns]
Standard Picker with Icons \[#standard-picker-with-icons]
```tsx
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
/
```
Custom Elements with asChild \[#custom-elements-with-aschild]
```tsx
```
The primitive's disabled state and click handler merge onto your element.
Inside a Message Footer \[#inside-a-message-footer]
The most common pattern places the BranchPicker alongside an ActionBar in a message footer:
```tsx
function AssistantMessage() {
return (
{/* prev / number / count / next */}
Copy
Reload
);
}
```
Relationship to Components \[#relationship-to-components]
The shadcn [Thread](/docs/ui/thread) component includes a BranchPicker in both AssistantMessage and UserMessage footers, with `hideWhenSingleBranch` enabled. If the default layout works, use the component. Reach for `BranchPickerPrimitive` directly when you need a custom position, different styling, or a non-standard branch navigation experience.
API Reference \[#api-reference]
For full prop details on every part, see the [BranchPickerPrimitive API Reference](/docs/api-reference/primitives/branch-picker).
Related:
* [ActionBarPrimitive API Reference](/docs/api-reference/primitives/action-bar)
* [MessagePrimitive API Reference](/docs/api-reference/primitives/message)