---
title: Being found in Search
summary: How the app's Search finds things inside an extension - collection routes for free, or a read-only search action for data that lives elsewhere.
audience: both
since: protocol 1
---

# Being found in Search

Search (the command palette: **Search** in the sidebar, or Ctrl/⌘+K) finds extensions by name, and also things inside them. As someone types, the host asks every installed extension at once for up to 5 results each, then shows them in one list, closest match first, with each result's extension named beside it. Picking one opens the extension's view at the result's route.

Closeness is judged on the `title` first (the whole title, its start, the start of a word, anywhere in it), then the `subtitle`. A result whose title and subtitle don't contain the query (it matched on a body, say) ranks below those that do, and your own order breaks ties. So give each result a title that names it, and return the best matches first.

Whatever makes your extension findable also lets people and the assistant file its things into their [Projects](../reference/projects.md).

There are two ways to be found, and an extension uses one of them.

## Collections: nearly free

Without anything extra, Search looks through your [collections](giving-the-assistant-data.md) with the same match as the `list` tool: a case-insensitive substring over `searchFields` (default: every string field). It doesn't start your extension to do it.

- The **first** search field is the result's title: its first line, without a markdown heading's `#`s. Put the field that names a record first. The subtitle is the collection's `itemName`.
- Add **`route`** so a found record opens in place, with `{id}` standing for its id. It must be a [route](../reference/host/view.md#routes) your view already understands. Without it, a result just opens your view where it was.

```ts
collections: [
  {
    name: "items",
    itemName: "task",
    searchFields: ["title", "notes"],
    route: "task/{id}",
    schema: { /* … */ },
  },
],
```

If your view's routes need more than the id (Mail's are `<folder>/<id>`), add a small route that takes only the id and redirects, with `navigate(…, { replace: true })`, to the full one.

## A search action: for data that lives elsewhere

When your data is behind an API, in a repository or in files, declare a read-only action and name it in the manifest's [`search`](../reference/manifest.md#searchdefinition). Search then calls it, and only it; your collections aren't searched.

```ts
// manifest.ts
actions: [
  {
    name: "search",
    title: "Search",
    description: "Find people and companies by name. Returns at most `limit` results, best first.",
    inputSchema: {
      type: "object",
      properties: { query: { type: "string" }, limit: { type: "number" } },
      required: ["query"],
    },
    readOnly: true,
  },
],
search: { action: "search" },
```

```ts
// actions.ts
search: async ({ query, limit = 5 }, host) => {
  const key = await host.storage.get<string>("apiKey");
  if (!key) return []; // Not connected yet: nothing to find, and no error.
  const people = await fetchPeople(key, String(query), Number(limit));
  return people.map((p) => ({ title: p.name, subtitle: p.company, route: `person/${p.id}` }));
},
```

- Return `SearchResult[]`, **best first**, at most `limit`. `title` and `subtitle` are plain text; `route` is one your view understands; `icon` (a Lucide name) is optional.
- **Sizes.** Search keeps `title` and `subtitle` to 200 characters and `route` to 2,000, cutting longer ones, and drops an `icon` that isn't 1 to 64 lowercase letters, digits and `-` (your extension's icon shows instead). A result without a non-empty string `title` is left out. A project that links to a result keeps the same values (see [Projects](../reference/projects.md#projectitem)).
- **Be quick.** An extension has 4 seconds; a slower answer is dropped, and so is a newer keystroke's older answer. Ask your API for few results, and use its own search rather than listing everything and filtering.
- **Return `[]` quietly** when there's nothing to search yet: no account, no site, no repository. An error just leaves your extension out of the results, but it's still wasted work on every keystroke.
- Search starts your frame without showing it, as the assistant does. Keep the work in the action; don't depend on your view having run.
- The assistant can call the action too, like any read-only action, so write its `description` for the model.

`defineExtension` checks that `search.action` names a declared action with `readOnly: true`, and that each collection `route` contains `{id}`.
