Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

Sanity CLI

$ sanity Official Med Risk
Sanity · Workspace & SaaS · MIT · macos / linux / windows

Sanity CLI (sanity) manages Sanity Content Lake datasets, executes GROQ queries from the terminal, validates schemas, and exports/imports dataset backups. It relies heavily on a local project directory with sanity.config.ts and SANITY_AUTH_TOKEN for headless runs.

FCRS-1.0 Score
80 /100
Good
Medium Confidence
Zero-Friction Install
npm install -g @sanity/cli
CLI vs MCP Decision Hybrid (CLI + MCP)

Use sanity CLI for dataset export/import, schema deploy, and local GROQ testing; use Sanity MCP when working remotely without a local Sanity Studio project checkout.

Agent-Readiness Checklist

✓ JSON Output
— Field Filtering
✓ Non-Interactive
— Dry-Run
— Read-Only Mode
— NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 19 / 25

sanity documents query emits clean JSON, though project-scoped commands require running inside a Sanity project directory.

  • sanity documents query returns JSON arrays directly
  • Most dataset commands require sanity.config.ts in the working directory
Trust & Safety 19 / 25

Dataset selection (-d) and read-only SANITY_AUTH_TOKEN scopes protect production content, though dataset delete is destructive.

  • Supports scoped API tokens via SANITY_AUTH_TOKEN
  • sanity dataset import --replace can overwrite documents if misused
Setup & Portability 13 / 15

Standard npm package usable globally or via npx sanity@latest across macOS, Linux, and Windows.

  • Published as @sanity/cli and bundled with sanity
Utility & Efficiency 12 / 15

Great for GROQ debugging, schema extraction, and dataset backups.

  • Native GROQ execution and schema deploy workflows
Maintenance & Lineage 9 / 10

Official Sanity monorepo (sanity-io/sanity) maintained under MIT.

  • Official Sanity GitHub organization
Docs & Verifiability 8 / 10

Documented in Sanity's official CLI reference and --help output.

  • Official docs at sanity.io/docs/cli-reference

Security, Auth & Guardrails

Auth Modes
OAuth Browser Env API Key Config File
Credential Storage

Stores auth tokens in ~/.config/sanity/config.json or reads SANITY_AUTH_TOKEN from the environment.

Side Effects
Read-Only Local Write Remote Write Destructive
Cost & Quotas

CLI is free (MIT); Sanity includes a free tier with usage-based plans for higher quotas.

Copyable Guardrail for CLAUDE.md / AGENTS.md
# Sanity CLI Agent Rules
- Always target non-production datasets with `-d staging` (or `--dataset=staging`) when querying or testing mutations.
- Export a backup (`sanity dataset export`) before running migrations or `sanity dataset import --replace`.
- Never run `sanity dataset delete` or `sanity documents delete` without explicit human approval.

Agent-Ready Command Recipes

Safe Read-Only Queries

List project datasets
sanity dataset list

Lists all datasets and dataset aliases configured for the current Sanity project.

Run a read-only GROQ query
sanity documents query "*[_type == 'post'][0...5]{_id, title}" -d staging

Executes a bounded GROQ query against the staging dataset and outputs JSON.

Controlled Writes & Previews

Export a dataset snapshot locally
sanity dataset export staging ./staging-backup.tar.gz

Downloads a full local archive of the staging dataset without mutating remote documents.

Strengths for Agents

  • + sanity documents query runs GROQ directly from the shell and returns clean JSON.
  • + sanity dataset export makes pre-migration snapshots effortless.
  • + Supports headless CI authentication via SANITY_AUTH_TOKEN.

Caveats & Pitfalls

  • ! Most commands fail outside a directory containing sanity.config.ts / sanity.cli.ts.
  • ! Missing universal --json flag on administrative commands like dataset list.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI