# `npx @sanity/cli blueprints init`

Initialize a local Blueprint and connect it to a new or existing remote Stack. Use this at the start of a Blueprint project or to configure an existing manifest.

## Before running

- Authenticate with Sanity.
- Choose the target directory and whether the Stack belongs to a project or an organization.
- Check the target directory and its parents for an existing manifest (`sanity.blueprint` or `blueprint`, with `.json`, `.js`, `.mjs`, or `.ts`). When one is found, the command configures it instead of creating another manifest.
- Confirm whether to create a Stack or attach an existing one.

## Run

Pass `.` to initialize the current directory without the directory confirmation prompt:

```sh
npx @sanity/cli blueprints init . --project-id PROJECT_ID --stack-name development
```

To connect to an existing Stack, provide its ID and scope:

```sh
npx @sanity/cli blueprints init . --project-id PROJECT_ID --stack-id STACK_ID
```

Use `--organization-id` instead of `--project-id` for an organization-scoped Stack. `--stack-id` and `--stack-name` are mutually exclusive, and either one requires an explicit project or organization scope.

For a new local Blueprint, choose the manifest format with `--blueprint-type json|js|ts`. JavaScript and TypeScript setups add `@sanity/blueprints` to `devDependencies`, writing a `package.json` with `"type": "module"` if the directory has none. A `js` manifest is written as `sanity.blueprint.mjs` when a `package.json` already exists there without `"type": "module"`. The command also writes `.sanity/blueprint.config.json` and a `.gitignore` covering `node_modules`, `.env`, and function build output; the `.sanity` config itself is not ignored. `--example NAME` takes a different path: it scaffolds a published example into the named directory (or `./NAME` when none is given), creates a project-scoped Stack called `example-NAME`, and cannot be combined with `--blueprint-type`, `--stack-id`, or `--stack-name`.

## Avoid the prompts

A fresh initialization is interactive unless every decision is supplied up front. Pass all four:

```sh
npx @sanity/cli blueprints init . --project-id PROJECT_ID --stack-name development --blueprint-type ts
```

Omitting `--blueprint-type` prompts for the manifest format. Omitting both `--stack-id` and `--stack-name` prompts for Stack selection. Omitting the scope starts a full organization and project wizard. Omitting the directory prompts to confirm the current one.

## Verify

Inspect the created files, then preview the first deployment:

```sh
npx @sanity/cli blueprints plan --json
```

Do not deploy until the plan targets the expected Stack and contains the expected resource changes.
