How to Use the Distlang CLI to Run and Debug Workers Locally


Why Local Development Matters for Workers

Shipping code to production without testing it locally is gambling. For workers, the stakes are higher than typical web apps because the runtime is unusual. It is not Node.js and not a browser. As one Cloudflare community member put it, “Cloudflare Workers is not a Node environment and not even a Browser environment, it’s service-workers with custom APIs. Therefore, it’s hard to assume that things that work in local dev will work on actual Workers.”

That gap between local behavior and production behavior is exactly what the Distlang CLI closes. By running your code on workerd locally, you get near-perfect parity with the production runtime. This glossary defines every concept involved in that workflow so you can move from writing code to seeing results in minutes.

If you’re new to the platform, the Distlang documentation hub covers the full CLI reference. For metrics specifically, the metrics quickstart gets you from zero to a working dashboard fast.

How to Use This Glossary

Each entry below follows a simple structure: a plain definition, why the term matters for local development, and how it connects to the Distlang CLI workflow. Terms are ordered to follow the natural build, run, debug, deploy cycle rather than alphabetically, because that is how you will actually encounter them.

Cross-references point you to related entries. When a term has a direct CLI command, you will see it formatted as code.


Core CLI Concepts

Distlang CLI

The command-line tool for building, running, and deploying Distlang worker applications. It wraps the entire local development lifecycle into three core commands: distlang build, distlang run, and distlang deploy.

Unlike Wrangler (Cloudflare’s native CLI), which exposes dozens of subcommands for KV, R2, D1, queues, and more, the Distlang CLI is deliberately narrow. It compiles JavaScript worker apps, runs them locally using workerd, and packages them for deployment. This opinionated design reduces the surface area you need to learn.

When you will use it: Every time you write, test, or ship worker code. It is the single entry point for the entire workflow.

See also: distlang build, distlang run, distlang deploy

distlang build

The compile step. Running distlang build bundles your JavaScript worker application into a format ready for local execution or deployment.

Why it matters locally: The build step resolves your imports, including any helpers and layers you have added (metrics, storage, etc.), into a single compiled output. If your code has syntax errors or missing dependencies, this is where they surface. Fix them here, not after deployment.

Typical usage:

distlang build

A clean build with no errors means your code is structurally sound. It does not guarantee runtime correctness, which is what distlang run is for.

See also: Layers, Helpers

distlang run

The local development command. Running distlang run starts a local server backed by workerd, the same JavaScript and WebAssembly runtime that powers Cloudflare Workers in production.

This is the command you will use most often when learning how to use the Distlang CLI to run and debug workers locally. It gives you a URL (typically http://127.0.0.1:8787 or similar) where you can send requests and see your worker respond in real time.

Why runtime parity matters: Because workerd is the actual production runtime, not a simulation, behaviors like V8 isolate limits, Web API compatibility, and execution timing match what you will see after deployment. The Cloudflare team has noted that improving parity between local and production environments “leads to increased developer efficiency and confidence.”

Typical usage:

distlang run

Console output, errors, and logs appear directly in your terminal. This is where debugging begins.

See also: workerd, Console.log Debugging, Breakpoint Debugging

distlang deploy

The deployment command. Running distlang deploy packages your built worker and ships it to Cloudflare or Distlang-hosted infrastructure. On success, it returns a managed subdomain URL where your worker is live.

Why it belongs in a local dev glossary: Deployment is the final step of the local development loop. You build, run, debug, fix, and then deploy. The one-command deploy workflow is simpler than configuring Wrangler’s wrangler.toml and running multiple steps. For a walkthrough of how deploy URLs work for demos and staging, see the guide on hosted deploy URLs.

Typical usage:

distlang deploy

The returned URL is a *.distlang.com subdomain you can share immediately.

See also: Hosted Deploy URL


Runtime and Environment

workerd

Pronounced “worker-dee,” workerd is an open-source JavaScript and WebAssembly server runtime built on the same code that powers Cloudflare Workers. It embeds V8 (the JavaScript engine inside Chrome and Node.js) to execute your worker code.

When you run distlang run, workerd is what executes your code underneath. This is not a mock or a polyfill. It is the real runtime, running on your laptop.

The workerd project documentation describes it as usable both “as an application server to self-host applications designed for Cloudflare Workers” and “as a development tool to develop and test such code locally.” That dual purpose is exactly what the Distlang CLI takes advantage of.

Why it matters: Runtime parity eliminates an entire class of bugs, the “works on my machine” kind. If your code runs correctly under distlang run, it will behave the same way on Cloudflare’s edge network.

See also: Workers, Local Development

Workers

Short-lived JavaScript handlers that run on edge or serverless runtimes. Each incoming request triggers a worker, which processes the request and returns a response. Workers do not persist state between invocations by default.

In the Distlang model, workers are the primary unit of execution. You write a JavaScript handler, build it with the CLI, run it locally, and deploy it. The Distlang platform is built as a Cloudflare-first platform, meaning Cloudflare Workers are the primary compilation target today, with more providers on the roadmap.

Key constraint for debugging: Because workers are short-lived, you cannot rely on long-running processes to collect data. Anything that needs to happen after the response (flushing metrics, writing logs) must use patterns like ctx.waitUntil().

See also: ctx.waitUntil(), Flush Semantics

Local Development

Running and testing worker code on your own machine before deploying to production. The Distlang CLI makes this straightforward: distlang build followed by distlang run gives you a local server.

Local development is where you catch bugs, test edge cases, and iterate quickly. Cloudflare’s own documentation emphasizes that local dev provides “a fully-controllable and easy-to-debug testing environment.” The Distlang CLI preserves that benefit while simplifying the toolchain.

Practitioners on GitHub and forums frequently report friction with local dev tooling. One developer noted that after upgrading Wrangler, “my debug level logs fully disappeared” because default log levels had changed between versions. Another reported that wrangler dev “crashed every time I tried to start the server. Both the dev and remote dev. But it was working fine yesterday.” These stability complaints highlight why a streamlined CLI with fewer moving parts is valuable.

See also: distlang run, workerd


Debugging Techniques

Understanding how to use the Distlang CLI to run and debug workers locally requires knowing the debugging tools available to you. There are three main approaches, ranging from simple to sophisticated.

Console.log Debugging

The simplest debugging method. Add console.log() statements to your worker code, run distlang run, send a request, and read the output in your terminal.

This sounds basic, and it is. But for workers, it is often the fastest path to understanding what your code is doing. As one developer blogger observed, when running a worker locally, “the console messages will show up right in your terminal,” making it trivial to trace request handling.

Tips:

  • Log the incoming request URL, headers, and body to verify your worker receives what you expect.
  • Log before and after async operations (database reads, API calls) to spot timing issues.
  • Remember to remove or gate verbose logging before deploying. Production logs have costs.

Limitation: Console.log cannot pause execution. If you need to inspect variables at a specific moment, you need breakpoints.

See also: Breakpoint Debugging

Breakpoint Debugging

Pausing worker execution at a specific line of code so you can inspect variables, the call stack, and program state. Breakpoints are the most powerful debugging tool available during local development.

Because workerd embeds V8, you get full access to the V8 inspector protocol. This means two debugging interfaces work out of the box.

Chrome DevTools approach:

  1. Start your worker locally with the inspector enabled (typically on port 9229).
  2. Open chrome://inspect in Chrome.
  3. Click “Configure” and add localhost:9229.
  4. Your worker appears under “Remote Target.” Click “inspect.”
  5. Set breakpoints in the Sources panel, send a request, and execution pauses.

VS Code approach:
Open a JavaScript Debug Terminal in VS Code and start your local dev server from within it. VS Code automatically connects to the running worker and enables breakpoints in your editor. Cloudflare’s documentation describes this workflow as requiring no extra configuration: “all you have to do is open a JS debug terminal” and start the server.

Both approaches work because workerd and Cloudflare Workers embed V8 to run JavaScript. The V8 inspector is the same protocol used for debugging Node.js applications, so the tools are familiar.

See also: workerd, Agent Debugger

Agent Debugger

Distlang’s dedicated debugging tool for inspecting worker behavior. The Agent Debugger goes beyond basic breakpoints to provide structured inspection of how your worker interacts with helpers, layers, and external services.

For usage details, the Agent Debugger documentation covers setup and common workflows. This tool is particularly useful when debugging complex interactions between multiple layers in a single worker.

See also: Helpers, Layers


The Distlang Application Model

Helpers

Reusable application capabilities in Distlang that you import directly into your worker code. Examples include ObjectDB storage and Distlang Metrics. Instead of configuring external services and writing glue code, you import a helper and use it as a first-class part of your application.

Why helpers matter for local development: When you run distlang run, helpers execute locally alongside your worker code. This means you can test metrics recording, storage operations, and other capabilities without deploying. The build step (distlang build) resolves helper imports so they are available at runtime.

For a deeper explanation, the blog post on what helpers are covers the design rationale.

See also: Layers

Layers

Composable, importable modules in the Distlang model. Layers are the architectural unit that makes helpers possible. You stack layers to build an application, each layer providing a distinct capability (metrics, storage, authentication, etc.).

The app layering model explains how layers compose. Think of each layer as a building block. Your worker is the base, and each layer adds functionality without requiring you to wire services together manually.

During local development: All layers resolve at build time and run locally under workerd. You can test the full stack of your application on your machine.

See also: Helpers, distlang build


Deployment and Lifecycle

Hosted Deploy URL

The managed *.distlang.com subdomain returned when you run distlang deploy. This URL is immediately accessible, no DNS configuration, no certificate provisioning, no waiting.

Use cases: Quick demos, staging environments, sharing work-in-progress with teammates. The one-command deploy workflow cuts the time between “it works locally” and “here is a live URL” to seconds.

See also: distlang deploy

Flush Semantics

How buffered data (metrics, logs, analytics) gets sent before a worker handler terminates. Because workers are short-lived, any data that has not been flushed when the handler returns its response may be lost.

The Distlang JavaScript client (@distlang/client) supports flush and buffering specifically to handle this constraint. The client accumulates metric recordings during handler execution and flushes them in a single batch before the handler exits. For strategies on configuring this behavior, see the guide on flush strategies for short-lived handlers.

During local development: Flush behavior is observable. You can see in your terminal whether the flush completed successfully and whether any data was lost. This is one of the most important things to verify locally before deploying.

See also: ctx.waitUntil(), Workers

ctx.waitUntil()

A Cloudflare Workers API that extends a handler’s lifetime past the response. You pass it a promise, and the runtime keeps the worker alive until that promise resolves, even though the response has already been sent to the client.

This is the standard pattern for flushing metrics, writing logs, or performing cleanup after responding. In Distlang, calling ctx.waitUntil(metrics.flush()) ensures your metric data is sent before the worker shuts down.

For instrumentation patterns using this API, the waitUntil semantics guide provides detailed examples.

During local development with distlang run: The ctx.waitUntil() behavior works identically to production because workerd implements the same API. Verify that your flush completes by checking terminal output.

See also: Flush Semantics, Workers


Distlang CLI vs. Wrangler: Quick Comparison

If you are coming from Wrangler, this table maps common tasks to their Distlang CLI equivalents. Both tools use workerd underneath, but the Distlang CLI is narrower and more opinionated.

Task Wrangler Distlang CLI
Build/compile worker wrangler build (implicit in dev) distlang build
Start local dev server wrangler dev distlang run
Deploy to production wrangler deploy distlang deploy
Get a live URL Configure custom domain or *.workers.dev Automatic *.distlang.com subdomain
Add metrics/storage Configure bindings in wrangler.toml Import helpers in code
Debug with breakpoints Start via JS Debug Terminal Start via JS Debug Terminal
View local logs Terminal output + wrangler tail Terminal output

The key difference is not capability but philosophy. Wrangler is a general-purpose tool for the entire Cloudflare platform. The Distlang CLI focuses on building, running, and deploying worker applications with built-in helpers, so you spend less time on configuration and more time writing code.


Workflow Quick Reference

Here is the complete loop for how to use the Distlang CLI to run and debug workers locally, from first line of code to live URL.

1. Write your worker. Create a JavaScript handler that processes requests. Import any helpers you need (metrics, storage).

2. Build. Run distlang build to compile your worker and resolve all imports. Fix any errors the compiler reports.

3. Run locally. Run distlang run to start a local workerd-backed server. Send requests to the local URL and verify behavior.

4. Debug. Use console.log for quick checks. For deeper issues, attach Chrome DevTools or VS Code’s debugger via the V8 inspector. Use the Agent Debugger for complex layer interactions.

5. Iterate. Fix bugs, rebuild, rerun. The cycle is fast because everything runs on your machine.

6. Deploy. Run distlang deploy to ship your worker and get a live *.distlang.com URL.

For a full end-to-end walkthrough that includes metrics setup, see the app-to-dashboard guide.


Troubleshooting Common Local Development Issues

Logs disappear or change format after updates

Developers frequently report that CLI updates change logging behavior. One developer on GitHub noted that after a Wrangler upgrade, “my debug level logs fully disappeared” because default log levels had changed between versions. With the Distlang CLI, check that your console.log statements are not gated behind a log level you have not set. If output looks different after an update, check the release notes for changes to default verbosity.

Worker crashes on startup

If distlang run fails immediately, the most common causes are:

  • A syntax error that distlang build did not catch (rare, but possible with dynamic imports)
  • A missing environment variable or binding that your code expects
  • A port conflict (another process is using the default port)

Try running distlang build first to isolate compile-time errors from runtime errors.

Behavior differs between local and production

This is uncommon when using workerd locally because it is the same runtime. But it can happen when your worker depends on external services (APIs, databases) that behave differently from your machine vs. the edge. Check network calls, DNS resolution, and any IP-based access controls.

Metrics not appearing after flush

If you are using @distlang/client and your metrics are not showing up, verify that ctx.waitUntil() wraps your flush call. Without it, the worker may terminate before the flush completes. You can confirm flush success by checking terminal output during distlang run. The debugging missing metrics guide covers this scenario in detail.


FAQ

What is the Distlang CLI?

The Distlang CLI is a command-line tool with three core commands: distlang build (compile), distlang run (local dev server), and distlang deploy (ship to production). It is designed for JavaScript worker applications and uses the workerd runtime for local execution.

How does distlang run work under the hood?

It starts a local instance of workerd, the same open-source runtime that powers Cloudflare Workers in production. Your compiled worker code runs inside a V8 isolate on your machine, giving you near-identical behavior to the production environment.

Can I use Chrome DevTools to debug workers running via the Distlang CLI?

Yes. Because workerd embeds V8, it supports the V8 inspector protocol. Start your local server with the inspector enabled, open chrome://inspect, add localhost:9229, and you can set breakpoints, inspect variables, and step through code.

How is the Distlang CLI different from Wrangler?

Wrangler is Cloudflare’s general-purpose CLI covering dozens of services (KV, R2, D1, Queues, etc.). The Distlang CLI is narrower and more opinionated, focusing on build, run, and deploy with built-in support for helpers and layers. Both use workerd for local development.

Do helpers work during local development?

Yes. Helpers resolve during distlang build and execute locally when you run distlang run. You can test metrics recording, storage operations, and other helper functionality on your machine before deploying.

What URL do I get after running distlang deploy?

You receive a managed *.distlang.com subdomain. No DNS setup or certificate configuration required. The URL is live immediately.

How do I make sure metrics flush before my worker terminates?

Wrap your flush call in ctx.waitUntil(). This tells the runtime to keep the worker alive until the flush promise resolves, even though the HTTP response has already been sent. Verify this works locally by checking terminal output during distlang run.

Where can I learn more about the full Distlang platform?

The Distlang documentation covers the CLI, metrics, helpers, and deployment in detail. For metrics specifically, the metrics product page explains pricing, features, and how to get started.