Command Line Interface (CLI)
Build, deploy, init plugin boilerplate, run scripts, and wrangle datasets and webhooks, all from the command line
npx sanity@latest --helppnpm dlx sanity@latest --helpyarn dlx sanity@latest --helpbunx sanity@latest --helpThe 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, includinglogin,deploy,undeploy,schemas deploy,cors,tokens, andprojects. CLI telemetry also goes to this domain.*.api.sanity.io: Your project's API, at<your-project-id>.api.sanity.io. Commands that work with content use it, includingdatasets,documents,graphql deploy, andmigrations run.www.sanity.io: Completes the browser sign-in forsanity login.sanity-cdn.com: Checks module versions duringbuild,deploy, anddevwhen auto-updates are turned on.- Your npm registry (
registry.npmjs.orgby default): Checks for CLI updates and installs dependencies duringinit.
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: "<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 sanityWas this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?