npx skills add ...
npx skills add triggerdotdev/skills --skill trigger-realtime
Trigger.dev client/frontend surface: subscribe to runs in realtime (runs.subscribeToRun and the @trigger.dev/react-hooks hook useRealtimeRun), consume metadata and AI/text streams in React (useRealtimeStream), trigger tasks from the browser (useTaskTrigger, useRealtimeTaskTrigger), and mint scoped frontend credentials with auth.createPublicToken / auth.createTriggerPublicToken. Load when wiring a frontend (React/Next.js/Remix) or backend-for-frontend to show live run progress, status badges, token streams, trigger buttons, or wait-token approval UIs. NOT for writing the backend task itself (streams.define / metadata.set is trigger-tasks territory); this is the consumer side.
npx skills add triggerdotdev/skills --skill trigger-realtime
The consumer side of Trigger.dev's run state and streams: read live run
updates, render AI/text streams, and trigger tasks from a browser. Hooks come
from @trigger.dev/react-hooks; token minting and backend subscription come
from @trigger.dev/sdk.
The flow is always: mint a scoped token in the backend, pass it to the frontend, subscribe with a hook.
There are two token kinds: Public Access Tokens (read/subscribe, from
auth.createPublicToken) and Trigger Tokens (trigger-from-browser, single-use,
from auth.createTriggerPublicToken). Both default to a 15 minute expiry.
metadata is Record<string, DeserializedJson>, so nested values need a cast.
Pass onComplete: (run, error) => {} to react when the run finishes.
skipColumnsFor a badge or progress bar you do not need payload/output. Skipping them
reduces wire size and avoids "Large HTTP Payload" warnings.
You can skip any of: payload, output, metadata, startedAt, delayUntil,
queuedAt, expiredAt, completedAt, number, isTest, usageDurationMs,
costInCents, baseCostInCents, ttl, payloadType, outputType, runTags,
error.
accessToken here is a Trigger Token (auth.createTriggerPublicToken), not a
Public Access Token.
submit(payload, options?) takes the same options as a backend trigger call.
Use useRealtimeTaskTriggerWithStreams<typeof myTask, STREAMS> when you also
want the task's streams (it returns { submit, run, streams, error, isLoading }).
useRealtimeStream takes a defined stream for full type safety, or a runId
plus optional stream key. Returns { parts, error }.
Without a defined stream: useRealtimeStream<string>(runId, "ai-output", { accessToken }),
or omit the key to use the default stream. Other options: baseURL, startIndex,
throttleInMs (default 16). The legacy useRealtimeRunWithStreams(runId, options)
hook is still supported when you need both the run and all its streams at once.
runs.subscribeToRun completes when the run finishes, so the loop exits on its own.
CRITICAL: Triggering from the browser with a Public Access Token. The
read token from createPublicToken cannot trigger tasks.
useTaskTrigger("my-task", { accessToken: publicAccessTokenFromCreatePublicToken })auth.createTriggerPublicToken("my-task") and pass that.Token with no scopes. A scopeless token authorizes nothing, so every subscribe 403s.
await auth.createPublicToken()await auth.createPublicToken({ scopes: { read: { runs: ["run_1234"] } } })Polling with useRun/SWR for live updates. useRun is the SWR-based
management-API hook (not recommended for live state); set refreshInterval: 0
to stop polling if you do use it.
useRun(runId, { refreshInterval: 1000 }) to track progressuseRealtimeRun(runId, { accessToken }) (no polling, no WebSocket setup)Forgetting "use client". Realtime/trigger hooks cannot run in a server component.
useRealtimeRun"use client"; at the top of any component using these hooks.Shipping payload/output you do not render.
useRealtimeRun(runId, { accessToken }) for a status badge (large payloads over the wire)useRealtimeRun(runId, { accessToken, skipColumns: ["payload", "output"] })Subscribing before the handle exists.
useRealtimeRun(handle, { accessToken: handle?.publicAccessToken }) with no guardenabled: !!handle so it subscribes only once the trigger returns a handle.Sibling skills:
trigger-tasks for the task side: streams.define(), metadata.set(), and wait.createToken.trigger-authoring-chat-agent and trigger-chat-agent-advanced for chat agents, which build on these realtime streams.Reference docs ship beside this skill in the same package, read them locally (no network), pinned to your installed version. The sources: frontmatter above lists every doc this skill draws from, all under @trigger.dev/sdk/docs/. Start with:
@trigger.dev/sdk/docs/realtime/react-hooks/subscribe.mdx@trigger.dev/sdk/docs/realtime/react-hooks/streams.mdx@trigger.dev/sdk/docs/realtime/auth.mdx@trigger.dev/sdk/docs/realtime/run-object.mdx (the realtime run object differs from the management-API object returned by useRun)This skill is bundled inside @trigger.dev/sdk and read directly from node_modules, so it always matches your installed SDK version (see the adjacent package.json). The full documentation for these APIs ships alongside it under @trigger.dev/sdk/docs/.