sanity dev command starts a local development server for your Sanity Studio with live reloading and hot module replacement. This is the primary command you’ll use during development.
Basic Usage
http://localhost:3333 by default.
In the Sanity monorepo, the dev studio runs at
http://localhost:3333 and requires browser authentication on first visit.Options
--port <port>- TCP port to start server on (default:3333)--host <host>- The local network interface at which to listen (default:"127.0.0.1")
Examples
Development Server Features
Hot Module Replacement (HMR)
The dev server includes HMR for instant updates:- Schema changes reload automatically
- Component updates apply without full page refresh
- Configuration changes trigger rebuilds
Vite-Powered
Sanity Studio uses Vite for fast, modern development:- Lightning-fast cold starts
- Instant HMR
- Optimized dependency pre-bundling
- Native ES modules
Studio Configuration
The dev server reads fromsanity.config.ts:
sanity.config.ts
Network Access
By default, the server only listens on localhost (127.0.0.1). To allow access from other devices on your network:
CORS Configuration
If you access the Studio from a different hostname, you may need to add it to the CORS allow list:- Go to manage.sanity.io
- Select your project
- Navigate to API → CORS Origins
- Add your development URL (e.g.,
http://192.168.1.100:3333)
Authentication
The dev server requires authentication to access Sanity APIs:- Open the Studio URL in your browser
- You’ll be prompted to log in on first visit
- Session persists in browser for subsequent visits
Environment Variables
The dev server loads environment variables from:.env- All environments.env.local- Local overrides (gitignored).env.development- Development only
.env.local:
.env.local
Environment variables must be prefixed with
SANITY_STUDIO_ to be included in the browser bundle.Custom Vite Configuration
Extend Vite configuration insanity.config.ts:
sanity.config.ts
Troubleshooting
Port Already in Use
If port 3333 is already in use:CORS Errors
If you see CORS errors in the browser console:- Check your project’s CORS settings at manage.sanity.io
- Add your development URL to the allow list
- Include
http://localhost:3333for local development
Authentication Issues
If authentication fails:Schema Errors
If the server crashes on schema errors:- Check the terminal output for error details
- Fix schema validation issues in
schemas/ - The server will automatically restart after saving
Performance Tips
Dependency Pre-bundling
Vite pre-bundles dependencies on first run. This may take a moment initially, but subsequent starts are instant.Large Projects
For large projects with many schemas:sanity.config.ts
Memory Issues
If you encounter memory issues with large projects:Development Workflow
Typical development workflow:- Start the dev server:
sanity dev - Open
http://localhost:3333in your browser - Edit schemas, components, or configuration
- Changes appear instantly via HMR
- Test in the Studio UI
- Commit your changes
Monorepo Development
When working in the Sanity monorepo:The dev studio in the monorepo requires Sanity user authentication in the browser. It’s a Vite application that communicates with Sanity API endpoints.
Next Steps
Build for Production
Create production-ready static bundles
Deploy Studio
Deploy your Studio to Sanity hosting