# Thread Search (/docs/agent-ui/components/thread-search)

Use a thread search to let people jump to any conversation they've had with the agent, by its title or what was said in it. The button opens a dialog with a search field over the threads, grouped by date, and a **New chat** row after them.

<Example caption="Press Search chats, or press Cmd+K or Ctrl+K, type build, then press Enter to open the thread. Choose New chat to start one with what you typed.">
  <ThreadSearchExample />

  ```tsx tab="React"
  "use client";
  import { useState } from "react";
  import { ThreadSearch } from "@/components/ui/thread-search";

  const initialThreads = [
    {
      id: "t1",
      title: "Fix the flaky login test",
      updatedAt: "2026-11-18T09:12:00Z",
      status: "running" as const,
    },
    {
      id: "t2",
      title: "Release notes for 0.6",
      updatedAt: "2026-11-02T16:40:00Z",
      pinned: true,
      snippet: "Draft the highlights and the breaking changes",
    },
    {
      id: "t3",
      title: "Rename the billing tables",
      updatedAt: "2026-11-18T07:30:00Z",
      status: "awaiting-input" as const,
      snippet: "Waiting for approval to run the migration",
    },
    { id: "t4", title: "Onboarding checklist", updatedAt: "2026-11-10T11:05:00Z", group: "Handbook" },
    {
      id: "t5",
      title: "Why is the build slow?",
      updatedAt: "2026-11-17T18:22:00Z",
      snippet: "Type checking takes 40 s",
    },
    { id: "t6", title: "Dark mode tokens", updatedAt: "2026-11-14T13:50:00Z" },
    {
      id: "t7",
      title: "Search index size",
      updatedAt: "2026-11-12T08:15:00Z",
      snippet: "Split the index by section",
    },
    { id: "t8", title: "Plan the docs site", updatedAt: "2026-10-21T10:00:00Z" },
    { id: "t9", title: "Upgrade to Node 24", updatedAt: "2026-09-03T15:30:00Z", pinned: true },
    { id: "t10", title: "Kickoff notes", updatedAt: "2025-12-01T09:00:00Z" },
  ];

  export default function ThreadSearchExample() {
    const [threads, setThreads] = useState(initialThreads);
    const [opened, setOpened] = useState("Nothing opened yet");
    return (
      <div style={{ display: "grid", gap: "0.75rem", justifyItems: "start" }}>
        <ThreadSearch
          threads={threads}
          now="2026-11-18"
          timeZone="UTC"
          shortcut="mod+k"
          onSelect={(id) => setOpened(`Opened: ${threads.find((thread) => thread.id === id)?.title}`)}
          onNew={(query) => {
            const title = query.trim() || "New chat";
            setThreads([
              { id: `new-${threads.length + 1}`, title, updatedAt: "2026-11-18T12:00:00Z" },
              ...threads,
            ]);
            setOpened(`Opened: ${title}`);
          }}
        />
        <p>{opened}</p>
      </div>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import { ref, shallowRef } from "vue";
  import { ThreadSearch } from "@/components/ui/vue/thread-search";

  const initialThreads = [
    {
      id: "t1",
      title: "Fix the flaky login test",
      updatedAt: "2026-11-18T09:12:00Z",
      status: "running" as const,
    },
    {
      id: "t2",
      title: "Release notes for 0.6",
      updatedAt: "2026-11-02T16:40:00Z",
      pinned: true,
      snippet: "Draft the highlights and the breaking changes",
    },
    {
      id: "t3",
      title: "Rename the billing tables",
      updatedAt: "2026-11-18T07:30:00Z",
      status: "awaiting-input" as const,
      snippet: "Waiting for approval to run the migration",
    },
    { id: "t4", title: "Onboarding checklist", updatedAt: "2026-11-10T11:05:00Z", group: "Handbook" },
    {
      id: "t5",
      title: "Why is the build slow?",
      updatedAt: "2026-11-17T18:22:00Z",
      snippet: "Type checking takes 40 s",
    },
    { id: "t6", title: "Dark mode tokens", updatedAt: "2026-11-14T13:50:00Z" },
    {
      id: "t7",
      title: "Search index size",
      updatedAt: "2026-11-12T08:15:00Z",
      snippet: "Split the index by section",
    },
    { id: "t8", title: "Plan the docs site", updatedAt: "2026-10-21T10:00:00Z" },
    { id: "t9", title: "Upgrade to Node 24", updatedAt: "2026-09-03T15:30:00Z", pinned: true },
    { id: "t10", title: "Kickoff notes", updatedAt: "2025-12-01T09:00:00Z" },
  ];

  type Thread = { id: string; title: string; updatedAt: string };

  const threads = shallowRef<Thread[]>(initialThreads);
  const opened = ref("Nothing opened yet");

  function onSelect(id: string) {
    opened.value = `Opened: ${threads.value.find((thread) => thread.id === id)?.title}`;
  }

  function onNew(query: string) {
    const title = query.trim() || "New chat";
    threads.value = [
      { id: `new-${threads.value.length + 1}`, title, updatedAt: "2026-11-18T12:00:00Z" },
      ...threads.value,
    ];
    opened.value = `Opened: ${title}`;
  }
  </script>

  <template>
    <div style="display: grid; gap: 0.75rem; justify-items: start">
      <ThreadSearch
        :threads="threads"
        now="2026-11-18"
        time-zone="UTC"
        shortcut="mod+k"
        @select="onSelect"
        @new="onNew"
      />
      <p>{{ opened }}</p>
    </div>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import { ThreadSearch } from "@/components/ui/svelte/thread-search/index.js";

    let threads = $state.raw([
      {
        id: "t1",
        title: "Fix the flaky login test",
        updatedAt: "2026-11-18T09:12:00Z",
        status: "running" as const,
      },
      {
        id: "t2",
        title: "Release notes for 0.6",
        updatedAt: "2026-11-02T16:40:00Z",
        pinned: true,
        snippet: "Draft the highlights and the breaking changes",
      },
      {
        id: "t3",
        title: "Rename the billing tables",
        updatedAt: "2026-11-18T07:30:00Z",
        status: "awaiting-input" as const,
        snippet: "Waiting for approval to run the migration",
      },
      { id: "t4", title: "Onboarding checklist", updatedAt: "2026-11-10T11:05:00Z", group: "Handbook" },
      {
        id: "t5",
        title: "Why is the build slow?",
        updatedAt: "2026-11-17T18:22:00Z",
        snippet: "Type checking takes 40 s",
      },
      { id: "t6", title: "Dark mode tokens", updatedAt: "2026-11-14T13:50:00Z" },
      {
        id: "t7",
        title: "Search index size",
        updatedAt: "2026-11-12T08:15:00Z",
        snippet: "Split the index by section",
      },
      { id: "t8", title: "Plan the docs site", updatedAt: "2026-10-21T10:00:00Z" },
      { id: "t9", title: "Upgrade to Node 24", updatedAt: "2026-09-03T15:30:00Z", pinned: true },
      { id: "t10", title: "Kickoff notes", updatedAt: "2025-12-01T09:00:00Z" },
    ]);
    let opened = $state("Nothing opened yet");
  </script>

  <div style="display: grid; gap: 0.75rem; justify-items: start">
    <ThreadSearch
      {threads}
      now="2026-11-18"
      timeZone="UTC"
      shortcut="mod+k"
      onSelect={(id: string) => (opened = `Opened: ${threads.find((thread) => thread.id === id)?.title}`)}
      onNew={(query: string) => {
        const title = query.trim() || "New chat";
        threads = [{ id: `new-${threads.length + 1}`, title, updatedAt: "2026-11-18T12:00:00Z" }, ...threads];
        opened = `Opened: ${title}`;
      }}
    />
    <p>{opened}</p>
  </div>
  ```

  ```tsx tab="Solid"
  import { createSignal } from "solid-js";
  import { ThreadSearch } from "@/components/ui/solid/thread-search";

  const initialThreads = [
    {
      id: "t1",
      title: "Fix the flaky login test",
      updatedAt: "2026-11-18T09:12:00Z",
      status: "running" as const,
    },
    {
      id: "t2",
      title: "Release notes for 0.6",
      updatedAt: "2026-11-02T16:40:00Z",
      pinned: true,
      snippet: "Draft the highlights and the breaking changes",
    },
    {
      id: "t3",
      title: "Rename the billing tables",
      updatedAt: "2026-11-18T07:30:00Z",
      status: "awaiting-input" as const,
      snippet: "Waiting for approval to run the migration",
    },
    { id: "t4", title: "Onboarding checklist", updatedAt: "2026-11-10T11:05:00Z", group: "Handbook" },
    {
      id: "t5",
      title: "Why is the build slow?",
      updatedAt: "2026-11-17T18:22:00Z",
      snippet: "Type checking takes 40 s",
    },
    { id: "t6", title: "Dark mode tokens", updatedAt: "2026-11-14T13:50:00Z" },
    {
      id: "t7",
      title: "Search index size",
      updatedAt: "2026-11-12T08:15:00Z",
      snippet: "Split the index by section",
    },
    { id: "t8", title: "Plan the docs site", updatedAt: "2026-10-21T10:00:00Z" },
    { id: "t9", title: "Upgrade to Node 24", updatedAt: "2026-09-03T15:30:00Z", pinned: true },
    { id: "t10", title: "Kickoff notes", updatedAt: "2025-12-01T09:00:00Z" },
  ];

  export default function ThreadSearchExample() {
    const [threads, setThreads] = createSignal(initialThreads);
    const [opened, setOpened] = createSignal("Nothing opened yet");
    return (
      <div style={{ display: "grid", gap: "0.75rem", "justify-items": "start" }}>
        <ThreadSearch
          threads={threads()}
          now="2026-11-18"
          timeZone="UTC"
          shortcut="mod+k"
          onSelect={(id) => setOpened(`Opened: ${threads().find((thread) => thread.id === id)?.title}`)}
          onNew={(query) => {
            const title = query.trim() || "New chat";
            setThreads([
              { id: `new-${threads().length + 1}`, title, updatedAt: "2026-11-18T12:00:00Z" },
              ...threads(),
            ]);
            setOpened(`Opened: ${title}`);
          }}
        />
        <p>{opened()}</p>
      </div>
    );
  }
  ```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/thread-search
```

```bash tab="Web Components"
npx shadcn@latest add @kind-ui/thread-search-web
```

```bash tab="Vue"
npx shadcn@latest add @kind-ui/thread-search-vue
```

```bash tab="Svelte"
npx shadcn@latest add @kind-ui/thread-search-svelte
```

```bash tab="Solid"
npx shadcn@latest add @kind-ui/thread-search-solid
```

## Composition [#composition]

```text
ThreadSearch
├── ThreadSearchTrigger
│   └── ThreadSearchShortcut
├── ThreadSearchBackdrop
└── ThreadSearchContent
    └── ThreadSearchList
        └── ThreadSearchSectionRows
            └── ThreadSearchRowItem
                └── ThreadSearchItem
                    └── ThreadSearchStatus
```

`ThreadSearchTrigger` is the button, with a search icon, the `label` and `ThreadSearchShortcut`, the `shortcut`'s keys. `ThreadSearchBackdrop` dims the page under the dialog, and a press on it closes the dialog. `ThreadSearchContent` is the dialog, and `ThreadSearchList` is UI SDK's Command inside it: the search field, its status line, the text shown while nothing matches, and the rows. To arrange the rows yourself, pass `ThreadSearchList` a function of its state that renders `ThreadSearchSectionRows` for each group. `ThreadSearchRowItem` is a row, and `ThreadSearchItem` is its content: the title, the snippet, `ThreadSearchStatus` (the thread's status mark, named in words) and the date.

## Usage [#usage]

### Threads [#threads]

Pass `threads`, each with an `id` and a `title`, and optionally `updatedAt` (an ISO date-time), `pinned`, a `group`, a `snippet` (a second line under the title) and a `status` (`running`, `awaiting-input` or `error`, shown as a status mark named in words).

Threads are grouped as Thread List groups them: pinned ones first, then each `group` in the order it first appears, then by date from `updatedAt`: Today, Yesterday, Previous 7 days, Previous 30 days, then months and years. A pinned or grouped thread shows its date at the end of its row, like Nov 2. Pass `groupLabels` to rename the fixed groups, by key (`pinned`, `today`, `previous-7-days`, …).

The date groups depend on today. Pass `now`, an ISO date or an instant, so a server and a browser group the same; without it, it's today in `timeZone`, which is UTC by default. Set `locale` for the groups' words.

### Searching [#searching]

While the search is empty, only the newest 20 threads show. Typing searches every thread for the text as typed, in its title and snippet, and marks it. Threads whose title holds it come first, and each group moves to where its best match is. When nothing matches, the list shows `emptyText` ("No chats found"). Set `placeholder` to change the field's "Search chats…", and `label` to rename the button and the dialog.

### Choosing a Thread [#choosing-a-thread]

Choosing a thread calls `onSelect` with its `id`, with the reason `item-press` when a person chose it, or `imperative` from `select`, and closes the dialog. Cancel it with `details.cancel()` to keep the dialog open. The component doesn't follow a thread's `href`, so navigate in `onSelect`.

### New Chat [#new-chat]

Pass `onNew` to add a **New chat** row after the threads (`newLabel` renames it). It shows whatever the search, below "No chats found" when nothing matches, and names what was typed, like **New chat: “launch plan”**. It gets the search text, so the new conversation can start with what the person typed, and closes the dialog unless you cancel it.

### Shortcut [#shortcut]

Pass `shortcut`, like `"mod+k"`, to open the dialog from anywhere on the page. `mod` is Cmd on Apple platforms and Ctrl elsewhere, and the button shows the keys as the platform writes them, like ⌘K. There's no shortcut by default, and it does nothing while another modal dialog is open.

### Server Search [#server-search]

To search on your server, pass `filter={false}`. The dialog then shows `threads` as you pass them, in your order and ungrouped, with **Pinned** or the date at the end of each row. Follow `onQueryChange`, or control `query`, to run the search, and set `status` while it runs:

```tsx
<ThreadSearch
  threads={results}
  filter={false}
  status={loading ? "loading" : failed ? "error" : "idle"}
  onQueryChange={(query) => searchThreads(query)}
  onSelect={(id) => router.push(`/chat/${id}`)}
/>
```

While `status` is `"loading"`, the status line says `loadingText` ("Searching") and the list is `aria-busy`. With `"error"` it says `errorText` ("Search failed").

### Keyboard [#keyboard]

The button is one Tab stop. Enter or Space opens the dialog with focus in the search field. The arrow keys move the highlight, and Enter chooses. Escape clears the search, then closes the dialog, and focus returns to the button. A line under the list, `ThreadSearchHints`, shows these keys to the eye; screen readers skip it, and touch screens hide it.

### Presentation and Motion [#presentation-and-motion]

The search opens as a modal dialog over the page. With `presentation="auto"`, the default, it's a bottom sheet on small touch screens instead; pass `"sheet"` to always show a sheet. The dialog rises and fades in. Under `prefers-reduced-motion`, or with `motion="reduced"`, it only fades, over 120 ms, and with `motion="none"` it opens at once.

## API Reference [#api-reference]

### ThreadSearchOptions

Thread Search's options: Picker's, less the value and footer actions, with its search and the threads.

| Prop             | Type                                                                                       | Description                                                                                                                                                                                                                                                                        |
| ---------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `open?`          | `boolean \| undefined`                                                                     | Whether the list is open. Passing it controls it: change it in `onOpenChange`.                                                                                                                                                                                                     |
| `defaultOpen?`   | `boolean \| undefined`                                                                     | Whether the list is open at first, when `open` isn't passed. Default: `false`                                                                                                                                                                                                      |
| `onOpenChange?`  | `((open: boolean, details: ChangeDetails<PickerOpenChangeReason>) => void) \| undefined`   | Called when the list opens or closes, with what caused it.                                                                                                                                                                                                                         |
| `presentation?`  | `"auto" \| "popover" \| "sheet"`                                                           | How the list presents. `"auto"` is a bottom sheet on small touch screens and a popover elsewhere. Default: `"auto"`                                                                                                                                                                |
| `disabled?`      | `boolean \| undefined`                                                                     | Whether the trigger can't open the list. Default: `false`                                                                                                                                                                                                                          |
| `motion?`        | `"auto" \| "none" \| "reduced"`                                                            | How the list opens and closes. `"auto"` follows `prefers-reduced-motion`. Default: `"auto"`                                                                                                                                                                                        |
| `query?`         | `string \| undefined`                                                                      | What the search field holds. Passing it controls it: change it in `onQueryChange`.                                                                                                                                                                                                 |
| `defaultQuery?`  | `string \| undefined`                                                                      | What the search field holds at first, when `query` isn't passed. Default: `""`                                                                                                                                                                                                     |
| `onQueryChange?` | `((query: string, details: ChangeDetails<CommandQueryChangeReason>) => void) \| undefined` | Called when a person types or `search` runs, with why.                                                                                                                                                                                                                             |
| `filter?`        | `boolean \| undefined`                                                                     | `false` shows the rows as they are, for results the host searched itself, and leaves them in its order. Default: `true`                                                                                                                                                            |
| `status?`        | `"error" \| "idle" \| "loading"`                                                           | Whether the host's results are loading or failed, which a status line says and the list's `aria-busy` follows. Default: `"idle"`                                                                                                                                                   |
| `loadingText?`   | `string \| undefined`                                                                      | The status line while `status` is `"loading"`. Default: `"Searching"`                                                                                                                                                                                                              |
| `errorText?`     | `string \| undefined`                                                                      | The status line while `status` is `"error"`. Default: `"Search failed"`                                                                                                                                                                                                            |
| `threads?`       | `Thread[] \| undefined`                                                                    | The threads to search. While the search is empty the newest 20 show; while it filters, every one does, grouped as Thread List groups them: pinned first, then each `group`, then by date from `updatedAt`, the groups and rows holding the search's text best first. Default: `[]` |
| `onSelect?`      | `((id: string, details: ChangeDetails<ThreadSearchSelectReason>) => void) \| undefined`    | Called when a person or `select` chooses a thread, by its `id`. Cancel it to keep the dialog open.                                                                                                                                                                                 |
| `onNew?`         | `((query: string, details: ChangeDetails<ThreadSearchSelectReason>) => void) \| undefined` | Adds a "New chat" row after the threads, which shows whatever the search and names it (`New chat: “text”`), called with the search text when a person or `newThread` runs it.                                                                                                      |
| `newLabel?`      | `string \| undefined`                                                                      | Names the "New chat" row. Default: `"New chat"`                                                                                                                                                                                                                                    |
| `label?`         | `string \| undefined`                                                                      | Names the trigger, the dialog and the search field. Default: `"Search chats"`                                                                                                                                                                                                      |
| `placeholder?`   | `string \| undefined`                                                                      | Shown in the empty search field. Default: `"Search chats…"`                                                                                                                                                                                                                        |
| `emptyText?`     | `string \| undefined`                                                                      | Shown while no thread matches the search. Default: `"No chats found"`                                                                                                                                                                                                              |
| `shortcut?`      | `string \| undefined`                                                                      | Keys that open the dialog from anywhere on the page, like `"mod+k"`, shown in the trigger. None by default.                                                                                                                                                                        |
| `now?`           | `string \| undefined`                                                                      | Today, for the date groups: an ISO date or an instant. Defaults to today in `timeZone`.                                                                                                                                                                                            |
| `locale?`        | `string \| undefined`                                                                      | A BCP 47 tag for the date groups' words. Defaults to English.                                                                                                                                                                                                                      |
| `timeZone?`      | `string \| undefined`                                                                      | The IANA time zone that decides a thread's day. Defaults to UTC.                                                                                                                                                                                                                   |
| `groupLabels?`   | `Partial<Record<"pinned" \| DateGroupKey, string>> \| undefined`                           | Replaces the fixed groups' words ("Pinned", "Previous 7 days", …), by key.                                                                                                                                                                                                         |

Vue, Svelte and Solid take the same props. Controlled props and callbacks are spelled as each framework expects:

| React                    | Vue                              | Svelte                        | Solid                    |
| ------------------------ | -------------------------------- | ----------------------------- | ------------------------ |
| `open`, `onOpenChange`   | `v-model:open`, `@open-change`   | `bind:open`, `onOpenChange`   | `open`, `onOpenChange`   |
| `query`, `onQueryChange` | `v-model:query`, `@query-change` | `bind:query`, `onQueryChange` | `query`, `onQueryChange` |
| `onSelect`               | `@select`                        | `onSelect`                    | `onSelect`               |
| `onNew`                  | `@new`                           | `onNew`                       | `onNew`                  |

### Agent [#agent]

An agent connected with `createAgent` finds the search by its label and reads `open` and `query`. Its `search` types into the field, as a person would. `select` takes a thread's `id` and refuses an unknown one, and is offered only while `onSelect` is set. `newThread` runs **New chat** with the search text and is offered only while `onNew` is set. None of them opens or closes the dialog, and none is offered while the search is `disabled`.

### ThreadSearchAgentActions

| Prop        | Type                                        | Description                                                                                                                                                                                                                                                                |
| ----------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `open`      | `(() => boolean) \| undefined`              | Opens the list. Offered only while it's closed and enabled. Returns whether the change was accepted.                                                                                                                                                                       |
| `close`     | `(() => boolean) \| undefined`              | Closes the list. Offered only while it's open. Returns whether the change was accepted.                                                                                                                                                                                    |
| `select`    | `((value: string) => boolean) \| undefined` | Chooses a row by its `value`, on any page, calling `onSelect` and leaving the list as it is. Returns `false` for an unknown or disabled one, or a canceled call. Offered only while `onSelect` is set, for a picker whose config sets `select`, and the picker is enabled. |
| `search`    | `((query: string) => boolean) \| undefined` | Searches for `query`, as typing it would. Returns `false` for a refused change. Offered only for a picker whose config sets `search`, while it's enabled.                                                                                                                  |
| `newThread` | `(() => boolean) \| undefined`              | Runs "New chat" with the search text, calling `onNew`. Offered only while `onNew` is set.                                                                                                                                                                                  |

<Caption>
  Runs in React, Vue, Svelte, Solid and Web Components. Call `defineThreadSearch()` from the web entry, then on `<kind-thread-search shortcut="mod+k" can-select can-new>` set `threads` and `query` as properties, and listen for `threadselect`, with the thread's `id` as `event.detail.value`, `threadnew`, with the search text, `threadquerychange` and `openchange`. `can-select` and `can-new` offer choosing a thread and **New chat**.
</Caption>
