Init Sanity project from CLI without creating files using custom template

13 replies
Last updated: Sep 27, 2021
Hi there! Is there the option to init a new project from the cli without creating all the files? Ideally it would even work with a custom template created using sanity-template....
AI Update

Yes! There are actually a couple of options for initializing a Sanity project without creating all the Studio files:

The --bare Flag

As of Sanity CLI v3.9.0 (April 2023), the sanity init command supports a --bare flag that does exactly what you're looking for:

sanity init --bare

or with npm create:

npm create sanity@latest -- --bare

What --bare does:

  • Skips the installation of a Sanity Studio
  • Takes you through the project and dataset creation process
  • Prints the project ID and dataset names to the console
  • Perfect when you want to integrate with an existing application or have your own Studio code ready

The --env Flag

The same update also introduced the --env flag, which is useful when setting up environment variables:

sanity init --env

This flag:

  • Detects the framework used in your current directory
  • Creates a .env file with the correct prefix for environment variables
  • You can specify a custom path like --env .env.local.example

Using with Custom Templates

While the documentation doesn't explicitly cover using --bare with custom templates created via sanity-template, you can combine these approaches:

  1. Use --bare to create just the project/dataset
  2. Then use your custom template or existing Studio code
  3. Configure it with the project ID that was printed to the console

The sanity projects create Command

For even more control, you can use the sanity projects create command directly to create just a project without any Studio files at all, then set up your Studio or application separately.

These flags are particularly useful when you're integrating Sanity into an existing application, working with custom templates, or when you only need the Content Lake capabilities without a full Studio setup.

Show original thread
13 replies
Hi Rachael, thanks for your answer. I'm currently trying to create a template and would like to create new projects from it through the cli...
Got it. You have a few options for using a template, but it sounds like this section on developing a template locally is what you need. There's more info on the
sanity-template
CLI in its repo .
Thanks. I checked the
sanity-template
repo... Well - not all the commands there work for me, but I opened an issue in that regards over at github.
Thanks. I checked the
sanity-template
repo... Well - not all the commands there work for me, but I opened an issue in that regards over at github.
However this does not solve my issue of creating a new sanity project from the cli
In other words: in my agency we have created a sanity/gatsby boilerplate. I'm currently trying to move this to a sanity template. My ultimate goal would be to replicate the functionality of sanity.io/create for our own starter but from the cli. So any employee could start a new project with a configuration and a simple command
In other words: in my agency we have created a sanity/gatsby boilerplate. I'm currently trying to move this to a sanity template. My ultimate goal would be to replicate the functionality of sanity.io/create for our own starter but from the cli. So any employee could start a new project with a configuration and a simple command
I'd suggest setting up a github repo of the studio for your team to clone, then initializing a new project there if you're looking to bypass using sanity.io/create .
I don't necessarily need to bypass sanity.io/create however how can I use it with my own custom template?
and how would I be creating a new project from a github repo?
thanks!
Actually, reading through this guide, you can create a reusable 1-click template without having to publicly share it on /create! I was wrong! If you follow the steps there, you'll end up with a link that you can share with your team. The drawbacks here: you would have to create on the project in the browser via that link, then, once the project has been created, you would need to
git clone
the repo it gives you. You wouldn't be able to just run a command via the CLI, unfortunately. Sorry for the confusion there 😅
Thanks rachael, that sounds like precisely what I was looking for! Will look into it

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.

Was this answer helpful?