sanity init command creates a new Sanity Studio project or initializes a project in an existing directory. It scaffolds the project structure, sets up configuration files, and optionally creates a new Sanity project.
Basic Usage
- Authentication (if not logged in)
- Project selection or creation
- Dataset configuration
- Template selection
- Output path specification
- Package manager choice
Recommended: Create Sanity
The recommended way to initialize a new project is using the create command:Options
Project Configuration
--project <projectId>,--project-id <projectId>- Project ID to use for the studio--organization <organizationId>- Organization ID to use for the project--create-project <name>- Create a new project with the given name--project-plan <name>- Select a plan for a new project--coupon <name>- Apply a coupon for a new project (cannot be used with--project-plan)
Dataset Configuration
--dataset <dataset>- Dataset name for the studio--dataset-default- Set up a project with a public dataset named “production”--visibility <mode>- Visibility mode for dataset (publicorprivate)
Template & Output
--template <template>- Project template to use (default: “clean”)--output-path <path>- Path to write studio project to--overwrite-files- Overwrite existing files (default: false)
Build Configuration
--no-typescript- Do not use TypeScript for template files--package-manager <name>- Specify package manager (npm,pnpm,yarn,bun)--auto-updates- Enable/disable auto updates of studio versions (default: true)
Authentication & Mode
--provider <provider>- Login provider to use-y,--yes- Unattended mode, accepting defaults and using only flags--bare- Skip Studio initialization, only print project ID and dataset name to stdout--env <filename>- Write environment variables to file (default: “.env”)--no-mcp- Skip AI editor integration (MCP) setup
Next.js Specific
When initializing in a Next.js project:--nextjs-add-config-files- Add config files to Next.js project (default: true)--nextjs-embed-studio- Embed Studio in Next.js application (default: true)--nextjs-append-env- Append project ID and dataset to .env file (default: true)
Examples
Templates
Sanity provides several starter templates:clean- Minimal clean slate (default)moviedb- Movie database exampleblog- Blog with posts and authorsshopify- E-commerce with Shopify integrationpodcast- Podcast management
What Gets Created
Runningsanity init creates:
Configuration Files
sanity.config.ts
Defines your Studio configuration:sanity.config.ts
sanity.cli.ts
Defines CLI-specific settings:sanity.cli.ts
Unattended Mode
For CI/CD pipelines or scripts, use unattended mode:Framework Detection
The CLI automatically detects frameworks in your directory:- Next.js
- Remix
- Astro
- SvelteKit
- Nuxt
For Next.js projects, the CLI offers to embed the Studio directly in your application.
Troubleshooting
Authentication Required
If not logged in, run:Overwriting Existing Files
To overwrite existing files without prompts:Custom Package Manager
Specify your preferred package manager:Next Steps
After initialization:- Navigate to your project directory
- Start the development server:
sanity dev - Define your schema in
schemas/ - Customize
sanity.config.ts
Development Server
Learn how to run the local development server