sanity

Implements Sanity CMS conventions for GROQ queries, typegen, schema design, and Astro content rendering.

Updated Sep 6, 2026
One-click install
npx skills add https://github.com/malikkotb/shellpluscore --skill sanity-malikkotb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sanity
Source: https://github.com/malikkotb/shellpluscore/tree/main/.agents/skills/sanity
Command: npx skills add https://github.com/malikkotb/shellpluscore --skill sanity-malikkotb

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Keeping GROQ queries, generated TypeScript types, the Sanity schema, and Astro renderers consistent is error-prone: queries balloon past the 300 KB API limit, generated files get hand-edited, React leaks from the Studio into public pages, and related fields sprawl as prefix-named siblings. This Skill encodes the end-to-end conventions so every change follows the same query-to-type-to-renderer pipeline. ## Core Features & Use Cases - Query and typegen workflow: Define GROQ with defineQuery in src/sanity/queries.ts, regenerate types with npm run sanity:typegen, and fetch through loadQuery<ResultType> with draft-mode and stega handling built in. - Schema and Studio conventions: Field factories, field grouping into wrapper objects, singleton IDs from sanity/constants.ts, and React strictly confined to the root sanity/ Studio. - Custom GROQ functions: Rules for hoisting repeated projections into frag:: namespaced functions to stay under the query size limit, including typegen evaluation pitfalls. - Use Case: When adding a new page-builder section, you create the schema with field factories, write the query reusing shared fragments, run typegen, render through SanityMedia/SanityRichText, and verify with npm run check. ## Quick Start Ask the AI to add a new GROQ query for a page type following the Sanity conventions, regenerate the types, and render it with the existing Astro media components.

Frequently Asked Questions about sanity

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new GROQ query in a Sanity and Astro project?

Define the query with defineQuery in src/sanity/queries.ts using a PascalCase name ending in Q, composed from shared fragments. Run npm run sanity:typegen, then fetch with loadQuery using the generated result type like PageQResult.

How do I fix a Sanity query exceeding the 300 KB size limit?

Convert repeated projections into custom GROQ functions namespaced with frag::, since inlined fragments multiply textually when nested. A function wins from the second copy onward for projections above roughly 60 bytes; measure real copies in the expanded query before deciding.

Can I use React components in Astro pages that render Sanity content?

No. React is allowed only inside the root sanity/ Studio directory. Public pages render content through .astro components like SanityMedia and SanityRichText, and Studio modules must never be imported into pages or src/sanity/ renderers.

Why is my query result type missing from sanity/types.ts after typegen?

Typegen silently drops queries it cannot statically evaluate, such as factories returning objects or methods called on imported objects. Use standalone exported functions returning strings, and check the query count in the typegen output after changes.

How does draft mode work with Sanity and Astro?

Draft mode is per-request, driven by the preview perspective cookie parsed inside loadQuery. Stega encoding for visual editing overlays only activates when that cookie is present, so it never reaches published HTML.

When should Sanity fields be grouped into an object field?

Group fields when two or more describe the same concept, placing them inside one object field named for that concept instead of prefix-named siblings. The rule fires on the second related field, and regrouping published content requires a data migration.