Setting metadata at trigger time
Pass ametadata object when triggering a run:
Reading metadata inside a run
Usemetadata.current() to get the entire metadata object, or metadata.get(key) to retrieve a specific key:
/trigger/my-task.ts
Calling
metadata.current() or metadata.get() outside of a run function always returns
undefined. Calling update methods outside of a run is a no-op. This makes it safe to use
metadata methods anywhere in shared utilities without guarding.Updates API
All update methods (exceptflush and stream) are synchronous and non-blocking. The SDK periodically flushes changes to the database in the background, so you can call them as often as needed without impacting run performance.
set
Set the value of a specific key:
del
Delete a key from the metadata object:
replace
Replace the entire metadata object:
append
Append a value to an array key (creates the array if the key does not exist):
remove
Remove a specific value from an array key:
increment / decrement
Atomically increment or decrement a numeric key:
flush
Force an immediate write to the database. Use this when you need the metadata to be persisted before a checkpoint or external call:
Fluent API
All update methods return the updater object, so you can chain them:Parent & root updates
A child task can update the metadata of its parent or the root task. This is useful for rolling up progress across a task hierarchy./trigger/tasks.ts
metadata.parent and metadata.root, and they support chaining:
Example: tracking progress across parallel child tasks
/trigger/csv-processing.ts
Inspecting metadata
Dashboard
Metadata for a run is displayed in the run details view in the Trigger.dev dashboard.API
Retrieve a run’s metadata usingruns.retrieve():
Type-safe metadata
Metadata is loosely typed by default — it accepts any JSON-serializable object. Wrap the metadata API with a Zod schema for full type safety:Values like
Date are serialized to strings when stored. Use z.coerce.date() or equivalent to
deserialize them on retrieval.Size limit
The maximum metadata size is 256 KB. Exceeding this throws an error. If you are self-hosting, you can increase the limit with theTASK_RUN_METADATA_MAXIMUM_SIZE environment variable (value in bytes).