Initialize Sanity and install the migration toolkit
From the root of your project:
pnpm create sanity@latestFollow the prompts. Choose a new project, create a staging dataset, and select TypeScript. When asked for the project output path, type ./sanity. The CLI defaults to a folder named after your project, but you want it at /sanity/ relative to your migration root, and the ./ prefix is required — typing sanity alone will fail. This scaffolds /sanity/ with a Studio configuration, a schemaTypes/ folder, and a dev server.
Once it completes, fill in the Sanity credentials in your .env file. Your project ID shows up in the terminal output, and also at sanity.io/manage. For the token, go to sanity.io/manage → your project → API → Tokens and create one with Editor permissions:
# .env — add these after running pnpm create sanity@latestSANITY_PROJECT_ID=your_project_idSANITY_DATASET=stagingSANITY_TOKEN=your_editor_tokenThe Sanity CLI scaffolds the project but doesn't always create the dataset you named — type staging but the project only has production, and the first import fails with "dataset not found." Confirm it before continuing:
npx sanity datasets list --project <your_project_id>If staging isn't in the list, create it:
npx sanity dataset create stagingFrom the project root (not inside /sanity/):
pnpm dlx skills add sanity-io/agent-toolkit --skill sanity-migrationThis gives AI agents in your project access to Sanity's mutation API, GROQ querying, and asset upload, the tools the migration scripts use.
cd sanity && pnpm devOpen localhost:3333. The sidebar is empty at this point since you haven't added any schemas yet and that's expected. What you're confirming here is that Studio loads without errors. Fix any TypeScript or compilation error before moving on.
Next, you’ll design your content model using the API data you just fetched.