How can I delete a document in sanity studio?
There are a few ways to delete documents in Sanity Studio depending on your needs:
Deleting in Sanity Studio (UI)
The most straightforward method is through the Studio interface:
- Open the document you want to delete in Sanity Studio
- Look for the three-dot menu (⋯) or arrow icon to the right of the Publish button in the top-right corner
- Click it and select "Delete" from the dropdown menu
- Confirm the deletion when prompted
This is part of the document actions system in Sanity Studio. The delete action is available by default for all documents unless it's been explicitly disabled through custom document actions configuration.
Deleting via Sanity CLI
If you need to delete documents programmatically or in bulk, you can use the Sanity CLI:
sanity documents delete <document-id>You'll need to have the Sanity CLI installed (npm install -g @sanity/cli) and be authenticated to your project.
For bulk deletions, you can combine GROQ queries with the delete command:
sanity documents query "*[_type == 'yourType']" | sanity documents deleteProgrammatic Deletion
You can also delete documents programmatically using the Sanity client:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-token',
apiVersion: '2024-01-01'
})
await client.delete('document-id')Troubleshooting
If you don't see the delete option in the Studio menu, it could be because:
- Custom document actions have been configured to hide it (especially common with singleton documents)
- You don't have the necessary permissions based on your role configuration
The delete action may be filtered out for certain document types to prevent accidental deletion of critical content like site settings or configuration documents.
Show original thread2 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.