Home › Sanity › Sanity Studio + GROQ AGENTS.md

Sanity Studio + GROQ AGENTS.md

AGENTS.md for Sanity projects: schema types with defineType, typed GROQ queries via TypeGen, Portable Text, previews, and safe content migrations.

AGENTS.mdSanity

How to use

Save this as AGENTS.md 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.

AGENTS.mdDownload  
# AGENTS.md: Sanity (Studio + frontend)

## Commands
- Studio dev: `npx sanity dev` · deploy (only when asked): `npx sanity deploy`
- Types: `npx sanity schema extract && npx sanity typegen generate` after any schema or query change
- Migrations: `npx sanity migration create` then `npx sanity migration run <id>` (dry run by default; add `--no-dry-run` only when asked)

## Code map
- `schemaTypes/` (or `sanity/schemaTypes/`): one file per document/object type, exported from `index.ts`.
- `sanity.config.ts`, `sanity.cli.ts` at the Studio root. Frontend queries in `lib/queries.ts` (or `sanity/lib/queries.ts`).

## Schema rules
- Use `defineType`, `defineField`, `defineArrayMember` for every type so TypeScript and TypeGen work.
- Every document has `title`, a `slug` with `options.source`, `validation` rules for required fields, and a `preview` config.
- Use references for shared entities (authors, categories) instead of duplicating objects.
- Images use `type: 'image'` with `options.hotspot: true` and a required `alt` field.
- Renaming or removing fields breaks existing content: write a migration instead of deleting the field.

## Query rules
- Write GROQ with the `defineQuery` helper so TypeGen produces result types; project only the fields you need (`{_id, title, "slug": slug.current}`).
- Pass parameters (`$slug`), never string-interpolate user input into GROQ.
- Use the CDN (`useCdn: true`) for public reads; use a token-authenticated client only on the server, and never ship tokens to the browser.
- Render Portable Text with `@portabletext/react` (or the framework's equivalent) and explicit components for custom blocks.
- Use `next-sanity`'s `sanityFetch` with tags / Live Content API for revalidation when the frontend is Next.js.

## Done
Studio builds (`npx sanity build`), typegen is up to date with no type errors, and the frontend build passes.

More: all Sanity rules · all AGENTS.md 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

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

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

Shopify Liquid theme rules

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

CursorShopify

WordPress block theme & blocks rules

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

CursorWordPress

WordPress plugin CLAUDE.md

CLAUDE.md for WordPress plugin development: prefixes, hooks, nonces and capabilities, sanitizing, escaping, and wp-env.

Claude Code (CLAUDE.md)WordPress

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.