How to reconnect VS Code to existing Sanity dataset without wiping data?

23 replies
Last updated: Jan 28, 2026
Hi just re 'setup' question. I have a website, using sanity to store some images and data. I connect to sanity through vscode. I connect to sanity dataset production for example. My site and data are all finished.
Now the problem. I have backups of my visual studio project. Though my pc has completely died. Motherboard issues so I am starting my new build i was planning. When I reinstall Vs code and use my backup vscode files......how do I connect to my existing sanity dataset in vscode without wiping that dataset? I think its called 'production' or 'projecttest'.
AI Update

Good news - you won't wipe your dataset! Your Sanity content lives in the cloud, not in your local VS Code files. Your backup project files just contain the connection configuration to access that data, so you're safe to restore them on your new machine.

Here's what you need to do:

Restore Your Project

  1. Install Node.js and npm on your new machine (if not already installed)

  2. Restore your VS Code project files from your backup to your new machine

  3. Install dependencies - Navigate to your project folder and run:

    npm install
  4. Check your configuration - Your project should have a sanity.cli.js (or sanity.cli.ts) file in the root that contains your project ID and dataset name:

    export default defineCliConfig({
      api: {
        projectId: 'your-project-id',
        dataset: 'production'  // or 'projecttest'
      }
    })
  5. Authenticate - Run this command to log in to your Sanity account:

    npx sanity login

    This will open a browser window for authentication and store your credentials locally.

  6. Start your Studio (if you're running Sanity Studio locally):

    npm run dev

That's it! Your project will connect to your existing dataset without any issues. The sanity login command just authenticates your machine - it doesn't affect your content at all.

If Configuration Files Are Missing

If your backup doesn't include the sanity.cli.js file, you can recreate it manually. You'll need:

  • Your Project ID (find it in manage.sanity.io)
  • Your dataset name (likely "production" or "projecttest" as you mentioned)

Just create the configuration file with those values, and you'll be connected to your existing data.

Your content is completely safe in Sanity's cloud - these configuration files are just the "key" to access it, not the data itself!

Show original thread
23 replies

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?