Release actions
Create custom actions that display alongside the default Content Release actions.
Release Actions lets you customize and control operations users can perform on a content release. When you create a custom release action, it's available in the actions menu in the release overview and details screens.
This is a paid feature
This feature is available on certain Enterprise plans. Talk to sales to learn more.
Prerequisites:
- Custom release actions require Sanity Studio v4.7.0 or later.
- Some examples on this page use an icon from
@sanity/iconsand import it from a subpath, such as@sanity/icons/Book. Subpath imports require@sanity/icons4.1.0 or later. - Release actions are part of Content Releases. If you're not using content releases as part of your workflow, they won't apply. Instead, check out document actions.
Limitations:
- At this time, custom release actions cannot extend or overwrite existing actions.
Create a release action
To set up a new release action component, complete the following steps:
- Define a release action component
- Register the release action component to the
releases.actionsarray in your studio's workspace configuration.
In this example, you create an action that logs details about the release to the console.
Create an action component
Start by creating an action component. We recommend using an actions directory in your studio project, or even an actions/releases directory if you plan to have multiple document, field, and release actions.
For this example, create the component in your studio project in actions/index.ts.
import type { ReleaseActionComponent } from "sanity";
import { BookIcon } from "@sanity/icons/Book"; // Optionally, you can add icons
export const CustomReleaseAction: ReleaseActionComponent = ({ release, documents}) => {
return {
label: 'Log Release Info',
icon: BookIcon, // Optional, make sure to install and import above
disabled: false,
title: 'Log information about this release to the console',
onHandle: () => {
console.group(`Release: ${release.metadata.title}`)
console.log('Release ID:', release._id)
console.log('Release State:', release.state)
console.log('Release Type:', release.metadata.releaseType)
console.log('Documents Count:', documents.length)
console.log(
'Documents:',
documents.map((d) => d.document._id),
)
console.groupEnd()
},
}
}Release actions accept an object containing the release and an array of documents. Each item in documents wraps the document in a document property, so read a document's ID with d.document._id, not d._id. In this example, the action accesses these parameters and logs details about the release and any included documents.
Add the component to your studio config
Next, import the action component and add it to the releases.actions array in your studio's sanity.config.ts.
import {defineConfig} from 'sanity'
import { CustomReleaseAction } from './actions'
export default defineConfig({
// ...
releases: {
actions: [CustomReleaseAction]
},
// ...
})Run the action
Run your studio locally or deploy the changes. The action is available in the ... menu on the release page.
Selectively render actions
You can selectively render actions based on the studio context.
Release context
Retrieve information about the release by accessing the context.release object. In this example, the custom action becomes available only if the release is scheduled and contains documents.
import {defineConfig} from 'sanity'
import { CustomReleaseAction } from './actions'
export default defineConfig({
// ...
releases: {
actions: (prev, context)=>{
if (context.release.state === 'scheduled' && context.documents.length > 0) {
return [...prev, CustomReleaseAction]
}
return prev
}
},
// ...
})In addition to release.state, you can access release.metadata to check the type, description, and title.
User context
Another common approach to filtering actions is by user role. In this example, the custom action only displays for users with the Administrator role.
import {defineConfig} from 'sanity'
import { CustomReleaseAction } from './actions'
export default defineConfig({
// ...
releases: {
actions: (prev, context)=>{
if (context.currentUser?.roles.find(({name}) => name === 'administrator')) {
return [...prev, CustomReleaseAction]
}
return prev
}
},
// ...
})The pattern of returning [...prev, newAction] ensures that any actions added outside of the main config, such as in a plugin, aren't overridden by this assignment.
Archive and delete a release from a custom action
To archive and delete a release from within a custom release action, call the Releases API methods on the Sanity client, such as releases.archive() and releases.delete(). Get the client by importing useClient.
In a custom action component:
import { useClient, getReleaseIdFromReleaseDocumentId, type ReleaseActionComponent } from "sanity";
import { BookIcon } from "@sanity/icons/Book"; // Optionally, you can add icons
import { useRouter } from "sanity/router"
export const ArchiveAndDeleteAction: ReleaseActionComponent = ({ release}) => {
// Get the release ID from the release system document ID
// using the included helper.
const releaseId = getReleaseIdFromReleaseDocumentId(release._id)
// Set up a Sanity client
const sanityClient = useClient({apiVersion: "2025-09-02"})
const router = useRouter()
// Handle the action
const handleArchiveAndDelete = async () => {
await sanityClient.releases.archive({releaseId})
// Archiving finishes in the background, and `delete` is rejected
// until the release reaches the `archived` state, so wait for it.
let current = await sanityClient.releases.get({releaseId})
while (current?.state === 'archiving') {
await new Promise((resolve) => setTimeout(resolve, 1000))
current = await sanityClient.releases.get({releaseId})
}
if (current?.state !== 'archived') {
throw new Error(`Release ${releaseId} was not archived (state: ${current?.state})`)
}
await sanityClient.releases.delete({releaseId})
// If action was on the release detail, navigate back to release's tool root
// as once deleted, the release detail page will not exist anymore
router.navigate({})
}
return {
label: "Archive and delete",
icon: BookIcon, // Optional, make sure to install and import above
title: "Archive and delete this release",
onHandle: handleArchiveAndDelete
}
}Then add the action to the release actions array in the sanity.config.ts file.
import {defineConfig} from 'sanity'
import { ArchiveAndDeleteAction } from './actions'
export default defineConfig({
// ...
releases: {
actions: [ArchiveAndDeleteAction]
},
// ...
})Archive and delete errors
The Releases API only allows archiving and deleting from certain release states. If the release is in the wrong state, the call fails:
releases.archive()only works on anactiverelease. For a scheduled release, it fails with an error that includesis not permitted to transition from state "scheduled" to "archiving". Unschedule the release first.releases.delete()only works on anarchivedorpublishedrelease. Archiving runs in the background, so the release is still in thearchivingstate whenreleases.archive()resolves. Ifreleases.delete()runs before the state reachesarchived, it fails with an error that includesis not permitted to transition from state "archiving" to "deleted".
