Trigger.dev Skill
You are an expert at building production-grade Trigger.dev v4 background tasks, workflows, and automations in TypeScript.
Read the detailed reference files in ${CLAUDE_SKILL_DIR} for comprehensive code patterns:
core-reference.md — Tasks, runs, triggering, queues, concurrency, retries, errors, idempotency, wait functions
config-reference.md — trigger.config.ts, build extensions, deployment, CLI, project structure, env vars, monorepos
advanced-reference.md — AI integration, streams, realtime, middleware, locals, lifecycle hooks, metadata, tags, scheduled tasks
Setup Checklist
If starting a new Trigger.dev project or adding to an existing one, refer to https://trigger.dev/docs/manual-setup and use the mcp__trigger__search_docs tool for the latest setup instructions. Core steps:
- Install packages:
npm add @trigger.dev/sdk@latest and npm add -D @trigger.dev/build@latest
- Create
trigger.config.ts at project root with defineConfig({ project: "<ref>", dirs: ["./src/trigger"] })
- Add
TRIGGER_SECRET_KEY to .env
- Create task files in the configured
dirs directory
- Run
npx trigger.dev@latest dev for local development
- Deploy with
npx trigger.dev@latest deploy
Core Patterns
Basic Task
import { task } from "@trigger.dev/sdk";
export const myTask = task({
id: "my-task",
run: async (payload: { data: string }, { ctx }) => {
return { result: "done" };
},
});
Schema-Validated Task
import { schemaTask } from "@trigger.dev/sdk";
import { z } from "zod";
export const myTask = schemaTask({
id: "my-task",
schema: z.object({ name: z.string(), age: z.number() }),
run: async (payload) => { /* payload is typed and validated */ },
});
Scheduled Task (Cron)
import { schedules } from "@trigger.dev/sdk";
export const dailyCleanup = schedules.task({
id: "daily-cleanup",
cron: "0 0 * * *",
run: async (payload) => {
// payload.timestamp, payload.lastTimestamp, payload.timezone
},
});
Trigger from Backend
import { tasks } from "@trigger.dev/sdk";
import type { myTask } from "~/trigger/my-task";
const handle = await tasks.trigger<typeof myTask>("my-task", { data: "hello" });
Trigger from Inside a Task
const result = await otherTask.triggerAndWait({ data: "hello" });
if (result.ok) console.log(result.output);
Critical Rules
- Task IDs must be unique across the entire project
- Payloads and return values must be JSON serializable — no classes, functions, or circular refs
- Always export tasks from trigger files (unexported tasks become hidden/internal-only)
- Use type-only imports when triggering from backend:
import type { myTask } from "~/trigger/my-task"
- trigger.config.ts must be at the project root — it cannot be nested
- Use
AbortTaskRunError to fail without retrying on permanent errors
- Wait functions are free — tasks checkpoint during waits, no compute charges
- Concurrency limits only count actively executing runs — delayed/waiting runs don't count
- Max 10 tags per run, max 256KB metadata per run, max 1000 items per batch
- Use
idempotencyKeys.create() inside tasks to prevent duplicate child triggers during retries
- Use the
mcp__trigger__search_docs tool to look up the latest docs when unsure about any API
- Use
mcp__trigger__deploy to deploy tasks, mcp__trigger__list_runs to check runs, mcp__trigger__trigger_task to trigger tasks
Machine Presets
| Preset |
vCPU |
RAM |
| micro |
0.25 |
0.25 GB |
| small-1x (default) |
0.5 |
0.5 GB |
| small-2x |
1 |
1 GB |
| medium-1x |
1 |
2 GB |
| medium-2x |
2 |
4 GB |
| large-1x |
4 |
8 GB |
| large-2x |
8 |
16 GB |
Key SDK Imports
import {
task, schemaTask, schedules, batch, tasks, runs, queues,
tags, metadata, wait, auth, idempotencyKeys, logger, streams,
AbortTaskRunError, configure, query,
} from "@trigger.dev/sdk";
import { ai } from "@trigger.dev/sdk/ai";
Use $ARGUMENTS to understand what the user wants to build. Read the reference files for detailed patterns before writing code.
1---2name: trigger-dev3description: Build Trigger.dev background jobs, automations, and workflows in TypeScript. Use when the user wants to create tasks, scheduled jobs, AI agent workflows, queued background processing, cron jobs, or any long-running async work with Trigger.dev. Triggers on imports from @trigger.dev/sdk or mentions of trigger.dev.4argument-hint: [description of what to build]5risk: safe6metadata:7 source: https://skillmd.com/skills/kursku/trigger-dev8---910# Trigger.dev Skill1112You are an expert at building production-grade Trigger.dev v4 background tasks, workflows, and automations in TypeScript.1314Read the detailed reference files in `${CLAUDE_SKILL_DIR}` for comprehensive code patterns:1516- `core-reference.md` — Tasks, runs, triggering, queues, concurrency, retries, errors, idempotency, wait functions17- `config-reference.md` — trigger.config.ts, build extensions, deployment, CLI, project structure, env vars, monorepos18- `advanced-reference.md` — AI integration, streams, realtime, middleware, locals, lifecycle hooks, metadata, tags, scheduled tasks1920## Setup Checklist2122If starting a new Trigger.dev project or adding to an existing one, refer to https://trigger.dev/docs/manual-setup and use the `mcp__trigger__search_docs` tool for the latest setup instructions. Core steps:23241. Install packages: `npm add @trigger.dev/sdk@latest` and `npm add -D @trigger.dev/build@latest`252. Create `trigger.config.ts` at project root with `defineConfig({ project: "<ref>", dirs: ["./src/trigger"] })`263. Add `TRIGGER_SECRET_KEY` to `.env`274. Create task files in the configured `dirs` directory285. Run `npx trigger.dev@latest dev` for local development296. Deploy with `npx trigger.dev@latest deploy`3031## Core Patterns3233### Basic Task34```typescript35import { task } from "@trigger.dev/sdk";3637export const myTask = task({38 id: "my-task",39 run: async (payload: { data: string }, { ctx }) => {40 return { result: "done" };41 },42});43```4445### Schema-Validated Task46```typescript47import { schemaTask } from "@trigger.dev/sdk";48import { z } from "zod";4950export const myTask = schemaTask({51 id: "my-task",52 schema: z.object({ name: z.string(), age: z.number() }),53 run: async (payload) => { /* payload is typed and validated */ },54});55```5657### Scheduled Task (Cron)58```typescript59import { schedules } from "@trigger.dev/sdk";6061export const dailyCleanup = schedules.task({62 id: "daily-cleanup",63 cron: "0 0 * * *",64 run: async (payload) => {65 // payload.timestamp, payload.lastTimestamp, payload.timezone66 },67});68```6970### Trigger from Backend71```typescript72import { tasks } from "@trigger.dev/sdk";73import type { myTask } from "~/trigger/my-task";7475const handle = await tasks.trigger<typeof myTask>("my-task", { data: "hello" });76```7778### Trigger from Inside a Task79```typescript80const result = await otherTask.triggerAndWait({ data: "hello" });81if (result.ok) console.log(result.output);82```8384## Critical Rules85861. **Task IDs must be unique** across the entire project872. **Payloads and return values must be JSON serializable** — no classes, functions, or circular refs883. **Always export tasks** from trigger files (unexported tasks become hidden/internal-only)894. **Use type-only imports** when triggering from backend: `import type { myTask } from "~/trigger/my-task"`905. **trigger.config.ts must be at the project root** — it cannot be nested916. **Use `AbortTaskRunError`** to fail without retrying on permanent errors927. **Wait functions are free** — tasks checkpoint during waits, no compute charges938. **Concurrency limits only count actively executing runs** — delayed/waiting runs don't count949. **Max 10 tags per run**, max 256KB metadata per run, max 1000 items per batch9510. **Use `idempotencyKeys.create()`** inside tasks to prevent duplicate child triggers during retries9611. **Use the `mcp__trigger__search_docs` tool** to look up the latest docs when unsure about any API9712. **Use `mcp__trigger__deploy`** to deploy tasks, **`mcp__trigger__list_runs`** to check runs, **`mcp__trigger__trigger_task`** to trigger tasks9899## Machine Presets100101| Preset | vCPU | RAM |102|--------|------|-----|103| micro | 0.25 | 0.25 GB |104| small-1x (default) | 0.5 | 0.5 GB |105| small-2x | 1 | 1 GB |106| medium-1x | 1 | 2 GB |107| medium-2x | 2 | 4 GB |108| large-1x | 4 | 8 GB |109| large-2x | 8 | 16 GB |110111## Key SDK Imports112113```typescript114import {115 task, schemaTask, schedules, batch, tasks, runs, queues,116 tags, metadata, wait, auth, idempotencyKeys, logger, streams,117 AbortTaskRunError, configure, query,118} from "@trigger.dev/sdk";119import { ai } from "@trigger.dev/sdk/ai";120```121122Use `$ARGUMENTS` to understand what the user wants to build. Read the reference files for detailed patterns before writing code.