Claude Templates / A-tier · High leverage
Infrastructure
The Trigger.dev Worker Playbook
The three-file pattern for anything that can't finish inside an HTTP request.
TRIGGER-DEV-WORKER-PLAYBOOK.md · 12 sections · 2,590 words · 21 KB · markdown
By Moe Ameen, founder of BILT · Published · Updated
The Trigger.dev Worker Playbook starts from one rule: any flow that can run longer than about 60 seconds must be a Trigger.dev worker. It gives Claude Code a three-file pattern (worker, dispatch route, browser bridge), charges credits in the dispatch before the task starts, refunds on failure, recovers orphaned jobs when a page remounts, and adds a rule to redeploy workers when their code changes.
Key takeaways
- Over ~60 seconds, it's a worker. The file lists slow providers, ffmpeg and 3+ chained calls.
- Three files per job: worker, dispatch route, browser bridge.
- Charge in the dispatch, never inside the worker.
- Vercel deploys don't update workers; the file makes redeploys a rule.
Any task that can exceed 60 seconds has to leave the request cycle. This is the pattern for doing it without losing work: a worker, a dispatch route, and a bridge: plus orphan recovery, refund-on-failure, and mount-time resume so a closed browser tab doesn't strand a job.
What does the Trigger.dev Worker Playbook build?
It builds a repeatable way to run long jobs outside the request cycle: a worker in src/trigger, a dispatch route that charges and triggers, and a bridge that hands the run ID back to the page.
It adds a generic job-status endpoint, worker self-heal and an audit cron for orphaned charges.
When should you reach for a background worker?
Reach for it the moment a task can exceed 60 seconds or calls a slow provider. The file bans browser-bound generation routes because a closed tab orphans the job.
Short, fast API calls don't need it and are simpler as normal routes.
What do you need first?
You need App Infrastructure and a Trigger.dev project with its secret key and project ref. If the job costs credits, run Credit Metering too.
Expect to set environment variables in Trigger.dev separately from Vercel.
What's inside
What does the playbook give you?
- //The three-file pattern (worker + dispatch + bridge) with full code
- //Refund-on-failure so a crashed job doesn't eat a user's credits
- //Orphan recovery for jobs whose callback never landed
- //Mount-time resume: the UI reattaches to an in-flight job
- //Deploy discipline: when a Vercel push also needs a worker redeploy
When to use it
The moment a task can exceed 60 seconds.
Build these first
Unlocks
Straight from the file
What does the writing look like?
Browser-bound generation paths and /api/generate-style routes that await long providers are banned. Tab close mid-render orphans the pipeline row, burns credit, and silently corrupts state. The pattern below eliminates that entire class of bug.
Table of contents
Which sections does the file cover?
- 0. The universal rule
- 1. Use this spec
- 2. Architecture
- 3. The three-file pattern
- 4. Worker self-heal (Vara incident pattern)
- 5. Generic status endpoint — [/api/jobs/[runId]/route.ts](file:///<reference-app>/src/app/api/jobs/[runId]/route.ts)
- 6. trigger.config.ts — build extensions
- 7. Mount-time orphan recovery (pipeline page wiring)
- 8. Auto-deploy rule (mandatory)
- 9. The audit-orphan-charges cron (final safety net)
- 10. Common pitfalls
- 11. Kickoff prompt
How do you run it?
Drop TRIGGER-DEV-WORKER-PLAYBOOK.md into your repo, then tell Claude Code: “Read TRIGGER-DEV-WORKER-PLAYBOOK.md and implement it in this codebase.” It's written for an agent to execute end to end. Search the file for angle-bracket placeholders and swap in your own project names, domains, and keys before the first run.
Who is this for, and who should skip it?
Best for
- AI and media apps with renders, transcriptions or batch jobs
- Any app where users can close the tab mid-task
- Apps already on Trigger.dev v4
Not ideal for
- Apps whose every request finishes in a few seconds
- Teams on a different queue (Inngest, BullMQ, SQS) who won't switch
- Serverless setups that can't run a separate worker deployment
- Builders who won't adapt paths: the file points to a reference app you won't have
What else do people ask?
What inputs does the Trigger.dev Worker Playbook ask for?
The Trigger.dev Worker Playbook asks for five things: a kebab-case kind slug, the provider chain the task runs, the credit cost (or "no charge"), the maximum expected wall time, and whether it needs native modules like ffmpeg, ONNX or sharp. Wall time sets maxDuration, and the native-module answer decides which build extensions go into trigger.config.ts.
Does it work outside Next.js, Supabase and Vercel?
The Trigger.dev Worker Playbook is written for Trigger.dev v4 inside a Next.js app, with dispatch routes under src/app/api, a Supabase service-role client in the worker and Vercel env vars synced through syncVercelEnvVars. It doesn't describe a version for other frameworks, databases or hosts.
Can I use it for jobs that don't charge credits?
Yes. The Trigger.dev Worker Playbook includes a triggerWithoutCredit helper for free and regen flows that handles auth, rate limiting and the trigger with no credit step. Paid flows use triggerWithCredit, which charges before tasks.trigger and refunds right away if the trigger throws.
What is in the Trigger.dev Worker Playbook download?
The Trigger.dev Worker Playbook is a markdown file of about 2,600 words. It has TypeScript for the worker, dispatch route, browser bridge, self-heal call, trigger.config.ts and mount-time recovery, plus a file tree, the deploy command and a kickoff prompt. There are no SQL migrations in it.
Why is maxAttempts set to 1?
The Trigger.dev Worker Playbook sets maxAttempts to 1 because automatic retries pay the provider twice. The worker wraps its body in a try/catch that refunds the credit and rethrows, and the refund is idempotent on taskRunId through a unique index on credit_refunds.
How do we know this?
This page is based on the playbook file itself, TRIGGER-DEV-WORKER-PLAYBOOK.md, which Moe Ameen wrote from the Kompozy codebase (called BKE in the file). We read the file on November 4, 2026; the facts here come from it, not from independent testing in other codebases.
More infrastructure playbooks
Email Infrastructure
Postmark, the SPF/DKIM/DMARC recipe, drip campaigns, and transactional vs marketing routing.
Read + download →B-tierWebhook Receiver
Receiving third-party webhooks (and sending your own) without losing events.
Read + download →B-tierScheduler Engine
One queue for every future-dated action: drips, reminders, scheduled sends.
Read + download →