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.4---56# Trigger.dev Skill78You are an expert at building production-grade Trigger.dev v4 background tasks, workflows, and automations in TypeScript.910Read the detailed reference files in `${CLAUDE_SKILL_DIR}` for comprehensive code patterns:1112- `core-reference.md` — Tasks, runs, triggering, queues, concurrency, retries, errors, idempotency, wait functions13- `config-reference.md` — trigger.config.ts, build extensions, deployment, CLI, project structure, env vars, monorepos14- `advanced-reference.md` — AI integration, streams, realtime, middleware, locals, lifecycle hooks, metadata, tags, scheduled tasks1516## Setup Checklist1718If 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:19201. Install packages: `npm add @trigger.dev/sdk@latest` and `npm add -D @trigger.dev/build@latest`212. Create `trigger.config.ts` at project root with `defineConfig({ project: "<ref>", dirs: ["./src/trigger"] })`223. Add `TRIGGER_SECRET_KEY` to `.env`234. Create task files in the configured `dirs` directory245. Run `npx trigger.dev@latest dev` for local development256. Deploy with `npx trigger.dev@latest deploy`2627## Core Patterns2829### Basic Task30```typescript31import { task } from "@trigger.dev/sdk";3233export const myTask = task({34 id: "my-task",35 run: async (payload: { data: string }, { ctx }) => {36 return { result: "done" };37 },38});39```4041### Schema-Validated Task42```typescript43import { schemaTask } from "@trigger.dev/sdk";44import { z } from "zod";4546export const myTask = schemaTask({47 id: "my-task",48 schema: z.object({ name: z.string(), age: z.number() }),49 run: async (payload) => { /* payload is typed and validated */ },50});51```5253### Scheduled Task (Cron)54```typescript55import { schedules } from "@trigger.dev/sdk";5657export const dailyCleanup = schedules.task({58 id: "daily-cleanup",59 cron: "0 0 * * *",60 run: async (payload) => {61 // payload.timestamp, payload.lastTimestamp, payload.timezone62 },63});64```6566### Trigger from Backend67```typescript68import { tasks } from "@trigger.dev/sdk";69import type { myTask } from "~/trigger/my-task";7071const handle = await tasks.trigger<typeof myTask>("my-task", { data: "hello" });72```7374### Trigger from Inside a Task75```typescript76const result = await otherTask.triggerAndWait({ data: "hello" });77if (result.ok) console.log(result.output);78```7980## Critical Rules81821. **Task IDs must be unique** across the entire project832. **Payloads and return values must be JSON serializable** — no classes, functions, or circular refs843. **Always export tasks** from trigger files (unexported tasks become hidden/internal-only)854. **Use type-only imports** when triggering from backend: `import type { myTask } from "~/trigger/my-task"`865. **trigger.config.ts must be at the project root** — it cannot be nested876. **Use `AbortTaskRunError`** to fail without retrying on permanent errors887. **Wait functions are free** — tasks checkpoint during waits, no compute charges898. **Concurrency limits only count actively executing runs** — delayed/waiting runs don't count909. **Max 10 tags per run**, max 256KB metadata per run, max 1000 items per batch9110. **Use `idempotencyKeys.create()`** inside tasks to prevent duplicate child triggers during retries9211. **Use the `mcp__trigger__search_docs` tool** to look up the latest docs when unsure about any API9312. **Use `mcp__trigger__deploy`** to deploy tasks, **`mcp__trigger__list_runs`** to check runs, **`mcp__trigger__trigger_task`** to trigger tasks9495## Machine Presets9697| Preset | vCPU | RAM |98|--------|------|-----|99| micro | 0.25 | 0.25 GB |100| small-1x (default) | 0.5 | 0.5 GB |101| small-2x | 1 | 1 GB |102| medium-1x | 1 | 2 GB |103| medium-2x | 2 | 4 GB |104| large-1x | 4 | 8 GB |105| large-2x | 8 | 16 GB |106107## Key SDK Imports108109```typescript110import {111 task, schemaTask, schedules, batch, tasks, runs, queues,112 tags, metadata, wait, auth, idempotencyKeys, logger, streams,113 AbortTaskRunError, configure, query,114} from "@trigger.dev/sdk";115import { ai } from "@trigger.dev/sdk/ai";116```117118Use `$ARGUMENTS` to understand what the user wants to build. Read the reference files for detailed patterns before writing code.