APIs and SDKs

Command Line Interface (CLI)

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

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.

To make sure you always have the latest version we suggest running entirely using npx sanity@latest [command], which bypasses the need to install the CLI globally. Additional package managers like pnpm are also supported.

You'll need Node.js 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: "YOUR_DATASET",
  }
});

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: "YOUR_DATASET",
  },
  server: {
    hostname: "localhost",
    port: 3333,
  },
  graphql: [{
    tag: "default",
    playground: true,
    generation: "gen3",
    nonNullDocumentFields: false,
  }],
  vite: (config) => config,
});

Uninstall Sanity CLI

If you previously installed sanity globally and experience unexpected version collisions, you can uninstall it with the following commands:

# Remove the CLI globally
npm uninstall --global sanity

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

Was this page helpful?