|
| 1 | +--- |
| 2 | +name: getting-started |
| 3 | +description: > |
| 4 | + Bootstrap Trigger.dev into an existing project from scratch: authenticate the |
| 5 | + CLI, install @trigger.dev/sdk and @trigger.dev/build, write trigger.config.ts |
| 6 | + with the project ref and task dirs, scaffold a /trigger directory with a first |
| 7 | + task, wire tsconfig and .gitignore, set TRIGGER_SECRET_KEY, and run the dev |
| 8 | + server. Load this when a project has no trigger.config.ts yet and the user |
| 9 | + asks to "add Trigger.dev", "set up Trigger.dev", "initialize Trigger.dev", or |
| 10 | + get a first task running, including in a monorepo. Once the project is set up |
| 11 | + and you are writing task code, switch to the authoring-tasks skill. |
| 12 | +type: core |
| 13 | +library: trigger.dev |
| 14 | +library_version: "{{TRIGGER_SDK_VERSION}}" |
| 15 | +sources: |
| 16 | + - docs/quick-start.mdx |
| 17 | + - docs/manual-setup.mdx |
| 18 | + - docs/config/config-file.mdx |
| 19 | + - docs/triggering.mdx |
| 20 | +--- |
| 21 | + |
| 22 | +# Getting started with Trigger.dev |
| 23 | + |
| 24 | +Set up Trigger.dev in an existing project. The end state is: the SDK installed, a |
| 25 | +`trigger.config.ts` pointing at a project ref, a `/trigger` directory with at least |
| 26 | +one exported task, and `trigger dev` running so the task shows up in the dashboard. |
| 27 | + |
| 28 | +The fastest path is the CLI's own wizard, which performs every mechanical step below |
| 29 | +and also offers to install the MCP server and these agent skills: |
| 30 | + |
| 31 | +```bash |
| 32 | +npx trigger.dev@latest init |
| 33 | +``` |
| 34 | + |
| 35 | +Prefer `init` when you can. Do the manual steps further down when `init` does not fit |
| 36 | +(monorepos, an existing config to extend, or a non-interactive environment). |
| 37 | + |
| 38 | +## Two steps need the human |
| 39 | + |
| 40 | +Most of setup is automatable, but two steps require a person and cannot be done |
| 41 | +headlessly. When you reach them, stop and ask the user to do them, then continue: |
| 42 | + |
| 43 | +1. **Authenticating the CLI.** `npx trigger.dev@latest login` opens a browser for the |
| 44 | + user to sign in. If they have no account, point them to https://cloud.trigger.dev |
| 45 | + (or a self-hosted instance) first. You cannot complete this for them. |
| 46 | +2. **The secret key and project ref.** `TRIGGER_SECRET_KEY` and the project ref |
| 47 | + (`proj_...`) come from the dashboard. Ask the user to copy the **DEV** secret key |
| 48 | + from the project's API Keys page, and to pick or create the project so you have its |
| 49 | + ref. `trigger init` can select the project interactively once the user is logged in. |
| 50 | + |
| 51 | +Treat these as handoffs: state exactly what you need, wait for the user, then resume. |
| 52 | + |
| 53 | +## Manual setup |
| 54 | + |
| 55 | +### 1. Authenticate (human step) |
| 56 | + |
| 57 | +```bash |
| 58 | +npx trigger.dev@latest login |
| 59 | +# self-hosted: |
| 60 | +npx trigger.dev@latest login --api-url https://your-trigger-instance.com |
| 61 | +``` |
| 62 | + |
| 63 | +### 2. Install the packages |
| 64 | + |
| 65 | +`@trigger.dev/sdk` is a runtime dependency; `@trigger.dev/build` is a dev dependency. |
| 66 | +Pin both to the same version as the `trigger.dev` CLI you run; the CLI warns on a |
| 67 | +mismatch during `dev`/`deploy`. |
| 68 | + |
| 69 | +```bash |
| 70 | +npm add @trigger.dev/sdk@latest |
| 71 | +npm add --save-dev @trigger.dev/build@latest |
| 72 | +``` |
| 73 | + |
| 74 | +### 3. Write `trigger.config.ts` |
| 75 | + |
| 76 | +Create it in the project root (or `trigger.config.mjs` for JavaScript). The `project` |
| 77 | +ref and `dirs` are the only required fields. |
| 78 | + |
| 79 | +```ts |
| 80 | +import { defineConfig } from "@trigger.dev/sdk"; |
| 81 | + |
| 82 | +export default defineConfig({ |
| 83 | + project: "<project ref>", // e.g. "proj_abc123", from the dashboard |
| 84 | + dirs: ["./src/trigger"], // where your tasks live |
| 85 | + maxDuration: 3600, |
| 86 | + retries: { |
| 87 | + enabledInDev: false, |
| 88 | + default: { maxAttempts: 3, factor: 2, minTimeoutInMs: 1000, maxTimeoutInMs: 10000, randomize: true }, |
| 89 | + }, |
| 90 | +}); |
| 91 | +``` |
| 92 | + |
| 93 | +Use the Bun runtime by adding `runtime: "bun"`. Build extensions (`prismaExtension`, |
| 94 | +`puppeteer`, `additionalFiles`, etc.) come from `@trigger.dev/build` and go in |
| 95 | +`build.extensions`. |
| 96 | + |
| 97 | +### 4. Add a first task |
| 98 | + |
| 99 | +Create the directory that matches `dirs` and export a task from it. Every task must be |
| 100 | +a named export with a project-unique `id`. |
| 101 | + |
| 102 | +```ts |
| 103 | +// src/trigger/example.ts |
| 104 | +import { task } from "@trigger.dev/sdk"; |
| 105 | + |
| 106 | +export const helloWorld = task({ |
| 107 | + id: "hello-world", |
| 108 | + run: async (payload: { name: string }) => { |
| 109 | + return { message: `Hello ${payload.name}!` }; |
| 110 | + }, |
| 111 | +}); |
| 112 | +``` |
| 113 | + |
| 114 | +### 5. Wire tsconfig and gitignore |
| 115 | + |
| 116 | +Add `trigger.config.ts` to the `include` array in `tsconfig.json`, and add `.trigger` |
| 117 | +to `.gitignore` (the CLI writes local dev state there). |
| 118 | + |
| 119 | +```jsonc |
| 120 | +// tsconfig.json |
| 121 | +{ "include": ["trigger.config.ts" /* ...existing */] } |
| 122 | +``` |
| 123 | + |
| 124 | +```bash |
| 125 | +# .gitignore |
| 126 | +.trigger |
| 127 | +``` |
| 128 | + |
| 129 | +### 6. Set the secret key (human step) |
| 130 | + |
| 131 | +For triggering from your own code, set `TRIGGER_SECRET_KEY` to the DEV key from the |
| 132 | +dashboard's API Keys page. Self-hosted users also set `TRIGGER_API_URL`. |
| 133 | + |
| 134 | +```bash |
| 135 | +# .env (or .env.local for Next.js) |
| 136 | +TRIGGER_SECRET_KEY=tr_dev_xxxxxxxx |
| 137 | +``` |
| 138 | + |
| 139 | +### 7. Run the dev server |
| 140 | + |
| 141 | +```bash |
| 142 | +npx trigger.dev@latest dev |
| 143 | +``` |
| 144 | + |
| 145 | +Leave it running. Tasks register with the dashboard, where the user can fire a test run |
| 146 | +from the task's test page. On first run the CLI offers to install the MCP server and |
| 147 | +agent skills; recommend both. |
| 148 | + |
| 149 | +## Triggering from your app |
| 150 | + |
| 151 | +Once a task exists, trigger it from backend code with a **type-only** import so the |
| 152 | +task code is never bundled into your app. Trigger by id, not by calling the task object. |
| 153 | + |
| 154 | +```ts |
| 155 | +import { tasks } from "@trigger.dev/sdk"; |
| 156 | +import type { helloWorld } from "@/trigger/example"; // type-only |
| 157 | + |
| 158 | +const handle = await tasks.trigger<typeof helloWorld>("hello-world", { name: "Ada" }); |
| 159 | +``` |
| 160 | + |
| 161 | +`TRIGGER_SECRET_KEY` must be set wherever this runs. Framework specifics live in the |
| 162 | +Next.js / Remix / Node.js guides. |
| 163 | + |
| 164 | +## Monorepos |
| 165 | + |
| 166 | +Two layouts, both supported: put tasks in a shared package (`@repo/tasks` with its own |
| 167 | +`trigger.config.ts`, consumed via `workspace:*`), or install Trigger.dev directly in the |
| 168 | +app that needs it. Run `trigger dev` from the directory that holds `trigger.config.ts`. |
| 169 | +See the manual setup docs for full Turborepo examples before scaffolding either. |
| 170 | + |
| 171 | +## Common mistakes |
| 172 | + |
| 173 | +1. **Trying to do the human-only steps headlessly.** You cannot complete `trigger login` |
| 174 | + or read the dashboard secret key for the user. |
| 175 | + - Wrong: spawning `trigger login` and waiting on it to finish in an agent session. |
| 176 | + - Correct: ask the user to log in and to paste the DEV key, then continue. |
| 177 | + |
| 178 | +2. **Mismatched CLI and SDK versions.** A `trigger.dev` CLI on a different major than |
| 179 | + `@trigger.dev/sdk` breaks dev/deploy. |
| 180 | + - Wrong: `npx trigger.dev@latest dev` against an old pinned SDK. |
| 181 | + - Correct: keep `trigger.dev`, `@trigger.dev/sdk`, and `@trigger.dev/build` on the same version. |
| 182 | + |
| 183 | +3. **Importing from `@trigger.dev/sdk/v3` or using `client.defineJob()`.** Both are old. |
| 184 | + - Correct: always import from `@trigger.dev/sdk`; define work with `task()`. |
| 185 | + |
| 186 | +4. **Tasks not exported, or outside `dirs`.** A task that is not a named export inside a |
| 187 | + configured directory will not be picked up. |
| 188 | + - Correct: `export const ... = task({ ... })` in a file under a `dirs` path. |
| 189 | + |
| 190 | +5. **Importing the task instance into backend code.** This bundles the task. |
| 191 | + - Wrong: `import { helloWorld } from "@/trigger/example"` in a route handler. |
| 192 | + - Correct: `import type { helloWorld }` plus `tasks.trigger<typeof helloWorld>("hello-world", payload)`. |
| 193 | + |
| 194 | +6. **Forgetting `TRIGGER_SECRET_KEY`.** Triggering from your app fails without it; the |
| 195 | + `dev` server itself works once the CLI is logged in. |
| 196 | + |
| 197 | +## References |
| 198 | + |
| 199 | +Sibling skills: |
| 200 | + |
| 201 | +- **authoring-tasks** for writing the tasks themselves once setup is done: retries, waits, |
| 202 | + queues, scheduled tasks, triggering, and the full `trigger.config.ts`. |
| 203 | +- **realtime-and-frontend** for showing live run status in a frontend. |
| 204 | +- **authoring-chat-agent** and **chat-agent-advanced** for building AI chat agents. |
| 205 | + |
| 206 | +Docs: |
| 207 | + |
| 208 | +- [Quick start](https://trigger.dev/docs/quick-start) |
| 209 | +- [Manual setup](https://trigger.dev/docs/manual-setup) |
| 210 | +- [Configuration file](https://trigger.dev/docs/config/config-file) |
| 211 | + |
| 212 | +## Version |
| 213 | + |
| 214 | +Generated for @trigger.dev/sdk {{TRIGGER_SDK_VERSION}}. Re-run the trigger.dev skills installer after upgrading. |
0 commit comments