Command line interface
Build, deploy, init plugin boilerplate and wrangle datasets and webhooks, all from the command line
The Sanity CLI tool can be installed through npm: npm install -g @sanity/cli
. Once installed, you can bootstrap a new project using sanity init
.
usage: sanity [--default] [-v|--version] [-d|--debug] [-h|--help] <command> [<args>] Commands: build Builds the current Sanity configuration to a static bundle configcheck Checks if the required configuration files for plugins exists and are up to date cors Interact with CORS-entries for your project dataset Interact with datasets in your project debug Gathers information on Sanity environment deploy Deploys a statically built Sanity studio docs Opens the Sanity documentation documents Interact with documents in your project exec Runs a script in Sanity context graphql Interact with GraphQL APIs help Displays help information about Sanity hook Interact with hooks in your project init Initialize a new Sanity project or plugin install Installs a Sanity plugin to the current Sanity configuration login Authenticates against the Sanity.io API logout Logs out of the Sanity.io session manage Opens the Sanity project management UI projects Interact with projects connected to your logged in user start Starts a web server for the Content Studio undeploy Removes the deployed studio from <hostname>.sanity.studio uninstall Removes a Sanity plugin from the current Sanity configuration upgrade Upgrades all (or some) Sanity modules to their latest versions users Manage users of your project versions Shows the installed versions of Sanity CLI and core components See 'sanity help <command>' for specific information on a subcommand.
Gotcha
Some of the commands listed above only apply when the sanity
command is being run from a Sanity project folder. If sanity help
is missing any of these commands, make sure your current working directory is the root of your Sanity project.
Not to be confused with sanity debug
, which returns information about your Sanity environment, you can use the DEBUG
environment variable with your sanity
commands to get more verbose results and troubleshoot potential issues.
For full debugger results, use a wildcard on its own (DEBUG=* sanity <command>
). For more targeted results, you can specify a namespace followed by a wildcard (DEBUG=sanity* sanity <command>
or DEBUG=sanity:cli* sanity <command>
).
Example
Least verbosesanity dataset import production.tar.gz dev
More verbose, returning all debuggers in the sanity
namespaceDEBUG=sanity* sanity dataset import production.tar.gz dev
Most verbose, returning all debuggersDEBUG=* sanity dataset import production.tar.gz dev
Results can also be excluded by using a -
prefix. DEBUG=sanity*,-sanity:export* sanity dataset export production production.tar.gz
would return all debuggers in the sanity
namespace except for sanity:export
debuggers (e.g., sanity:cli
and sanity:client
) during an export of the production
dataset.