> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# 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.

> [!WARNING]
> Early access
> Workflows is in early access, built in public. Read [How early access works](https://www.sanity.io/docs/workflows/prerelease) 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](https://www.sanity.io/docs/workflows/studio-user-guide).

Before you start, you need:

- The finished [quick start](https://www.sanity.io/docs/workflows/getting-started): `article-review` deployed to the `dev` partition of your project. To deploy your own definitions instead, see [Configure and deploy workflow definitions](https://www.sanity.io/docs/workflows/deploy-definitions).
- Sanity Studio v6.15.0 or later (v6.x).
- React and React DOM 19.2.7 or later.
- `styled-components` 6.4.2 or later.
- `@sanity/sdk` 3.1 or later in the 3.x line. The plugin requires this dependency directly.
- Node.js 20 or later.

> [!NOTE]
> 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](https://www.sanity.io/docs/workflows/getting-started) 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](https://www.sanity.io/docs/workflows/upgrade).

`@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:

**package.json (npm)**

```json
{
  "overrides": {
    "@sanity/sdk": {
      "@sanity/mutate": "0.18.2"
    }
  }
}
```

**pnpm-workspace.yaml (pnpm)**

```yaml
overrides:
  '@sanity/sdk@3>@sanity/mutate': 0.18.2
```

Install the plugin, SDK, and Workflows runtime packages:

**npm**

```shell
npm install @sanity/sdk@^3.1 @sanity/workflows-ui @sanity/workflows @sanity/workflows-cli
```

**pnpm**

```shell
pnpm add @sanity/sdk@^3.1 @sanity/workflows-ui @sanity/workflows @sanity/workflows-cli
```

**yarn**

```shell
yarn add @sanity/sdk@^3.1 @sanity/workflows-ui @sanity/workflows @sanity/workflows-cli
```

**bun**

```shell
bun add @sanity/sdk@^3.1 @sanity/workflows-ui @sanity/workflows @sanity/workflows-cli
```

To 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:

**sanity.config.ts**

```typescript
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:

- `partition` must match the partition you deployed the definitions to. If you omit it, it defaults to `default`, which matches a deployment that also omits it.
- `workflowResource` names 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. `workflowDataset` is its deprecated form for a dataset in the same project.

For every option, with types and defaults, see the [Studio plugin configuration reference](https://www.sanity.io/docs/workflows/studio-plugin-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 `subject` takes its value from the person starting the workflow.
- The `subject` accepts 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 `autoStart` for one workflow.
- Bind a definition that identifies its document with a [doc.ref](https://www.sanity.io/docs/workflows/workflow-authoring-reference) field instead of a `subject` field.
- Customize the label an editor sees, seed the workflow's start values, or bind the workflow to a [Content Release](https://www.sanity.io/docs/user-guides/content-releases) perspective.

**sanity.config.ts**

```typescript
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](https://www.sanity.io/docs/workflows/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:

- `initialStateBuilder` returns the starting field values. It replaces the default, which sets the subject to the current document. Return `[]` to set nothing.
- `contextBuilder` returns the starting `$context`.

The [mapping row reference](https://www.sanity.io/docs/workflows/studio-plugin-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:

**sanity.config.ts**

```typescript
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](https://www.sanity.io/docs/user-guides/content-releases) perspective.
- [Inputs](https://www.sanity.io/docs/workflows/fields) declared `required: true` are collected before the editor enters the form.
- The mapping’s `initialStateBuilder` and `contextBuilder` do 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 `object` field without `fields`, 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:

1. The plugin’s `partition` matches 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.
2. The definition is deployed to the resource the plugin reads: `workflowResource`, or the dataset the deprecated `workflowDataset` names. With neither set, the plugin reads the workspace dataset.
3. The workflow’s `subject` accepts the document type. A mapping row doesn’t override this check.
4. A type in the reserved `sanity.` or `system.` 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](https://www.sanity.io/docs/workflows/guards).

## 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](https://www.sanity.io/docs/workflows/studio-plugin-reference).

## Next steps

- [Workflows in Sanity Studio](https://www.sanity.io/docs/workflows/studio-user-guide): what editors see and how they move work forward.
- [Effects and runtimes](https://www.sanity.io/docs/workflows/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](https://www.sanity.io/docs/workflows/generate-functions) creates that runtime from your definitions.
- [Choose your surface](https://www.sanity.io/docs/workflows/introduction): every package that can drive a workflow, and when to reach for each.
- [Create a workflow-powered Document Action](https://www.sanity.io/docs/workflows/custom-studio-integrations): build your own workflow controls inside Studio with the Studio adapter.
- [Studio plugin configuration reference](https://www.sanity.io/docs/workflows/studio-plugin-reference): every plugin option, mapping field, structure helper, and table prop, with types and defaults.

> [!NOTE]
> 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](https://www.sanity.io/docs/workflows/mcp).



