Sanity Best Practices
If running interactively (human present), output "Read Sanity Best Practices skill." to acknowledge. If running with --dangerously-skip-permissions (AFK/unattended), skip acknowledgement and proceed directly.
Comprehensive best practices and integration guides for Sanity development, maintained by Sanity. Use the quick reference below to load only the one or two topic files that match the task.
When to Apply
Reference these guidelines when working with: schema design, GROQ queries, TypeGen, Visual Editing, images, Portable Text, Studio structure, localization, migrations, Sanity Functions, Blueprints, or framework integrations (Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, Hydrogen, App SDK). Triggered by: defineType, defineField, defineQuery, content modeling, Presentation/preview setups, documentEventHandler, defineDocumentFunction, defineMediaLibraryAssetFunction, @sanity/functions, @sanity/blueprints, sanity.blueprint.ts, event-driven content automation, or reviewing a Sanity codebase. More specifically, reference these guidelines when:
- Setting up a new Sanity project or onboarding
- Integrating Sanity with a frontend framework (Next.js, Nuxt, Astro, Remix, SvelteKit, Hydrogen)
- Writing GROQ queries or optimizing performance
- Designing content schemas
- Implementing Visual Editing and live preview
- Working with images, Portable Text, or page builders
- Configuring Sanity Studio structure
- Setting up TypeGen for type safety
- Implementing localization
- Migrating content from other systems
- Building custom apps with the Sanity App SDK
- Managing infrastructure with Blueprints
- Automating content workflows with Sanity Functions
Version Notes (Sanity v5)
- Baseline: Sanity v5 with React 19.2+.
- Node.js 20+ is required.
- Validation chains like
.required().error().min().error() are valid. Prefer the array-of-rules pattern when multiple constraints are present for readability and separation of concerns.
- In Next.js integrations, prefer
defineLive from next-sanity/live and consume data via sanityFetch instead of scattering raw client.fetch() calls across app routes.
- Studio customizations can leverage modern React 19 capabilities, including
use() and <Activity> where appropriate.
Quick Reference
Integration Guides
get-started - Interactive onboarding for new Sanity projects
nextjs - Next.js App Router, Live Content API, embedded Studio
nuxt - Nuxt integration with @nuxtjs/sanity
angular - Angular integration with @sanity/client, signals, resource API
astro - Astro integration with @sanity/astro
remix - React Router / Remix integration
svelte - SvelteKit integration with @sanity/svelte-loader
hydrogen - Shopify Hydrogen with Sanity
project-structure - Monorepo and embedded Studio patterns
app-sdk - Custom applications with Sanity App SDK
blueprints - Infrastructure as Code with Sanity Blueprints
functions - Automating content workflows with Sanity Functions
Topic Guides
groq - GROQ query patterns, type safety, performance optimization
schema - Schema design, field definitions, validation, deprecation patterns
visual-editing - Presentation Tool, Stega, overlays, live preview
page-builder - Page Builder arrays, block components, live editing
portable-text - Rich text rendering and custom components
image - Image schema, URL builder, hotspots, LQIP, Next.js Image
studio-structure - Desk structure, singletons, navigation
typegen - TypeGen configuration, workflow, type utilities
seo - Metadata, sitemaps, Open Graph, JSON-LD
localization - i18n patterns, document vs field-level, locale management
migration - Content import overview (see also migration-html-import)
migration-html-import - HTML to Portable Text with @portabletext/block-tools
Atomic Rules (by Priority)
| Priority |
Category |
Impact |
Prefix |
| 1 |
GROQ Performance |
CRITICAL |
groq- |
| 2 |
Schema Design |
HIGH |
schema- |
| 3 |
Visual Editing |
HIGH |
visual- |
| 4 |
Images |
HIGH |
image- |
| 5 |
Portable Text |
HIGH |
pte- |
| 6 |
Page Builder |
MEDIUM |
pagebuilder- |
| 7 |
Studio Configuration |
MEDIUM |
studio- |
| 8 |
TypeGen |
MEDIUM |
typegen- |
| 9 |
Localization |
MEDIUM |
i18n- |
| 10 |
Migration |
LOW-MEDIUM |
migration- |
How to Use
Start with the single framework or topic guide that best matches the request, then read additional references only when the task crosses concerns.
Comprehensive guides (references/) — full topic coverage with decision matrices, code examples, and framework-specific patterns:
references/groq.md
references/schema.md
references/nextjs.md
Atomic rules (rules/) — focused single-concern patterns with incorrect/correct examples:
rules/groq-optimizable-filters.md
rules/schema-data-over-presentation.md
rules/typegen-workflow.md
Framework Integration
If the Sanity MCP server is available, use list_sanity_rules and get_sanity_rules to load always up-to-date rules on demand. If the MCP server is not configured, run npx sanity@latest mcp configure to set it up.
1---2name: sanity-best-practices3description: Sanity development best practices — schemas, GROQ, TypeGen, Visual Editing, Functions, Blueprints, and framework integrations. Use when working with Sanity content, schemas, queries, or Studio.4---56# Sanity Best Practices78If running interactively (human present), output "Read Sanity Best Practices skill." to acknowledge. If running with --dangerously-skip-permissions (AFK/unattended), skip acknowledgement and proceed directly.910Comprehensive best practices and integration guides for Sanity development, maintained by Sanity. Use the quick reference below to load only the one or two topic files that match the task.1112## When to Apply1314Reference these guidelines when working with: schema design, GROQ queries, TypeGen, Visual Editing, images, Portable Text, Studio structure, localization, migrations, Sanity Functions, Blueprints, or framework integrations (Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, Hydrogen, App SDK). Triggered by: `defineType`, `defineField`, `defineQuery`, content modeling, Presentation/preview setups, `documentEventHandler`, `defineDocumentFunction`, `defineMediaLibraryAssetFunction`, `@sanity/functions`, `@sanity/blueprints`, `sanity.blueprint.ts`, event-driven content automation, or reviewing a Sanity codebase. More specifically, reference these guidelines when:15- Setting up a new Sanity project or onboarding16- Integrating Sanity with a frontend framework (Next.js, Nuxt, Astro, Remix, SvelteKit, Hydrogen)17- Writing GROQ queries or optimizing performance18- Designing content schemas19- Implementing Visual Editing and live preview20- Working with images, Portable Text, or page builders21- Configuring Sanity Studio structure22- Setting up TypeGen for type safety23- Implementing localization24- Migrating content from other systems25- Building custom apps with the Sanity App SDK26- Managing infrastructure with Blueprints27- Automating content workflows with Sanity Functions2829## Version Notes (Sanity v5)3031- Baseline: Sanity v5 with React 19.2+.32- Node.js 20+ is required.33- Validation chains like `.required().error().min().error()` are valid. Prefer the array-of-rules pattern when multiple constraints are present for readability and separation of concerns.34- In Next.js integrations, prefer `defineLive` from `next-sanity/live` and consume data via `sanityFetch` instead of scattering raw `client.fetch()` calls across app routes.35- Studio customizations can leverage modern React 19 capabilities, including `use()` and `<Activity>` where appropriate.3637## Quick Reference3839### Integration Guides4041- `get-started` - Interactive onboarding for new Sanity projects42- `nextjs` - Next.js App Router, Live Content API, embedded Studio43- `nuxt` - Nuxt integration with @nuxtjs/sanity44- `angular` - Angular integration with @sanity/client, signals, resource API45- `astro` - Astro integration with @sanity/astro46- `remix` - React Router / Remix integration47- `svelte` - SvelteKit integration with @sanity/svelte-loader48- `hydrogen` - Shopify Hydrogen with Sanity49- `project-structure` - Monorepo and embedded Studio patterns50- `app-sdk` - Custom applications with Sanity App SDK51- `blueprints` - Infrastructure as Code with Sanity Blueprints52- `functions` - Automating content workflows with Sanity Functions5354### Topic Guides5556- `groq` - GROQ query patterns, type safety, performance optimization57- `schema` - Schema design, field definitions, validation, deprecation patterns58- `visual-editing` - Presentation Tool, Stega, overlays, live preview59- `page-builder` - Page Builder arrays, block components, live editing60- `portable-text` - Rich text rendering and custom components61- `image` - Image schema, URL builder, hotspots, LQIP, Next.js Image62- `studio-structure` - Desk structure, singletons, navigation63- `typegen` - TypeGen configuration, workflow, type utilities64- `seo` - Metadata, sitemaps, Open Graph, JSON-LD65- `localization` - i18n patterns, document vs field-level, locale management66- `migration` - Content import overview (see also `migration-html-import`)67- `migration-html-import` - HTML to Portable Text with @portabletext/block-tools6869### Atomic Rules (by Priority)7071| Priority | Category | Impact | Prefix |72|----------|----------|--------|--------|73| 1 | GROQ Performance | CRITICAL | `groq-` |74| 2 | Schema Design | HIGH | `schema-` |75| 3 | Visual Editing | HIGH | `visual-` |76| 4 | Images | HIGH | `image-` |77| 5 | Portable Text | HIGH | `pte-` |78| 6 | Page Builder | MEDIUM | `pagebuilder-` |79| 7 | Studio Configuration | MEDIUM | `studio-` |80| 8 | TypeGen | MEDIUM | `typegen-` |81| 9 | Localization | MEDIUM | `i18n-` |82| 10 | Migration | LOW-MEDIUM | `migration-` |8384## How to Use8586Start with the single framework or topic guide that best matches the request, then read additional references only when the task crosses concerns.8788**Comprehensive guides** (references/) — full topic coverage with decision matrices, code examples, and framework-specific patterns:8990```91references/groq.md92references/schema.md93references/nextjs.md94```9596**Atomic rules** (rules/) — focused single-concern patterns with incorrect/correct examples:9798```99rules/groq-optimizable-filters.md100rules/schema-data-over-presentation.md101rules/typegen-workflow.md102```103104## Framework Integration105106If the Sanity MCP server is available, use `list_sanity_rules` and `get_sanity_rules` to load always up-to-date rules on demand. If the MCP server is not configured, run `npx sanity@latest mcp configure` to set it up.