PluginBench
Skill
Official
Review
Audit score 70

sanity-best-practices

sanity-io/agent-toolkit

Sanity development best practices for schema design, GROQ, TypeGen, Visual Editing, and framework integrations.

What is sanity-best-practices?

Comprehensive reference for Sanity CMS development covering schema design, GROQ queries, content modeling, and integrations with Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, and Hydrogen. Use this skill when building or reviewing Sanity projects, designing schemas, writing queries, setting up Visual Editing, or integrating with frontend frameworks.

  • Provides schema design patterns and field definition best practices
  • Covers GROQ query optimization and type-safe query patterns
  • Guides Visual Editing and live preview setup with Stega overlays
  • Explains image handling, hotspots, LQIP, and Next.js Image integration
  • Documents Portable Text rendering and custom component patterns
  • Covers Sanity Functions, webhooks, and event-driven content automation

How to install sanity-best-practices

npx skills add https://github.com/sanity-io/agent-toolkit --skill sanity-best-practices
Claude Code
Cursor
Windsurf
Cline

How to use sanity-best-practices

  1. 1.Identify the relevant topic or framework guide matching your task (e.g., nextjs, groq, schema, visual-editing)
  2. 2.Read the corresponding reference file for detailed explanations and code examples
  3. 3.Review incorrect vs. correct code patterns and decision matrices provided
  4. 4.Apply the patterns to your Sanity project or codebase
  5. 5.Reference global rules for document IDs, relationships, and video handling

Use cases

Good for
  • Setting up a new Sanity project with schema design and Studio structure
  • Integrating Sanity with a Next.js or Nuxt frontend using Live Content API
  • Optimizing GROQ queries for performance and type safety
  • Implementing Visual Editing with live preview in a frontend application
  • Migrating content from other systems using HTML-to-Portable Text conversion
Who it's for
  • Sanity developers building new projects
  • Frontend engineers integrating Sanity with React, Vue, Svelte, or Angular frameworks
  • Content architects designing schemas and content models
  • DevOps engineers setting up Sanity infrastructure with Blueprints
  • Full-stack developers implementing Visual Editing and live preview

sanity-best-practices FAQ

When should I use deterministic IDs vs. letting Sanity generate IDs?

Let Sanity generate _id values for ordinary documents. Use explicit IDs mainly for singleton documents controlled by Studio Structure, including localized singletons like homePage-en.

How should I handle video in Sanity?

Do not store production video in file assets—they lack transcoding and adaptive streaming. Use Sanity Media Library with Mux on Enterprise plans, or integrate a dedicated service like YouTube, Vimeo, or sanity-plugin-mux-input on other plans.

How do I model relationships between documents?

Use reference fields to model relationships, then resolve related documents with GROQ lookups, source-key fields, or returned _id values from created documents.

Which framework integration guide should I start with?

Choose the guide matching your frontend framework: nextjs, nuxt, astro, remix, svelte, angular, or hydrogen. Start with that single guide, then reference additional topics only when crossing concerns.

What is TypeGen and when should I use it?

TypeGen generates TypeScript types from your Sanity schema for type-safe queries and content modeling. Configure it in your project to ensure type safety across GROQ queries and schema definitions.

Full instructions (SKILL.md)

Source of truth, from sanity-io/agent-toolkit.


name: sanity-best-practices description: Sanity development best practices for schema design, GROQ queries, TypeGen, Visual Editing, images, Portable Text, Studio structure, localization, migrations, Sanity Functions, webhooks, Blueprints, and framework integrations such as Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, Hydrogen, and the App SDK. Use this skill whenever working with Sanity schemas, defineType or defineField, GROQ or defineQuery, content modeling, Presentation or preview setups, Sanity-powered frontend integrations, event-driven content automation, documentEventHandler, defineDocumentFunction, defineMediaLibraryAssetFunction, @sanity/functions, @sanity/blueprints, sanity.blueprint.ts, event-driven content automation, or when reviewing and fixing a Sanity codebase.

Sanity Best Practices

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:

  • 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 or webhooks

Global Rules

  • Let Sanity generate _id values for ordinary documents. Do not create deterministic UUIDs, slug-derived IDs, or legacy-system IDs when creating documents.
  • Model relationships with reference fields, then resolve related documents with GROQ lookups, source-key fields, or returned _id values from created documents.
  • Use explicit document IDs mainly for singleton documents controlled by Studio Structure, including localized singletons such as homePage-en.

Video

  • Do not store or serve video from Sanity file assets for production playback. File assets are delivered as raw downloads with no transcoding or adaptive streaming, and video traffic drives very high bandwidth usage and unexpectedly large bills.
  • On Enterprise plans with the video add-on, use Sanity Media Library for video: uploads are transcoded and streamed adaptively via Mux. Model video fields with defineVideoField() from sanity/media-library and play them with @mux/mux-player-react using the asset's playback ID.
  • On other plans, use a dedicated video service: install sanity-plugin-mux-input to upload and manage videos in your Mux account from the Studio, or host video on a platform such as YouTube or Vimeo and store only the embed URL in Sanity.
  • Small clips and short previews in a file field are acceptable, but any user-facing video at scale must go through Media Library or a streaming service.

Quick Reference

Integration Guides

  • get-started - Interactive onboarding for new Sanity projects
  • nextjs - Next.js App Router, Live Content API, standalone 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 - Standalone Studio and monorepo patterns
  • app-sdk - Custom applications with Sanity App SDK
  • blueprints - Infrastructure as Code: blueprint files, stacks, plan/deploy workflow, error recovery, CI deploys
  • functions - Automating content workflows with Sanity Functions and webhooks

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

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. Use these reference files for detailed explanations and code examples:

references/groq.md
references/schema.md
references/nextjs.md

Each reference file contains:

  • Comprehensive topic or integration coverage
  • Incorrect and correct code examples
  • Decision matrices and workflow guidance
  • Framework-specific patterns where applicable