context object gives you this. It’s the second argument to your workflow’s fn, and it’s always there whether you use it or not.
Basic Usage
workflow.ts
context is always the second argument, even if your workflow has no inputSchema. In that case, use _input to signal you’re ignoring it: fn: async (_input, context) => { ... }.
Context Structure
| Namespace | Description |
|---|---|
context.control | Functions to control workflow execution flow |
context.info | Information about the current workflow execution |
Workflow Information
context.info.workflowId
The unique Temporal workflow ID for this execution. Include it in your output when you need to correlate results with external systems, track executions in logs, or pass a reference to another service.
See the Temporal workflow ID documentation for more details.
Control Functions
continueAsNew()
Every step your workflow executes adds to its execution history. For short workflows this doesn’t matter, but if you’re looping over thousands of leads or running a long-lived polling workflow, that history grows. continueAsNew checkpoints the current state and starts a fresh execution — same workflow, clean history.
The new execution is in the same chain as the previous one but generates a separate trace file. See Tracing — continue-as-new for how traces are correlated across runs.
continueAsNew must be the last thing your workflow does — call it with return:
inputSchema, pass the input object for the new execution. If it has no inputSchema, call without arguments: context.control.continueAsNew().
The function’s return type matches your outputSchema for type-checking, but it never actually returns — the execution is replaced.
See the Temporal continue-as-new documentation for more details.
isContinueAsNewSuggested()
Rather than guessing when to checkpoint, ask Temporal. This returns true when the runtime thinks your history is getting large enough that you should continue as new. Check it at loop boundaries:
Full Example
A workflow that processes a large batch of leads, checkpointing when Temporal suggests it:workflow.ts