Home › Shopify › Shopify Hydrogen storefront Cursor rules

Shopify Hydrogen storefront Cursor rules

Cursor rules for Shopify Hydrogen storefronts: route loaders with the Storefront API, GraphQL fragments and codegen, caching strategies, cart actions, and SEO.

CursorShopify

How to use

Save this as .cursor/rules/hydrogen.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.cursor/rules/hydrogen.mdcDownload  
---
description: Hydrogen storefront conventions
globs: ["app/**/*.{ts,tsx}", "server.ts", "*.graphql"]
alwaysApply: false
---

# Shopify Hydrogen

## Commands
`npm run dev` (Hydrogen dev server with Mini Oxygen) · `npm run build` · `npm run codegen` (Storefront API types) · `npm run typecheck` · `npm run lint`. Deploys go through Oxygen/CI; never run a production deploy unless asked.

## Data
- Load data in route `loader`s with `context.storefront.query(QUERY, { variables, cache })`. Never call the Storefront API from components or with a hand-built `fetch`.
- Queries are `#graphql`-tagged template strings with reusable fragments; request only fields the route renders. Run codegen after changing a query and use the generated types.
- Pass `country` and `language` from `context.storefront.i18n` via `@inContext` for localized prices.
- Pick a cache strategy on every query: `CacheLong()` for menus/shop data, `CacheShort()` for products/collections, `CacheNone()` for customer or cart data.
- Split critical vs deferred data: await what's above the fold; return non-critical promises and render them with `<Suspense>`/`<Await>`.
- Customer data uses the Customer Account API client from context, never the Storefront token; it is never cached publicly.

## Cart and UI
- Cart mutations go through the cart handler in actions (`context.cart.addLines`, `updateLines`, `removeLines`) with `CartForm`. Optimistic UI is fine; the server response is the source of truth.
- Use Hydrogen components (`Image`, `Money`, `Pagination`/`getPaginationVariables`) instead of reimplementing them.
- Handle missing products with `throw new Response('Not found', { status: 404 })`.

## SEO and performance
Set route `meta` from product/collection SEO fields; keep canonical URLs and structured data. Use `Image` with `sizes`, avoid client-only fetching for anything indexable, and check the Storefront API version in `server.ts` before using newer fields.

More: all Shopify rules · all Cursor rules

Related rules

Shopify app AGENTS.md

AGENTS.md for Shopify apps built with Shopify CLI and the React Router template: auth, GraphQL Admin API, and webhooks.

AGENTS.mdShopify

Shopify Liquid theme rules

Cursor rules for Shopify Online Store 2.0 themes: sections and blocks, JSON templates, Liquid performance, Theme Check.

CursorShopify

Payload CMS 3 + Next.js Cursor rules

Cursor rules for Payload CMS 3 inside Next.js: collections and fields config, access control, hooks, Local API, generated types and migrations.

CursorPayload CMS

Strapi 5 headless CMS Cursor rules

Cursor rules for Strapi 5 backends: content-type schemas, Document Service API, controllers and services, policies, population, and generated types.

CursorStrapi

WordPress block theme & blocks rules

Cursor rules for WordPress block themes and custom blocks: theme.json v3, block.json, patterns, and @wordpress/scripts.

CursorWordPress

Drupal 11 module development CLAUDE.md

CLAUDE.md for Drupal 11 sites and custom modules: Composer, Drush, services and dependency injection, config management, and PHPUnit.

Claude Code (CLAUDE.md)Drupal

Get the best new AI prompts every week

One short email a week: the best new prompts and rules for ChatGPT, Claude, Gemini, Midjourney, Cursor and more, plus what changed in the tools. Free, unsubscribe anytime.

Finishes on our newsletter page at beehiiv (opens in a new tab). Or subscribe directly.