> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# Command Line Interface (CLI)

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

**npm**

```shell
npx sanity@latest --help
```

**pnpm**

```shell
pnpm dlx sanity@latest --help
```

**yarn**

```shell
yarn dlx sanity@latest --help
```

**bun**

```shell
bunx 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.

[Reference: Command Line Interface](https://www.sanity.io/docs/cli-reference/cli-config)
Learn about all the commands available in the sanity CLI

## Requirements

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

- [Node.js](https://nodejs.org/) 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 `YOUR_PROJECT_ID.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](https://www.sanity.io/docs/studio/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

```javascript
// 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.

```javascript
// 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:

```sh
# Remove the CLI globally
npm uninstall --global sanity

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

