The Trigger.dev CLI (trigger.dev) is the primary command-line interface for managing Trigger.dev projects. It handles project initialization, local development, and production deployments. The CLI orchestrates the build pipeline, coordinates with the webapp API, and manages Docker image creation for task workers.
For information about task definition and the SDK API, see Task Definition API. For deployment infrastructure and Docker builds, see Docker Build Pipeline and Deployment Process.
The CLI is distributed as the trigger.dev npm package located at packages/cli-v3/package.json1-162 The package provides a single binary command trigger that dispatches to various subcommands.
Key Metadata:
| Property | Value |
|---|---|
| Package Name | trigger.dev |
| Binary Command | trigger |
| Entry Point | ./dist/esm/index.js |
| Required Node Version | >=18.20.0 |
| Type | ESM module |
The CLI depends on several internal packages:
@trigger.dev/build - Build system and extensions@trigger.dev/core - Core utilities and schemas@trigger.dev/schema-to-json - JSON schema conversionExternal Dependencies:
The CLI uses specialized libraries for its operations:
@depot/cli - Remote Docker builds via Depot serviceesbuild - JavaScript/TypeScript bundlingchokidar - File watching for dev modecommander - Command-line argument parsingsocket.io-client - Real-time communication with webapp@s2-dev/streamstore - Log streaming during deploymentsSources: packages/cli-v3/package.json1-162
Primary Commands
Sources: packages/cli-v3/CHANGELOG.md1-1000
The init command scaffolds a new Trigger.dev project by creating the configuration file and initial task structure.
Workflow:
trigger.config.ts with project reference./trigger)Configuration Options:
The generated trigger.config.ts file uses the defineConfig function and includes:
project - Project reference ID (from environment or prompt)dirs - Array of directories containing task filesbuild - Build extensions (optional)runtime - Node.js runtime version (default: "node")retries - Global retry configurationmaxDuration - Maximum task duration in secondsExample Generated Config:
Dependencies Installed:
The command automatically installs (via nypm package manager detection):
@trigger.dev/sdk - Latest v4 SDKSources: packages/cli-v3/CHANGELOG.md180-186 packages/core/package.json1-100
The dev command runs a local development server that executes tasks in response to trigger requests. It provides hot-reloading, real-time logs, and debugging capabilities.
Architecture Components:
| Component | Location | Role |
|---|---|---|
| DevSupervisor | apps/supervisor | Coordinates task execution |
| TaskRunProcessPool | apps/supervisor | Manages child processes |
| TaskRunProcess | apps/supervisor | Individual task execution |
| esbuild | packages/cli-v3 | Bundles TypeScript tasks |
| Socket.io client | packages/cli-v3 | Communicates with webapp |
Key Features:
chokidar) detects changes and triggers rebuild.trigger/ directory to reduce disk usageexperimental_processKeepAlive is enabledEnvironment Variables:
The dev command recognizes these environment variables:
TRIGGER_PROJECT_REF - Project reference IDTRIGGER_ACCESS_TOKEN - Personal access token for authenticationTRIGGER_SECRET_KEY - Alternative auth methodOTEL_EXPORTER_OTLP_ENDPOINT - External telemetry endpointConfiguration Options:
From trigger.config.ts:
dirs - Task directories to watch and buildbuild.extensions - Build-time modifications (see Build Extensions)build.external - Packages to exclude from bundlebuild.keepNames - Preserve function names for debugging (default: true)build.minify - Minify output (experimental)experimental_processKeepAlive - Reuse worker processes between runstelemetry.exporters - OpenTelemetry trace exporterstelemetry.logExporters - OpenTelemetry log exportersProcess Working Directory:
By default, process.cwd() in tasks points to the project root. Setting legacyDevProcessCwdBehaviour: false changes it to the build directory (.trigger/.trigger-*), which affects relative file paths.
Sources: packages/cli-v3/CHANGELOG.md155-162 packages/cli-v3/CHANGELOG.md287-289 packages/core/CHANGELOG.md68-74
The deploy command builds a Docker image containing your tasks and deploys it to the Trigger.dev platform. It supports both local and remote builds.
Deployment Stages:
| Stage | Status | Description |
|---|---|---|
| Initialize | PENDING | Create deployment record in database |
| Install | INSTALLING | Install dependencies (native build only) |
| Build | BUILDING | Create Docker image |
| Push | DEPLOYING | Upload to container registry |
| Index | DEPLOYING | Extract task metadata from image |
| Finalize | DEPLOYED | Activate deployment for traffic |
Build Strategies:
1. Remote Build (Default - Depot)
Uses the @depot/cli package to build on Depot's infrastructure:
2. Local Build (--local-build)
Builds using local Docker daemon:
docker buildx build for multi-platform supportBUILDX_CACHE_FROM/BUILDX_CACHE_TO env vars3. Native Build Server (--native-build-server)
Delegates building to the Trigger.dev platform:
TRIGGER_EXISTING_DEPLOYMENT_ID to attach to pre-created deploymentDocker Image Structure:
The Dockerfile uses multi-stage builds (see Docker Build Pipeline):
pruner - Isolates workspace dependenciesbase - Base Node.js runtime imagedev-deps - Development dependencies for buildingbuilder - Compiles TypeScript and bundles tasksrunner - Final minimal runtime imageRegistry Configuration:
Images are pushed to container registries configured by the webapp:
Environment Variable Synchronization:
The CLI can automatically sync environment variables during deployment:
syncEnvVars() build extension - Syncs from webapp APIsyncVercelEnvVars() - Syncs from Vercel project environmentsyncNeonEnvVars() - Syncs from Neon database projectDeployment Metadata:
The deployment record includes:
triggeredVia - Deployment source ("CLI", "GitHub Action", etc.)Image Compression:
Since v4.3.0, deployments use zstd compression for Docker layers, reducing image size and push/pull times.
Error Handling:
TRIGGER_ACCESS_TOKEN in CI fails fast with helpful error message--local-build flagSources: packages/cli-v3/CHANGELOG.md28-33 packages/core/CHANGELOG.md49-50 packages/cli-v3/CHANGELOG.md7-8 packages/cli-v3/CHANGELOG.md187-195
The whoami command displays authentication information and project details.
Output Information:
API Endpoint:
Calls GET /api/v1/whoami to retrieve information. The server authenticates using the API key or personal access token from the request headers.
Usage Scenarios:
Sources: apps/webapp/app/routes/api.v1.whoami.ts1-34 packages/cli-v3/CHANGELOG.md174-177
The switch command changes the active CLI profile, allowing developers to work with multiple projects or environments.
Functionality:
trigger switch production)xdg-app-paths)Related Configuration:
CLI profiles are stored per-user and persist across terminal sessions. Each profile stores:
Sources: packages/cli-v3/CHANGELOG.md189-195 packages/cli-v3/CHANGELOG.md270-272
The update command checks for and installs newer versions of Trigger.dev packages.
Version Detection:
@trigger.dev/* dependenciesUpdate Process:
fast-npm-meta packagenypm to install updates (detects npm/yarn/pnpm/bun)Error Prevention:
The command includes safeguards against:
Sources: packages/cli-v3/CHANGELOG.md162-164 packages/cli-v3/CHANGELOG.md180-182
login:
Authenticates the CLI with the Trigger.dev platform:
logout:
Clears stored credentials:
Sources: packages/cli-v3/CHANGELOG.md270-272
The trigger.config.ts file is the central configuration for CLI behavior and task execution. It uses the defineConfig function exported from @trigger.dev/sdk/v3.
Core Options:
Build Extensions:
Extensions modify the Docker image or build process. Built-in extensions include:
prismaExtension() - Prisma client generation and migrationspuppeteer() - Chromium browser installationplaywright() - Playwright browser binariesaudioWaveform() - Audio processing toolsffmpeg() - Video processing (v6 or v7)syncVercelEnvVars() - Sync environment variables from VercelsyncNeonEnvVars() - Sync from Neon databaseEnvironment-Specific Configuration:
Configuration can vary by environment using process.env:
OpenTelemetry Configuration:
External observability can be configured via exporters:
Resource Attributes:
Custom OpenTelemetry resource attributes can be set via config or environment variable:
Sources: packages/cli-v3/package.json83-149 packages/trigger-sdk/CHANGELOG.md14-16
CLI Dependencies Map:
| Dependency | Version | Purpose |
|---|---|---|
| commander | ^9.4.1 | CLI argument parsing |
| c12 | ^1.11.1 | Configuration loading |
| esbuild | ^0.23.0 | TypeScript bundling |
| chokidar | ^3.6.0 | File watching |
| socket.io-client | 4.7.5 | Real-time communication |
| @depot/cli | 0.0.1-cli.2.80.0 | Remote Docker builds |
| @s2-dev/streamstore | ^0.17.6 | Log streaming |
| eventsource | ^3.0.2 | SSE for build logs |
| semver | ^7.5.0 | Version comparisons |
| zod | 3.25.76 | Schema validation |
Sources: packages/cli-v3/package.json83-149
Global Flags:
Available for all commands:
--config <path> - Path to config file (default: ./trigger.config.ts)--project-ref <ref> - Override project reference from config--env <name> - Target environment (dev/staging/prod)--profile <name> - Use specific CLI profiledev Command Flags:
--port <port> - HTTP server port for health checks--hostname <host> - Bind to specific hostname--debugger - Enable Node.js debugger--skip-update-check - Don't check for CLI updatesdeploy Command Flags:
--env <name> - Target environment (required for prod/staging)--skip-typecheck - Skip TypeScript type checking--dry-run - Build image but don't deploy--save-logs - Save build logs even on success--push - Push image after dry-run build--local-build - Force local Docker build--native-build-server - Use platform build server--self-hosted - (Deprecated) No longer requiredEnvironment Variables:
CLI behavior can be controlled via environment variables:
| Variable | Purpose | Example |
|---|---|---|
TRIGGER_ACCESS_TOKEN | API authentication | tr_prod_abc123... |
TRIGGER_PROJECT_REF | Project reference | proj_abc123 |
TRIGGER_SECRET_KEY | Alternative auth | tr_dev_xyz... |
TRIGGER_API_URL | Custom API endpoint | https://api.trigger.dev |
TRIGGER_EXISTING_DEPLOYMENT_ID | Attach to deployment | dep_123 |
OTEL_RESOURCE_ATTRIBUTES | OpenTelemetry attributes | env=prod,version=1.0 |
BUILDX_CACHE_FROM | Docker cache source | type=registry,ref=... |
BUILDX_CACHE_TO | Docker cache target | type=registry,ref=... |
Sources: packages/cli-v3/CHANGELOG.md28-33 packages/core/CHANGELOG.md68-69 packages/cli-v3/CHANGELOG.md118-121
The CLI communicates with the webapp through multiple channels:
REST API Endpoints:
| Endpoint | Method | Purpose |
|---|---|---|
/api/v1/whoami | GET | Authentication check |
/api/v1/deployments | POST | Initialize deployment |
/api/v1/deployments/:id/index | POST | Upload task metadata |
/api/v1/deployments/:id | PUT | Finalize deployment |
/api/v1/projects/:ref/envvars | GET | Retrieve environment variables |
WebSocket Communication (dev mode):
The CLI uses Socket.io for real-time communication during local development:
Authentication Methods:
Personal Access Token (TRIGGER_ACCESS_TOKEN)
Authorization: Bearer headerSecret Key (TRIGGER_SECRET_KEY)
Worker Token
Sources: apps/webapp/app/routes/api.v1.whoami.ts1-34 packages/cli-v3/CHANGELOG.md214-215
The CLI includes an experimental MCP (Model Context Protocol) server for AI agent integration:
MCP Package Metadata:
Available Tools:
AI agents can interact with Trigger.dev via MCP tools:
Installation:
The trigger install-mcp command registers the CLI as an MCP server with supported AI tools (Claude Desktop, etc.).
Sources: packages/cli-v3/package.json15 packages/cli-v3/package.json80-81 packages/cli-v3/CHANGELOG.md144-146
Build Directory Structure:
.trigger/
├── .trigger-<hash>/ # Content-addressable build output
│ ├── index.js # Bundled task code
│ ├── index.js.map # Source maps
│ └── package.json # Runtime dependencies
├── metafile.json # esbuild metafile (with --dry-run)
└── logs/ # Build logs
Content-Addressable Storage:
Since v4.2.0, the dev CLI uses content-addressable storage for build outputs:
.trigger/.trigger-<hash>/Bundle Analysis:
The CLI provides detailed bundle analysis:
Cache Strategies:
For deployments with --local-build:
BUILDX_CACHE_FROM - Load cache from registry or localBUILDX_CACHE_TO - Export cache to registry or localSources: packages/cli-v3/CHANGELOG.md31-32 packages/cli-v3/CHANGELOG.md180-181
Common Error Scenarios:
Missing Authentication:
trigger login or set TRIGGER_ACCESS_TOKENMissing Configuration:
maxDuration to trigger.config.ts--config flag for custom locationsBuild Failures:
--local-build flag on upstream provider outagesDeployment Stuck:
Debug Options:
DEBUG=trigger:* - Enable debug logging (uses debug package)--save-logs - Keep build logs even on successkeepNames: true preserves function names for debuggingGraceful Shutdown:
The CLI handles signals properly:
Sources: packages/cli-v3/CHANGELOG.md82-84 packages/cli-v3/CHANGELOG.md213-214 packages/cli-v3/CHANGELOG.md267-271
Refresh this wiki