Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change Site Theme
Sanity logo

Documentation

    • Overview
    • Platform introduction
    • Next.js quickstart
    • Nuxt.js quickstart
    • Astro quickstart
    • React Router quickstart
    • Studio quickstart
    • Build with AI
    • Content Lake
    • Functions
    • APIs and SDKs
    • Agent Actions
    • Visual Editing
    • Blueprints
    • Platform management
    • Dashboard
    • Studio
    • Canvas
    • Media Library
    • App SDK
    • Content Agent
    • HTTP API
    • CLI
    • Libraries
    • Specifications
    • Changelog
    • User guides
    • Developer guides
    • Courses and certifications
    • Join the community
    • Templates
APIs and SDKs
Overview

  • HTTP API Reference →
  • Schemas

    Introduction to schemas
    Naming things
    Attribute limit
    Studio schema reference
    Schema Deployment
    Aspects schema for Media Library

  • Command Line Interface

    Introduction
    Importing content
    Reference
    Managing backups

  • TypeScript

    Generating types

  • App SDK

    Go to App SDK docs
    Reference

  • Content Releases

    Programmatic control
    Cheat sheet

  • Asset API

    Presenting Images
    Image transformations
    Image Metadata
    International Image Interoperability Framework (IIIF) API reference
    Asset CDN
    Image URL helper
    Asset utilities

  • Sanity Connect for Shopify

    Introduction
    Custom sync handlers
    Reference

On this page

Previous

Schema Deployment

Next

Generating types

Was this page helpful?

On this page

  • The CLI configuration file
  • Minimal example
  • Advanced example
  • Uninstall Sanity CLI
APIs and SDKsLast updated January 9, 2026

Command Line Interface (CLI)

Build, deploy, init plugin boilerplate, run scripts, and wrangle datasets and webhooks, all from the command line

# Installing the CLI globally
npm install --global sanity@latest

# Alternatively
yarn global add sanity@latest
pnpm install --global sanity@latest

# Running the CLI without global installation
npx -y sanity@latest [command]

The sanity Command Line Interface (CLI) is a collection of tools for managing, developing, debugging, and deploying your Sanity Studio projects as well as running scripts to migrate or manipulate your data.

The CLI can be installed as a global dependency in your development environment, locally on a per-project basis, or in many cases, accessed entirely using npx sanity@latest [command], which bypasses the need to install the CLI globally.

Reference: Command Line Interface

Learn about all the commands available in the sanity CLI

Gotcha

Whether you choose to install the sanity CLI or use it only with npx, you will need node and npm installed on your system.

How to install node and npm?

The CLI configuration file

You can add project-specific CLI configuration by adding a file named sanity.cli.js (.ts) in your project‘s root folder.

Minimal example

// sanity.cli.js
import { defineCliConfig } from "sanity/cli";

export default defineCliConfig({
  api: {
    projectId: "<your-project-id>",
    dataset: "production",
  }
});

Advanced example

You can embed further settings in your CLI configuration file, including specifying the local server port for sanity dev, GraphQL deployments, and extending the Vite configuration.

// sanity.cli.js
import { defineCliConfig } from "sanity/cli";

export default defineCliConfig({
  api: {
    projectId: "<your-project-id>",
    dataset: "production",
  },
  server: {
    hostname: "localhost",
    port: 3333,
  },
  graphql: [{
    tag: "default",
    playground: true,
    generation: "gen3",
    nonNullDocumentFields: false,
  }],
  vite: (config) => config,
});

Uninstall Sanity CLI

If you prefer to invoke the CLI with npx or similar, or you no longer want Sanity CLI installed globally, you can uninstall it using the preferred method for your package manager.

# Remove the CLI globally
npm uninstall --global sanity

# Alternatively
yarn global remove sanity
pnpm remove --global sanity

# Installing the CLI globally
npm install --global sanity@latest

# Alternatively
yarn global add sanity@latest
pnpm install --global sanity@latest

# Running the CLI without global installation
npx -y sanity@latest [command]
// sanity.cli.js
import { defineCliConfig } from "sanity/cli";

export default defineCliConfig({
  api: {
    projectId: "<your-project-id>",
    dataset: "production",
  }
});
// sanity.cli.js
import { defineCliConfig } from "sanity/cli";

export default defineCliConfig({
  api: {
    projectId: "<your-project-id>",
    dataset: "production",
  },
  server: {
    hostname: "localhost",
    port: 3333,
  },
  graphql: [{
    tag: "default",
    playground: true,
    generation: "gen3",
    nonNullDocumentFields: false,
  }],
  vite: (config) => config,
});
# Remove the CLI globally
npm uninstall --global sanity

# Alternatively
yarn global remove sanity
pnpm remove --global sanity