Different ways to initialize a Sanity project: npm create vs sanity init
I'm currently working through the Sanity Documentation to get Sanity up and running but I've discovered several ways to do this and I'm finding it confusing. For instance, in the section
Getting Started, the following commands are used:
npm create sanity@latest -- --template clean --create-project "Sanity Project" --dataset productionnpm run dev
then in the section
Setting up with Sanity, these commands:
npm install -g @sanity/cli
sanity init
sanity start
and the video tutorial:
npm create sanity@latest
I was wondering if anyone could help me to gain some clarity with this and explain the differences between the approaches?
Please forgive me if this question seems really simple
😳
Thanks!
These are mostly the same tool in different forms. npm create sanity@latest and npx sanity@latest init run the same project initializer. Adding flags just answers the setup questions ahead of time. The npm install -g @sanity/cli → sanity init → sanity start sequence is the old Studio v2 setup, which is deprecated, so don't follow it for a new project.
1. Create a new Studio (interactive)
You need Node.js v22.12 or later (installation docs).
npm create sanity@latestThe CLI asks you to sign in or create an account, then to pick a Studio template, TypeScript and a package manager. It then creates a folder and sets up the Studio config. Start it with:
cd your-studio-folder
npm run devThen open http://localhost:3333 and log in with the same provider you used for the CLI (quickstart).
2. The same command, with flags
Flags skip the prompts. The -- passes them through npm to the Sanity initializer:
npm create sanity@latest -- --template clean --dataset production --typescript --output-path my-studio--template clean: a minimal Studio with no schema. This is the default. Other options aremoviedbandpage-builder.--dataset production: the dataset name.--typescript: turns on TypeScript.--output-path: where the Studio is written.--project-name "Sanity Project": creates a new project with that name. The currentsanity initreference lists--project-namefor this, not--create-project, so use--project-name.-yruns unattended and accepts the defaults. For a fully unattended new project,--organization=<id>is also required.
Run npx sanity@latest help init to see every flag.
3. Adding Sanity to an existing project
Inside an existing app, such as a Next.js app, run:
npx sanity@latest initThis is the same initializer. In a supported framework, it sets up Sanity in the current directory instead of creating a new folder (installation docs).
4. About the global install and sanity start
The current docs recommend
npx sanity@latest <command>, which always runs the latest CLI, instead of a global install. If an older global install causes version clashes, remove it (CLI docs):npm uninstall --global sanityIf you installed the old
@sanity/clipackage globally, uninstall that package the same way.sanity startwas the v2 dev command. In current Studios, usenpm run devornpx sanity dev. This starts a Vite dev server on port 3333 with hot reloading (dev reference, local development). Usenpm run buildandnpx sanity previewto build and preview a production build.
Which to use
- New Studio:
npm create sanity@latest, with or without flags. - Existing app:
npx sanity@latest init. - Running it:
npm run dev.
If a tutorial tells you to install @sanity/cli globally or run sanity start, it was written for v2.
Show original thread3 replies
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.