CLI reference
Schema CLI command reference
List, validate, extract, and deploy schema.
Available commands
npx sanity schema --help
pnpm dlx sanity schema --help
yarn dlx sanity schema --help
bunx sanity schema --help
Commands
delete
USAGE
$ sanity schema delete
FLAGS
-p, --project-id=<PROJECT-ID> Project ID to delete schema from (overrides CLI configuration)
-d, --dataset=<DATASET> Delete schemas from a specific dataset
--ids=<IDS> Comma-separated list of schema ids to delete
--verbose Enable verbose logging
DESCRIPTION
Delete schema documents by id
EXAMPLES
Delete a single schema
sanity schema delete --ids sanity.workspace.schema.workspaceName
Delete multiple schemas
sanity schema delete --ids sanity.workspace.schema.workspaceName,prefix.sanity.workspace.schema.otherWorkspacedeploy
USAGE
$ sanity schema deploy
FLAGS
--extract-manifest Disables manifest generation - the command will fail if no manifest exists
--manifest-dir=<MANIFEST-DIR> Directory containing manifest file
--tag=<TAG> Add a tag suffix to the schema id
--verbose Print detailed information during deployment
--workspace=<WORKSPACE> The name of the workspace to deploy a schema for
DESCRIPTION
Deploy schema documents into workspace datasets.
**Note**: This command is experimental and subject to change.
This operation (re-)generates a manifest file describing the sanity config workspace by default.
To re-use an existing manifest file, use --no-extract-manifest.
EXAMPLES
Deploy all workspace schemas
sanity schema deploy
Deploy the schema for only the workspace "default"
sanity schema deploy --workspace defaultextract
USAGE
$ sanity schema extract
FLAGS
--enforce-required-fields Makes the schema generated treat fields marked as required as non-optional
--format=<FORMAT> Format the schema as GROQ type nodes. Only available format at the moment.
--path=<PATH> Optional path to specify destination of the schema file
--watch Enable watch mode to re-extract schema on file changes
--watch-patterns=<WATCH-PATTERNS>Additional glob pattern(s) to watch (can be specified multiple times)
--workspace=<WORKSPACE> The name of the workspace to generate a schema for
DESCRIPTION
Extracts a JSON representation of a Sanity schema within a Studio context.
**Note**: This command is experimental and subject to change.
EXAMPLES
Extracts schema types in a Sanity project with more than one workspace
sanity schema extract --workspace default
Watch mode - re-extract on changes
sanity schema extract --watch
Watch with custom glob patterns
sanity schema extract --watch --watch-patterns "lib/**/*.ts"list
USAGE
$ sanity schema list
FLAGS
--id=<ID> Fetch a single schema by id
--json Get schema as json
DESCRIPTION
Lists all schemas in the current dataset.
**Note**: This command is experimental and subject to change.
This operation (re-)generates a manifest file describing the sanity config workspace by default.
To re-use an existing manifest file, use --no-extract-manifest.
EXAMPLES
List all schemas found in any workspace dataset in a table
sanity schema list
Get a schema for a given id
sanity schema list --id _.schemas.workspaceName
Get stored schemas as pretty-printed json-array
sanity schema list --json
Get singular stored schema as pretty-printed json-object
sanity schema list --json --id _.schemas.workspaceNamevalidate
USAGE
$ sanity schema validate
FLAGS
--debug-metafile-path=<DEBUG-METAFILE-PATH>Optional path where a metafile will be written for build analysis. Only written on successful validation. Can be analyzed at https://esbuild.github.io/analyze/
--format=<FORMAT> The output format used to print schema errors and warnings
--level=<LEVEL> The minimum level reported out
--workspace=<WORKSPACE> The name of the workspace to use when validating all schema types
DESCRIPTION
Validates all schema types specified in a workspace
EXAMPLES
Validates all schema types in a Sanity project with more than one workspace
sanity schema validate --workspace default
Save the results of the report into a file
sanity schema validate > report.txt
Report out only errors
sanity schema validate --level error
Generate a report which can be analyzed with https://esbuild.github.io/analyze/
sanity schema validate --debug-metafile-path metafile.json