agentleFS
arndvsarndvs/ctrlshft/skills/sanity-best-practices/SKILL.md

sanity-best-practices

Skill0 starsChanged 6 months agoMITView on GitHub

Sanity development best practices — schemas, GROQ, TypeGen, Visual Editing, Functions, Blueprints, and framework integrations. Use when working with Sanity content, schemas, queries, or Studio.

We split this skill into the rules it gives an agent

3 rules. 1 is common, 0 are distinctive, and 2 are very specific to this project.

  • 1

    Common

    Most of the 6 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If running interactively (human present), output "Read Sanity Best Practices skill." to acknowledge.

    line 8
  2. Common:

    Start with the single framework or topic guide that best matches the request, then read additional references only when the task crosses …

    line 86
  3. Very specific:

    If the Sanity MCP server is available, use list_sanity_rules and get_sanity_rules to load always up-to-date rules on demand.

    line 106

“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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)

PriorityCategoryImpactPrefix
1GROQ PerformanceCRITICALgroq-
2Schema DesignHIGHschema-
3Visual EditingHIGHvisual-
4ImagesHIGHimage-
5Portable TextHIGHpte-
6Page BuilderMEDIUMpagebuilder-
7Studio ConfigurationMEDIUMstudio-
8TypeGenMEDIUMtypegen-
9LocalizationMEDIUMi18n-
10MigrationLOW-MEDIUMmigration-

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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.