Programmatic configuration

Last updated Sep 29, 2026 cloudflare.config.ts is the typed configuration file for a Workers project. Its default export can define a Worker, Container applications, and account settings. Because the file is a TypeScript module, it can use imports, functions, environment variables, and asynchronous values.

Open beta

Programmatic configuration with cloudflare.config.ts is in open beta. The configuration format can change before the stable release.

Loading cloudflare.config.ts requires Node.js 22.18 or later. Bun is not supported: when cf runs on Bun, loading the file fails with cloudflare.config.ts loading is not supported on Bun. Most cf commands load the nearest cloudflare.config.ts, including commands that only call the Cloudflare API, so this is the practical minimum for any cf command you run inside the project.

Set "type": "module" in the project's package.json. Without it, Node.js prints a warning each time it loads the file. With "type": "commonjs", loading fails with Cannot use import statement outside a module.

Create the minimum configuration

Import the configuration helpers from cf/config. Add cf as a development dependency so the project can resolve that import. Projects created with cf init already include it.

npmyarnpnpmbun

npm i -D cf
yarn add -D cf
pnpm add -D cf
bun add -d cf

A Worker requires name and compatibilityDate. A Worker that runs code also requires entrypoint.

Select a highlighted line to show its type and description below it.

cloudflare.config.ts

Expand allCopy

import { defineConfig } from "cf/config";

import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };

<details>

<summary>export default defineConfig({ (defineConfig reference)</summary>

<code>defineConfig</code>Function<a href="#config-minimum-defineconfig">Link to defineConfig</a>

<code>defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;</code>

Defines the default export of <code>cloudflare.config.ts</code>. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (<code>isPreview</code> and <code>mode</code>) and returns either.

<details>

<summary>Options (4)</summary>

<dl>

<dt><code>accountId?: string</code></dt> <dd>This is the ID of the account associated with your zone. It can also be specified through the <code>CLOUDFLARE_ACCOUNT_ID</code> environment variable.</dd>

<dt><code>complianceRegion?: "public" | "fedramp-high"</code></dt> <dd>The compliance boundary in which commands should operate. When omitted, this can be supplied through <code>CLOUDFLARE_COMPLIANCE_REGION</code>.</dd>

<dt><code>worker?: ConfigInput<WorkerConfig></code></dt> <dd>The Worker defined by this configuration.</dd>

<dt><code>containers?: ConfigInput<ContainerConfig>[]</code></dt> <dd>Container applications defined by this configuration.</dd></dl></details>

</details>

<details>

<summary>worker: { (worker reference)</summary>

<code>worker</code>Optional<a href="#config-minimum-cloudflareconfig-worker">Link to worker</a>

<code>worker?: ConfigInput<WorkerConfig></code>

The Worker defined by this configuration.

</details>

<details>

<summary>name: "example-worker", (name reference)</summary>

<code>name</code>Required<a href="#config-minimum-workerconfig-name">Link to name</a>

<code>name: string</code>

The name of your Worker.

</details>

<details>

<summary>entrypoint, (entrypoint reference)</summary>

<code>entrypoint</code>Optional<a href="#config-minimum-workerconfig-entrypoint">Link to entrypoint</a>

<code>entrypoint?: string | WorkerModule</code>

The entrypoint module that will be executed. May be either a path string (e.g. <code>"./src/index.ts"</code>) or a module namespace imported with the <code>cf-worker</code> import attribute.

</details>

<details>

<summary>compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)</summary>

<code>compatibilityDate</code>Required<a href="#config-minimum-workerconfig-compatibilitydate">Link to compatibilityDate</a>

<code>compatibilityDate: string</code>

A date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at <a href="https://developers.cloudflare.com/workers/configuration/compatibility-dates">https://developers.cloudflare.com/workers/configuration/compatibility-dates</a>

</details>

},

});

The cf-worker import attribute lets TypeScript infer the Worker module, binding types, and exported classes.

An assets-only Worker can omit entrypoint. Its build implementation must provide the asset source. A deployable build must contain a Worker bundle, static assets, or both.

cloudflare.config.ts does not have an assets.directory field. In Vite projects, the static assets are the output of Vite's client build, which includes Vite's publicDir directory (public by default). Projects that build with Wrangler set the directory in a generated wrangler.config.ts file. For details, refer to How cf runs your project.

Understand the default export

Use defineConfig() for the default export. The helper returns the value you pass to it and preserves literal values for TypeScript inference.

Field Required Purpose
accountId No Sets the default account for cf commands
complianceRegion No Selects public or fedramp-high
worker Development and builds Defines the Worker
containers No Defines Container applications

cf API commands can read an account-only default export. The Cloudflare Vite plugin and Wrangler require worker for development and builds.

Use the configuration explorer to inspect the generated fields, builder methods, and nested options.

Select a highlighted line to show its type and description below it.

cloudflare.config.ts

Expand allCopy

import { bindings, defineConfig, triggers } from "cf/config";

import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };

<details>

<summary>export default defineConfig(({ mode }) => { (defineConfig, mode reference)</summary>

<code>defineConfig</code>Function<a href="#config-default-export-defineconfig">Link to defineConfig</a>

<code>defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;</code>

Defines the default export of <code>cloudflare.config.ts</code>. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (<code>isPreview</code> and <code>mode</code>) and returns either.

<details>

<summary>Options (4)</summary>

<dl>

<dt><code>accountId?: string</code></dt> <dd>This is the ID of the account associated with your zone. It can also be specified through the <code>CLOUDFLARE_ACCOUNT_ID</code> environment variable.</dd>

<dt><code>complianceRegion?: "public" | "fedramp-high"</code></dt> <dd>The compliance boundary in which commands should operate. When omitted, this can be supplied through <code>CLOUDFLARE_COMPLIANCE_REGION</code>.</dd>

<dt><code>worker?: ConfigInput<WorkerConfig></code></dt> <dd>The Worker defined by this configuration.</dd>

<dt><code>containers?: ConfigInput<ContainerConfig>[]</code></dt> <dd>Container applications defined by this configuration.</dd></dl></details>

<code>mode</code>Context value<a href="#config-default-export-defineconfig">Link to mode</a>

<code>mode: string | undefined</code>

The mode the config is being evaluated in. Set via the <code>--mode</code> CLI flag. In Vite the mode defaults to <code>development</code> in <code>vite dev</code> and <code>production</code> in <code>vite build</code> (<a href="https://vite.dev/guide/env-and-mode.html#modes">more info</a>). In Wrangler the mode defaults to <code>undefined</code>.

</details>

const isStaging = mode === "staging";

return {

<details>

<summary>accountId: "<ACCOUNT_ID>", (accountId reference)</summary>

<code>accountId</code>Optional<a href="#config-default-export-settings-accountid">Link to accountId</a>

<code>accountId?: string</code>

This is the ID of the account associated with your zone. It can also be specified through the <code>CLOUDFLARE_ACCOUNT_ID</code> environment variable.

</details>

<details>

<summary>complianceRegion: "public", (complianceRegion reference)</summary>

<code>complianceRegion</code>Optional<a href="#config-default-export-settings-complianceregion">Link to complianceRegion</a>

<code>complianceRegion?: "public" | "fedramp-high"</code>

The compliance boundary in which commands should operate. When omitted, this can be supplied through <code>CLOUDFLARE_COMPLIANCE_REGION</code>.

</details>

<details>

<summary>worker: { (worker reference)</summary>

<code>worker</code>Optional<a href="#config-default-export-cloudflareconfig-worker">Link to worker</a>

<code>worker?: ConfigInput<WorkerConfig></code>

The Worker defined by this configuration.

</details>

<details>

<summary>name: isStaging ? "example-staging" : "example-worker", (name reference)</summary>

<code>name</code>Required<a href="#config-default-export-workerconfig-name">Link to name</a>

<code>name: string</code>

The name of your Worker.

</details>

<details>

<summary>entrypoint, (entrypoint reference)</summary>

<code>entrypoint</code>Optional<a href="#config-default-export-workerconfig-entrypoint">Link to entrypoint</a>

<code>entrypoint?: string | WorkerModule</code>

The entrypoint module that will be executed. May be either a path string (e.g. <code>"./src/index.ts"</code>) or a module namespace imported with the <code>cf-worker</code> import attribute.

</details>

<details>

<summary>compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)</summary>

<code>compatibilityDate</code>Required<a href="#config-default-export-workerconfig-compatibilitydate">Link to compatibilityDate</a>

<code>compatibilityDate: string</code>

A date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at <a href="https://developers.cloudflare.com/workers/configuration/compatibility-dates">https://developers.cloudflare.com/workers/configuration/compatibility-dates</a>

</details>

<details>

<summary>env: { (env reference)</summary>

<code>env</code>Optional<a href="#config-default-export-workerconfig-env">Link to env</a>

<code>env?: Record<string, Binding | false | null | undefined></code>

Bindings exposed on the Worker's <code>env</code> object. Construct entries with <code>bindings.kv(...)</code>, <code>bindings.r2(...)</code>, etc. Entries set to <code>false</code>, <code>null</code>, or <code>undefined</code> are omitted, which allows bindings to be included conditionally.

</details>

<details>

<summary>MESSAGE: bindings.text(isStaging ? "staging" : "production"), (text reference)</summary>

<code>text</code>Builder<a href="#config-default-export-bindings-text-default">Link to text</a>

<code>text<T$1 extends string>(value: T$1): TextBinding<T$1>;</code>

Inline string value made available to the Worker on <code>env</code> under the binding name. For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables">https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables</a>

</details>

},

<details>

<summary>triggers: [triggers.scheduled({ schedule: "0 * * * *" })], (triggers, scheduled, schedule reference)</summary>

<code>triggers</code>Optional<a href="#config-default-export-workerconfig-triggers">Link to triggers</a>

<code>triggers?: Trigger[]</code>

Event triggers — fetch routes, queue consumers, cron schedules, Email Routing addresses, and raw sockets — that invoke this Worker. Construct entries with <code>triggers.fetch(...)</code>, <code>triggers.queue(...)</code>, <code>triggers.scheduled(...)</code>, <code>triggers.email(...)</code>, or <code>triggers.connect(...)</code>. For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#triggers">https://developers.cloudflare.com/workers/wrangler/configuration/#triggers</a>

<code>scheduled</code>Builder<a href="#config-default-export-workerconfig-triggers">Link to scheduled</a>

<code>scheduled(options: ScheduledTriggerOptions): ScheduledTrigger;</code>

Scheduled (cron) trigger — invokes this Worker on the given schedules. More details here <a href="https://developers.cloudflare.com/workers/platform/cron-triggers">https://developers.cloudflare.com/workers/platform/cron-triggers</a>

<details>

<summary>Options (1)</summary>

<dl>

<dt><code>schedule: string</code></dt> <dd>A "cron" definition to trigger a Worker's "scheduled" function. Lets you call Workers periodically, much like a cron job. More details here <a href="https://developers.cloudflare.com/workers/platform/cron-triggers">https://developers.cloudflare.com/workers/platform/cron-triggers</a></dd>

</dl></details>

<code>schedule</code>Required<a href="#config-default-export-workerconfig-triggers">Link to schedule</a>

<code>schedule: string</code>

A "cron" definition to trigger a Worker's "scheduled" function. Lets you call Workers periodically, much like a cron job. More details here <a href="https://developers.cloudflare.com/workers/platform/cron-triggers">https://developers.cloudflare.com/workers/platform/cron-triggers</a>

</details>

},

};

});

Evaluate configuration

defineConfig(), defineWorker(), and defineContainer() each accept an object, a promise, or a function. A function can return an object or a promise.

Functions receive this context:

Property Purpose
mode Identifies the selected mode, which depends on the command when you omit --mode
isPreview Is true when the configuration is evaluated for a Worker Preview

Return one complete configuration for each mode. Programmatic configuration does not merge environment blocks.

Reuse definitions

Use defineWorker() when another configuration file needs to import a Worker definition. Use defineContainer() when a Durable Object export and the containers array need to reference the same Container.

These helpers do not replace the default export. The default export must still use defineConfig().

Configure the Worker

The worker object supports these fields:

Field Required Purpose
name Yes Sets the Worker name
compatibilityDate Yes Selects a Workers runtime compatibility date
entrypoint Conditional Selects the Worker module
assets No Sets runtime request behavior for built assets
cache No Configures Worker cache behavior
compatibilityFlags No Turns on runtime compatibility flags
domains No Publishes the Worker to custom domains
env No Declares bindings and inline values
exports No Configures named Worker, Durable Object, and Workflow exports
limits No Sets CPU and subrequest limits
logpush No Sends trace events to Workers Logpush
observability No Configures logs, traces, and sampling
placement No Configures smart or targeted placement
previewUrls No Controls version preview URLs
tailConsumers No Sends events to Tail Workers
triggers No Declares routes, queues, schedules, and sockets
unsafe No Passes unsupported metadata through to deployment
workersDev No Controls the workers.dev route

The assets object controls runtime behavior only. It configures HTML handling, not-found handling, and whether matching requests run the Worker first. It does not select the asset source.

Use domains for custom domains. Use triggers.fetch() for routes.

Use typed builder values

The bindings, triggers, and exports builders return ordinary configuration objects. Each object has a literal type field that identifies its kind.

The type field lets TypeScript select the valid options for each kind. For example, a queue trigger accepts batching options, while a scheduled trigger requires a cron expression. The configuration loader uses the same fields for runtime validation.

Use builders instead of writing type fields directly. Builders preserve literal values and generic type arguments for Worker type inference.

Declare bindings

Each key under worker.env becomes a binding name in Worker code. The builder method selects the binding's runtime type.

This configuration declares inline values, a D1 database, a Queue, and a secret:

Select a highlighted line to show its type and description below it.

cloudflare.config.ts

Expand allCopy

import { bindings, defineConfig } from "cf/config";

import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };

type Job = {

id: string;

operation: "index" | "delete";

};

<details>

<summary>export default defineConfig({ (defineConfig reference)</summary>

<code>defineConfig</code>Function<a href="#config-bindings-defineconfig">Link to defineConfig</a>