Back to Skills

sanity-groq

verified

Expert assistance for writing, optimizing, and debugging GROQ queries. Use when writing queries or debugging performance.

View on GitHub

Marketplace

sanity-agent-toolkit

sanity-io/agent-toolkit

Plugin

sanity-plugin

Repository
Verified Org

sanity-io/agent-toolkit
55stars

sanity-plugin/skills/sanity-groq/SKILL.md

Last Verified

January 14, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/sanity-io/agent-toolkit/blob/main/sanity-plugin/skills/sanity-groq/SKILL.md -a claude-code --skill sanity-groq

Installation paths:

Claude
.claude/skills/sanity-groq/
Powered by add-skill CLI

Instructions

# GROQ Query Assistant

This skill helps users write GROQ queries that are efficient, correct, and compatible with Sanity TypeGen.

## Procedure

1.  **Analyze Request**
    *   Is the user asking for a new query?
    *   Is the user debugging an existing query?
    *   Is the user asking about performance?

2.  **Drafting Queries**
    *   **Rule:** Always wrap in `defineQuery` (or `groq` tag).
    *   **Rule:** Always use the `/* groq */` comment for syntax highlighting.
    *   **Rule:** Always use Projections `{ ... }`. Never return `*` (naked projection).
    *   **Example:**
        ```typescript
        const QUERY = defineQuery(/* groq */ `*[_type == "post" && slug.current == $slug][0]{ title, body }`);
        ```

3.  **Optimization Checks**
    *   **Scan:** Look for `*[_type == "..."]` without `{}`. -> **Warn:** "Fetch only what you need."
    *   **Scan:** Look for string interpolation (`slug == "${slug}"`). -> **Warn:** "Use parameters (`$slug`)."
    *   **Scan:** Look for deep expansion (`...`). -> **Warn:** "Be explicit to reduce payload size."

4.  **TypeGen Integration**
    *   After writing the query, remind the user to run `npm run typegen` (or equivalent).
    *   Show how to import the generated type: `import { type QUERYResult } from './sanity.types'`.

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
1191 chars