/shopify-hydrogen:hydrogen-predictive-searchfrom shopify-hydrogen
Guide for building predictive search with @shopify/hydrogen. Use when adding, modifying, or reviewing autocomplete/search-as-you-type UI, predictive search route handlers, tracking URLs, custom predictive search fragments, or framework predictive search bindings.
Ships in shopify-hydrogen. 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.
Hydrogen predictive search has four layers:
@shopify/hydrogen./api/predictive-search.Keep rendering app-owned. Hydrogen provides data, state, request lifecycle, and URL helpers — not a dropdown template.
Register the packaged route handler in the app's central handleShopifyRoutes() wiring before framework routing. Use the hydrogen-request-handlers skill for the full framework-specific request context, session manager, and Storefront client setup.
import { createPredictiveSearchServerHandlers } from "@shopify/hydrogen";
const predictiveSearchHandlers = createPredictiveSearchServerHandlers();
Use the same request-scoped Storefront client as the app's other Hydrogen handlers and loaders. Do not create a second client inside predictive search code.
The default browser predictive search endpoint is GET /api/predictive-search. Override it with predictiveSearchEndpoint when the JSON route lives elsewhere. The route accepts q plus optional Storefront API controls such as limit, limitScope, types, searchableFields, and unavailableProducts.
When the storefront serves locales under a path prefix (/fr-ca), the request, the form action, and the result links all need that prefix. Inside LocaleProvider, the React and Vue providers add it to the endpoint and the search action; result links take pathPrefix from useLocale() (see "Tracking URLs"). Use the local hydrogen-markets skill for the setup.
When building with a UI framework, check this skill's references/ directory for framework-specific instructions. Framework bindings share the same route, store, and URL contracts.
Use getPredictiveSearchItemUrl() for predictive result links. It infers Hydrogen's standard storefront route from the item's __typename and keeps Storefront API trackingParameters without double-encoding:
import { getPredictiveSearchItemUrl } from "@shopify/hydrogen";
const productHref = getPredictiveSearchItemUrl(product, { routes: routeTemplates, term });
const querySuggestionHref = getPredictiveSearchItemUrl(querySuggestion, {
routes: routeTemplates,
});
Pass {pathPrefix} when locales are served under a path prefix, so result links stay in the page's locale. Pass {term} for resource items such as products, collections, pages, and articles. These items do not contain the shopper's typed search text, but the destination URL needs it for attribution. Do not pass {term} for SearchQuerySuggestion items; the helper uses querySuggestion.text automatically. Pass {routes: routeTemplates} so query suggestions honor a custom search route. Pass {searchPath} only when the suggestion link intentionally differs from the shared search route; it takes precedence when provided.
If the storefront uses custom Shopify resource paths, use the local hydrogen-routing skill before wiring predictive search result URLs. Do not create predictive-search-only URL callbacks.
Use getSearchResultUrl() only when constructing a custom search-attributed URL that is not backed by a predictive search item.
Do not publish a new analytics event for predictive suggestions. Full search pages can keep their existing search-view analytics; predictive result links carry attribution through tracking parameters.
Use additive fragments when the UI needs extra result fields:
import {
createPredictiveSearchServerHandlers,
gql,
makePredictiveSearchQueries,
queryPredictiveSearch,
} from "@shopify/hydrogen";
const predictiveSearchFragments = {
product: gql(`
fragment PredictiveSearchProductFragment on Product {
vendor
}
`),
};
export const predictiveSearchHandlers = createPredictiveSearchServerHandlers({
fragments: predictiveSearchFragments,
});
const queries = makePredictiveSearchQueries({
fragments: predictiveSearchFragments,
});
const data = await queryPredictiveSearch({
storefrontClient,
term,
query: queries.predictiveSearch,
});
Use the route-handler form for browser-backed autocomplete. Use makePredictiveSearchQueries() when querying directly from server code. Keep fragment names as documented by the API types. Hydrogen composes these with required base fields such as IDs, handles, titles, prices, images, and tracking parameters.
Type client state from the same handlers so the UI sees the custom fields:
import type { PredictiveSearchDataFromHandlers } from "@shopify/hydrogen";
import { usePredictiveSearch } from "@shopify/hydrogen/react"; // or "@shopify/hydrogen/vue"
import type { predictiveSearchHandlers } from "./predictive-search-handlers";
type SearchData = PredictiveSearchDataFromHandlers<typeof predictiveSearchHandlers>;
// Call inside a component or setup().
export function usePredictiveSearchState() {
return usePredictiveSearch<SearchData>();
}
Import the handlers with import type so server code stays out of the client bundle. Derive the type from the handlers rather than writing it by hand, and point the provider at those handlers' route: the client doesn't validate responses, and when there's no response to show, the result only holds empty item arrays.
/search link or a role="search" GET form, and the predictive modal's form must submit GET /search natively (formProps() defaults to this). Predictive autocomplete is an enhancement layered on top — never the only way to reach search results. With JS off, the trigger navigates to /search (or submits the term to it) and the full search page renders results server-side.trackingParameters on every predictive result link.q for the search term so predictive and full search URLs align.hydrogen-routing skill for result URLs when the app uses custom Shopify resource paths.<dialog> opened with showModal(). For backdrop-dismiss, use closedby="any" where supported. For browsers without closedby support, use a pointerdown-plus-click guard: record whether pointerdown started on the dialog backdrop, then close only when the following click also targets the dialog. Do not close on a plain click.self alone — a drag that starts inside and ends on the backdrop can produce an accidental close.Done when:
/search link or role="search" GET form reaches server-rendered results, and the predictive modal's form submits GET /search natively./api/predictive-search route.trackingParameters (built with getPredictiveSearchItemUrl()).q so predictive and full search URLs align./search link or native GET form underneath, leaves no-JS shoppers with no way to search. The predictive layer must enhance a working /search path, not replace it./search?predictive=true as the autocomplete API when /api/predictive-search is available.What SKILL.md sets; muted values are Claude Code's defaults
11 skills in this plugin
/hydrogen-cart-drawerGuide for building an accessible cart drawer using @shopify/hydrogen. Use when creating or reviewing a cart drawer, mini cart, or slide-out cart, including native dialog element (showModal), closedby light dismiss, body scroll lock, exit animations, and wiring window.Shopify.actions.openCart()./hydrogen-cart-uiBehavioral guide for building cart UI with @shopify/hydrogen: line items, quantity and remove controls, optimistic updates, discount, note, and cart attribute inputs, and the full-page /cart fallback. Use when writing, modifying, or reviewing cart line-item UI, quantity/remove controls, cart mutation forms, or code that changes the cart without a form. Framework agnostic./hydrogen-customer-accountCustomer Account API setup for Hydrogen storefronts. Use when wiring customer sessions, login/logout/OAuth route handlers, account profile, order history, account-gated UI, cart buyer identity sync, or Customer Account GraphQL queries./hydrogen-marketsGuide for implementing Shopify Markets with Hydrogen. Use when adding market routing, country/language localization, Shopify Markets, subdomains, per-market domains, path-prefixed markets, defineShopifyI18n, LocaleProvider, locale switchers, hreflang links, the <html lang> attribute, Next.js App Router market routing, or Storefront API @inContext wiring./hydrogen-oxygenAudit and adapt an existing Hydrogen storefront for Shopify Oxygen and local MiniOxygen. Use when asked to make a server-capable Hydrogen project Oxygen-compatible, add or repair its Worker server entrypoint, configure MiniOxygen, remove Node runtime assumptions, wire Worker environment, cache, and waitUntil, or verify dev, preview, and deploy behavior./hydrogen-routingGuide for Hydrogen route templates and Shopify storefront URL routing. Use when adding, modifying, or reviewing defineShopifyRouteTemplates, routeTemplates, custom Shopify resource or utility-page paths, handleShopifyRoutes, standard route redirects, ShopifyScripts routes, predictive search result URLs, or localized path prefixes from defineShopifyI18n.Other plugins' skills for the same job
npx claudepluginhub fcakiroglu16/marketplace --plugin shopify-hydrogen