Command Line Interface (CLI)

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

npx sanity@latest --help

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.

Requirements

Whether you install the CLI or run it with npx, it requires:

  • Node.js 22.12 or later. On an older version, the CLI exits with ERROR: Node.js version >=22.12 required.
  • A package manager: npm, Yarn, or pnpm.

Network access

The CLI connects to Sanity over HTTPS on port 443. If your network or CI environment restricts outbound traffic, allowlist these domains:

  • api.sanity.io: The global API. Account and project management commands use it, including login, deploy, undeploy, schemas deploy, cors, tokens, and projects. CLI telemetry also goes to this domain.
  • *.api.sanity.io: Your project's API, at .api.sanity.io. Commands that work with content use it, including datasets, documents, graphql deploy, and migrations run.
  • www.sanity.io: Completes the browser sign-in for sanity login.
  • sanity-cdn.com: Checks module versions during build, deploy, and dev when auto-updates are turned on.
  • Your npm registry (registry.npmjs.org by default): Checks for CLI updates and installs dependencies during init.

A *.api.sanity.io wildcard doesn't match the bare api.sanity.io domain, so allowlist both. The CLI has no setting to send global API requests to your project's domain instead.

The CLI uses the proxy set in the HTTPS_PROXY, HTTP_PROXY, and NO_PROXY environment variables. For the domains Sanity Studio needs in the browser, see System requirements.

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: "",
    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: "",
    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?

sanity.ioAll Systems Operational© Sanity 2026
Change site theme