Add Workflows to Sanity Studio
Install the Workflows plugin in a Sanity Studio, bind it to your deployed definitions, and put workflows in front of editors.
Early access
Workflows is in early access, built in public. Read How early access works before you rely on it.
The Workflows Studio plugin connects deployed workflow definitions to Sanity Studio. It adds a workflow strip and a Workflows view to the document editor, and a Workflows tool for tracking work across documents.
This guide starts from a Studio with no workflow UI and ends with an editor starting a workflow on a document. For what editors see and do once it is running, read Workflows in Sanity Studio.
Before you start, you need:
- The finished quick start:
article-reviewdeployed to thedevpartition of your project. To deploy your own definitions instead, see Configure and deploy workflow definitions. - Sanity Studio v6.15.0 or later (v6.x).
- React and React DOM 19.2.7 or later.
styled-components6.4.2 or later.@sanity/sdk3.1 or later in the 3.x line. The plugin requires this dependency directly.- Node.js 20 or later.
Only the plugin needs a Studio
Studio 6 is a major version. If your studio is still on v5, upgrade it before you install the plugin. You don’t have to wait for that upgrade to use Workflows: the engine, the CLI, the App SDK adapter, and @sanity/workflows/agents don’t depend on Sanity Studio. The quick start runs end to end without a studio.
Install the packages
Install the packages in a Sanity Studio project on version 6.15 or later in the 6.x line. The plugin reads the definitions you deployed with the Workflows CLI.
Install @sanity/workflows-ui and @sanity/workflows at the same version. The install command in this section includes everything the plugin requires. To upgrade an existing installation, follow the compatibility and upgrade instructions.
@sanity/sdk 3.1.0 can install @sanity/mutate 0.18.1. With Sanity client 8, that version can leave document reads waiting forever. To prevent this, add this override to your project’s root package manager configuration before you install:
{
"overrides": {
"@sanity/sdk": {
"@sanity/mutate": "0.18.2"
}
}
}overrides:
'@sanity/sdk@3>@sanity/mutate': 0.18.2Install the plugin, SDK, and Workflows runtime packages:
npm install @sanity/sdk@^3.1 @sanity/workflows-ui @sanity/workflows @sanity/workflows-clipnpm add @sanity/sdk@^3.1 @sanity/workflows-ui @sanity/workflows @sanity/workflows-cliyarn add @sanity/sdk@^3.1 @sanity/workflows-ui @sanity/workflows @sanity/workflows-clibun add @sanity/sdk@^3.1 @sanity/workflows-ui @sanity/workflows @sanity/workflows-cliTo check the result, run npm ls @sanity/sdk @sanity/mutate or pnpm why @sanity/mutate. Confirm that @sanity/sdk 3 uses @sanity/mutate 0.18.2. Other packages may use other versions. Commit the configuration and the updated lockfile.
Keep the override until your @sanity/sdk version requires @sanity/mutate 0.18.2 or later. After you remove it, reinstall and check the dependency tree again.
Register the plugin
In sanity.config.ts, add the Workflows document view and the plugin. Set partition to the partition you deployed the definitions to:
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import {
workflowsDefaultDocumentNode,
workflowsStudioPlugin,
} from '@sanity/workflows-ui/studio-plugin'
export default defineConfig({
// ...your projectId, dataset, schema...
plugins: [
structureTool({
defaultDocumentNode: workflowsDefaultDocumentNode(),
}),
workflowsStudioPlugin({
partition: 'dev', // must match your deployment's partition
}),
],
})workflowsDefaultDocumentNode() adds the Workflows view to every document type. It takes no arguments. The plugin works out which workflows apply to each document when the document opens. To add the view to specific document types instead, append workflowsView(S) to that type’s views([...]).
Two options control where the plugin reads workflows:
partitionmust match the partition you deployed the definitions to. If you omit it, it defaults todefault, which matches a deployment that also omits it.workflowResourcenames the resource that holds workflow definitions and instances, such as{type: 'dataset', id: '<your-project-id>.workflows'}with your project ID. Set it when that isn’t the workspace’s own dataset.workflowDatasetis its deprecated form for a dataset in the same project.
For every option, with types and defaults, see the Studio plugin configuration reference.
Bind workflows to document types
The plugin finds workflows on its own. A workflow’s subject field names the document the workflow is about, and lists the document types it accepts. The plugin offers a workflow on a document type when these are true:
- The latest deployed version of the definition can be started directly. Child-only workflows are skipped.
- The definition’s
subjecttakes its value from the person starting the workflow. - The
subjectaccepts that document type.
Types in the reserved sanity. and system. namespaces are never found this way. To bind one, add a mapping row and list the type in the subject’s types. The engine’s own document types can’t be subjects. A mapping row that names one shows a configuration error.
A mapping row connects one document type to one deployed workflow definition. It replaces what the plugin found for that pair. Add a row when you need to do one of these:
- Enable
autoStartfor one workflow. - Bind a definition that identifies its document with a
doc.reffield instead of asubjectfield. - Customize the label an editor sees, seed the workflow's start values, or bind the workflow to a Content Release perspective.
workflowsStudioPlugin({
partition: 'dev',
mappings: [
{
docType: 'article',
definition: 'article-review',
label: 'Editorial review',
},
],
})One document type can have several workflows, so the same docType can appear on more than one row. Two rows with the same docType and definition are an error. The plugin throws Duplicate workflow mapping for article::article-review when it loads sanity.config.ts, and the studio doesn’t start.
A row doesn’t have to supply every value a workflow needs to start. The start dialog asks the editor for any required input field the row leaves empty. See Fields for the fields a definition can declare and where their starting values come from.
Two optional row functions apply only when an editor starts a workflow by hand:
initialStateBuilderreturns the starting field values. It replaces the default, which sets the subject to the current document. Return[]to set nothing.contextBuilderreturns the starting$context.
The mapping row reference lists every field.
Start a workflow automatically
To start a workflow when an editor creates a document in the studio, set autoStart: true on its mapping row. Add one row for each workflow that should start this way:
workflowsStudioPlugin({
partition: 'dev',
mappings: [
{
docType: 'article',
definition: 'article-review',
label: 'Article review',
autoStart: true,
},
],
})Auto-start works only for new documents created in the studio, and only when the workflow’s subject takes its value from the person starting it. It behaves like this:
- The new document becomes the workflow subject in the same draft or Content Release perspective.
- Inputs declared
required: trueare collected before the editor enters the form. - The mapping’s
initialStateBuilderandcontextBuilderdo not run. Start the workflow manually when it needs values from either builder. - If several workflows apply, Studio starts each one separately, so one failed start doesn’t undo the others. When the editor chooses Try again, Studio starts only the workflows that failed. If one of them requires an input that Studio can’t edit, such as an
objectfield withoutfields, Studio starts none of them and opens the document without a message. - If a start requirement refuses the new document, the studio shows the requirement’s description, title, or name. The editor can choose Try again or Continue editing without it. Try again checks the requirements again and asks for the required inputs again. Auto-start never asks for optional inputs, so a requirement that needs a value for one fails every time. If the failed requirement is
singleSubject, an unfinished instance of the workflow already has this document, so the studio opens the form without a message. - Documents created outside the studio don’t trigger auto-start. Auto-start is a convenience in the studio, not a rule the Content Lake enforces.
Verify it in the document editor
Open a document whose type a deployed workflow accepts. The workflow strip appears above the document form and lists the workflows for that type. Start one. Then open the Workflows view to see the stage’s activities, editable fields, and available actions.
If the strip lists no workflows, check these:
- The plugin’s
partitionmatches the partition you deployed to. If that partition has no definitions, the plugin logs a warning in the browser console that names the partitions that do. - The definition is deployed to the resource the plugin reads:
workflowResource, or the dataset the deprecatedworkflowDatasetnames. With neither set, the plugin reads the workspace dataset. - The workflow’s
subjectaccepts the document type. A mapping row doesn’t override this check. - A type in the reserved
sanity.orsystem.namespace has a mapping row.
If the plugin finds a problem with a workflow, the workflow still appears, but its start button is disabled. The tooltip reads Unavailable — this workflow isn’t set up correctly for Article documents, with your document type. To see the problem, open the workflow’s page in the Workflows tool and look under Setup issue. The browser console also logs it, with the prefix [workflow-studio-plugin]. The start dialog reads the deployed definitions each time it opens, so you don’t need to restart the studio after a deploy.
While an instance is in a guarded stage, the studio can disable publishing, unpublishing, or deleting; the Content Lake doesn’t enforce guards, so a client that writes to it directly isn’t stopped. The studio explains why the action is disabled. See Guards and enforcement.
Embed tables in a custom Studio tool
You can reuse the Workflows tool’s tables in your own studio tool. Render RunsTable for workflow runs or ForMeTable for assigned tasks, in a studio that has workflowsStudioPlugin. Build their rows with runRowsOf and forMeTaskRowsOf. Your tool handles loading, filtering, sorting, and selection. For props and row builders, see Workflow tables.
Next steps
- Workflows in Sanity Studio: what editors see and how they move work forward.
- Effects and runtimes: Studio calls the engine only while an editor is working, so to run queued effects or check deadlines when nobody has Studio open, you need a server runtime. Generate Functions from your workflow definitions creates that runtime from your definitions.
- Choose your surface: every package that can drive a workflow, and when to reach for each.
- Create a workflow-powered Document Action: build your own workflow controls inside Studio with the Studio adapter.
- Studio plugin configuration reference: every plugin option, mapping field, structure helper, and table prop, with types and defaults.
Visiting agent?
Workflows has MCP tools that let an agent inspect, operate, author, validate, and deploy workflows. An agent host embeds these tools. Ask the person you work for whether your host includes the Workflows tools.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?