sanity-cms
Manages Sanity CMS schemas, GROQ queries, dataset exports/imports, and Studio configuration. Use when updating Sanity schemas, running GROQ or Vision queries, exporting datasets, modifying content models, or configuring a headless CMS with Sanity.io.
git clone --depth 1 https://github.com/monkilabs/opencastle /tmp/sanity-cms && cp -r /tmp/sanity-cms/src/orchestrator/plugins/sanity ~/.claude/skills/sanity-cmsSKILL.md
<!-- ⚠️ This file is managed by OpenCastle. Edits will be overwritten on update. Customize in the .opencastle/ directory instead. -->
# Sanity CMS
Generic Sanity CMS development methodology. For project-specific configuration, schemas, plugins, document types, and GROQ examples, see [sanity-config.md](../../.opencastle/stack/sanity-config.md).
## Critical Development Rules
1. **Always check the schema before querying** — use `get_schema` to understand document types and field structures before writing GROQ queries
2. **Array vs single reference** — always verify whether a field is an array of references or a single reference; using the wrong query operator causes silent failures
3. **Local schema files are source of truth** — never edit deployed schemas directly; always change local files and redeploy
4. **Follow `defineType` and `defineField` patterns** — always use Sanity helpers for type safety and consistency
5. **Test GROQ queries in Vision** — validate queries against real data in the Vision plugin before deploying
6. **Handle draft/publish workflow** — always account for the `drafts.` prefix when querying or mutating documents
7. **Keep queries in the shared library** — queries belong in a shared queries library, never inline in components
## Quick GROQ examples
Fetch published articles with authors populated:
```groq
*[_type == "article" && defined(publishedAt)] | order(publishedAt desc) {
_id,
title,
"author": author-> { name, _id },
body
}
```
Filter by tag and return first 10:
```groq
*[_type == "article" && "tech" in tags[]] | order(_createdAt desc)[0..9] { title, slug }
```
## Example schema (executable)
```js
// schemas/article.js
import { defineType, defineField } from 'sanity'
export default defineType({
name: 'article',
title: 'Article',
type: 'document',
fields: [
defineField({ name: 'title', type: 'string', title: 'Title' }),
defineField({ name: 'slug', type: 'slug', options: { source: 'title' } }),
defineField({ name: 'author', type: 'reference', to: [{ type: 'author' }] }),
defineField({ name: 'body', type: 'array', of: [{ type: 'block' }] }),
],
})
```
## Workflow: change schema → validate → deploy
1. Update local schema files and run `sanity start` to surface schema errors locally.
2. Run Vision queries to validate GROQ results against local data: execute representative queries (see examples above).
3. Create a migration or dataset export if needed and test changes in a staging project/dataset.
- Validation checkpoint: run `sanity dataset export` and `sanity dataset import` into a temporary dataset and run queries.
4. Deploy the schema to Studio and run end-to-end site builds to confirm runtime behavior.
5. If validation fails at any step, revert schema changes locally, fix, and repeat from step 1.Creates pages/layouts, defines content collections, configures hydration directives, and wires integrations. Use when adding or modifying Astro pages, layouts, components, or content collections. Trigger terms: Astro, content collection, client:load, client:visible, astro:content
Drive real browsers via Chrome DevTools MCP: navigate pages, capture snapshots, run responsive checks, and collect console/perf traces. Use when the user mentions: 'validate UI change in Chrome', 'capture a screenshot', 'run responsive checks', or 'collect console logs'. Trigger terms: browser testing, DevTools, console logs, screenshot, responsive testing
Creates and deploys Cloudflare Workers, configures wrangler.toml bindings, sets up KV/D1/R2 storage and Durable Objects, manages Pages deployments, and implements edge function patterns. Use when building or deploying Cloudflare Workers, setting up Pages, working with KV/D1/R2 storage, configuring wrangler.toml, or deploying edge applications.
Creates Contentful content types, queries entries via GraphQL/REST, runs CLI migrations, and manages assets and locales. Use when building or modifying Contentful content models, writing queries, or migrating content.
Convex reactive database patterns, schema design, real-time queries, mutations, actions, authentication, migrations, performance optimization, and component creation. Use when designing Convex schemas, writing queries/mutations, managing the Convex backend, setting up auth, migrating data, optimizing performance, or building Convex components.
Deploys applications, databases, and services on self-hosted Coolify instances, manages environments and env vars, runs infrastructure diagnostics, and performs batch operations. Use when deploying apps to Coolify, managing Coolify servers, debugging deployment issues, setting up databases, or managing Coolify infrastructure.
Writes Cypress E2E/component tests, configures `cy.intercept()` and `cy.session()`, authors custom commands, and wires CI artifacts. Use when creating E2E specs, component tests, or CI test pipelines. Trigger terms: cypress, e2e, component test, cy.intercept, cy.session
Drizzle ORM schema definition, type-safe queries, relational queries, CRUD operations, transactions, migrations with drizzle-kit, and database setup for PostgreSQL, MySQL, and SQLite. Use when defining database schemas, writing queries or joins, managing migrations, setting up a new Drizzle project, or working with drizzle-kit.