trigger-realtime
Skill70 starsChanged 2 months agoMITView on GitHub
Subscribe to Trigger.dev task runs in real-time from frontend and backend. Use when building progress indicators, live dashboards, streaming AI/LLM responses, or React components that display task status.
6 other projects use a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- triggerdotdev/skillstheir own version, first seen Oct 19, 2026
- adrianhajdin/ghost-aiword for word, first seen Oct 9, 2026
- papermark/papermarkword for word, first seen Oct 8, 2026
- mfts/papermarkword for word, first seen Oct 8, 2026
- trycompai/compedited, first seen Oct 8, 2026
- Visitha2001/ghost-ai-sseword for word, first seen Jun 24, 2026
Other versions6 projects use a version of this.
Word for word · 4
- mfts/papermark★ 9.2k100% same
- papermark/papermark★ 9.2k100% same
- adrianhajdin/ghost-ai★ 332100% same
- Visitha2001/ghost-ai-sse★ 0100% same
Edited · 1
- trycompai/comp★ 2.1k24% same
Wrote their own version · 1
- triggerdotdev/skills★ 35same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- graduate-to-triggerSkill
- research-agentSkill
- research-process-builderSkill
- trigger-agentsSkill
- trigger-configSkill
- trigger-cost-savingsSkill
- trigger-setupSkill
- trigger-tasksSkill
- research-process-builderSkill
The file
Files
Trigger.dev Realtime
Subscribe to task runs and stream data in real-time from frontend and backend.
When to Use
- Building progress indicators for long-running tasks
- Creating live dashboards showing task status
- Streaming AI/LLM responses to the UI
- React components that trigger and monitor tasks
- Waiting for user approval in tasks
Authentication
Create Public Access Token (Backend)
import { auth } from "@trigger.dev/sdk";
// Read-only token for specific runs
const publicToken = await auth.createPublicToken({
scopes: {
read: {
runs: ["run_123"],
tasks: ["my-task"],
},
},
expirationTime: "1h",
});
// Pass this token to your frontendCreate Trigger Token (for frontend triggering)
const triggerToken = await auth.createTriggerPublicToken("my-task", {
expirationTime: "30m",
});Backend Subscriptions
import { runs, tasks } from "@trigger.dev/sdk";
// Trigger and subscribe
const handle = await tasks.trigger("my-task", { data: "value" });
for await (const run of runs.subscribeToRun(handle.id)) {
console.log(`Status: ${run.status}`);
console.log(`Progress: ${run.metadata?.progress}`);
if (run.status === "COMPLETED") {
console.log("Output:", run.output);
break;
}
}
// Subscribe to tagged runs
for await (const run of runs.subscribeToRunsWithTag("user-123")) {
console.log(`Run ${run.id}: ${run.status}`);
}
// Subscribe to batch
for await (const run of runs.subscribeToBatch(batchId)) {
console.log(`Batch run ${run.id}: ${run.status}`);
}React Hooks
Installation
npm add @trigger.dev/react-hooksTrigger Task from React
"use client";
import { useRealtimeTaskTrigger } from "@trigger.dev/react-hooks";
import type { myTask } from "../trigger/tasks";
function TaskTrigger({ accessToken }: { accessToken: string }) {
const { submit, run, isLoading } = useRealtimeTaskTrigger<typeof myTask>(
"my-task",
{ accessToken }
);
return (
<div>
<button
onClick={() => submit({ data: "value" })}
disabled={isLoading}
>
Start Task
</button>
{run && (
<div>
<p>Status: {run.status}</p>
<p>Progress: {run.metadata?.progress}%</p>
{run.output && <p>Result: {JSON.stringify(run.output)}</p>}
</div>
)}
</div>
);
}Subscribe to Existing Run
"use client";
import { useRealtimeRun } from "@trigger.dev/react-hooks";
import type { myTask } from "../trigger/tasks";
function RunStatus({ runId, accessToken }: { runId: string; accessToken: string }) {
const { run, error } = useRealtimeRun<typeof myTask>(runId, {
accessToken,
onComplete: (run) => {
console.log("Completed:", run.output);
},
});
if (error) return <div>Error: {error.message}</div>;
if (!run) return <div>Loading...</div>;
return (
<div>
<p>Status: {run.status}</p>
<p>Progress: {run.metadata?.progress || 0}%</p>
</div>
);
}Subscribe to Tagged Runs
"use client";
import { useRealtimeRunsWithTag } from "@trigger.dev/react-hooks";
function UserTasks({ userId, accessToken }: { userId: string; accessToken: string }) {
const { runs } = useRealtimeRunsWithTag(`user-${userId}`, { accessToken });
return (
<ul>
{runs.map((run) => (
<li key={run.id}>{run.id}: {run.status}</li>
))}
</ul>
);
}Realtime Streams (AI/LLM)
Define Stream (shared location)
// trigger/streams.ts
import { streams } from "@trigger.dev/sdk";
export const aiStream = streams.define<string>({
id: "ai-output",
});Pipe Stream in Task
import { task } from "@trigger.dev/sdk";
import { aiStream } from "./streams";
export const streamingTask = task({
id: "streaming-task",
run: async (payload: { prompt: string }) => {
const completion = await openai.chat.completions.create({
model: "gpt-4",
messages: [{ role: "user", content: payload.prompt }],
stream: true,
});
const { waitUntilComplete } = aiStream.pipe(completion);
await waitUntilComplete();
},
});Read Stream in React
"use client";
import { useRealtimeStream } from "@trigger.dev/react-hooks";
import { aiStream } from "../trigger/streams";
function AIResponse({ runId, accessToken }: { runId: string; accessToken: string }) {
const { parts, error } = useRealtimeStream(aiStream, runId, {
accessToken,
throttleInMs: 50,
});
if (error) return <div>Error: {error.message}</div>;
if (!parts) return <div>Waiting for response...</div>;
return <div>{parts.join("")}</div>;
}Wait Tokens (Human-in-the-loop)
In Task
import { task, wait } from "@trigger.dev/sdk";
export const approvalTask = task({
id: "approval-task",
run: async (payload) => {
// Process initial data
const processed = await processData(payload);
// Wait for human approval
const approval = await wait.forToken<{ approved: boolean }>({
token: `approval-${payload.id}`,
timeoutInSeconds: 86400, // 24 hours
});
if (approval.approved) {
return await finalizeData(processed);
}
throw new Error("Not approved");
},
});Complete Token from React
"use client";
import { useWaitToken } from "@trigger.dev/react-hooks";
function ApprovalButton({ tokenId, accessToken }: { tokenId: string; accessToken: string }) {
const { complete } = useWaitToken(tokenId, { accessToken });
return (
<div>
<button onClick={() => complete({ approved: true })}>
Approve
</button>
<button onClick={() => complete({ approved: false })}>
Reject
</button>
</div>
);
}Run Object Properties
| Property | Description |
id | Unique run identifier |
status | QUEUED, EXECUTING, COMPLETED, FAILED, CANCELED |
payload | Task input (typed) |
output | Task result (typed, when completed) |
metadata | Real-time updatable data |
createdAt | Start timestamp |
costInCents | Execution cost |
Best Practices
- Scope tokens narrowly — only grant necessary permissions
- Set expiration times — don't use long-lived tokens
- Use typed hooks — pass task types for proper inference
- Handle errors — always check for errors in hooks
- Throttle streams — use
throttleInMsto control re-renders
See references/realtime.md for complete documentation.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

