Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Local Worker Development: Bindings, Data and Multi-Worker Sessions

How local Worker dev separates code execution from bindings, when to use local vs remote resources, and how to persist data and run multiple Workers.

This page summarises Cloudflare’s documentation on local development for Workers and Pages Functions. You run Worker code on your machine through Miniflare and workerd, while bindings can point at empty local simulations or at live resources on your account.

Local development: where your Worker runs vs what bindings connect to

Section titled “Local development: where your Worker runs vs what bindings connect to”

Local development has two ideas that people often mix up: worker execution (where fetch handlers run) and bindings (how code reaches KV, R1, D1, Queues, Durable Objects, and the rest via env).

You can build, run, and test your Worker code on your own local machine before deploying it to Cloudflare’s network. This is made possible through Miniflare, a simulator that executes your Worker code in a local workerd ↗︎ process. workerd also powers the hosted Workers platform.

— Cloudflare, Local development

By default, wrangler dev and vite dev (with the Cloudflare Vite plugin) run your Worker locally and simulate bound resources locally. Those simulations start empty; reads for keys you never wrote locally return null, which matches KV local behaviour. The local runtime uses TZ=UTC for Date and Intl, matching production.

Mode Worker code Bindings (default)
Local dev (wrangler dev, Vite plugin) Your machine Local simulations
Local dev + remote: true per binding Your machine Proxied to deployed resources
wrangler dev --remote Cloudflare preview Always remote (legacy remote development)

For most day-to-day work, Cloudflare recommends local execution with **remote bindings only where you need real data or network-backed APIs—not full wrangler dev --remote, which uploads on every save and is slower to iterate.

Local bindings and .wrangler/state: how to seed KV, D1, and R2 locally

Section titled “Local bindings and .wrangler/state: how to seed KV, D1, and R2 locally”

When you start wrangler dev or Vite, Miniflare creates local stand-ins for configured bindings. You do not need separate local installs per service, but new local stores have no data until you fill them.

When you run either wrangler dev or vite ↗︎, Miniflare automatically creates local versions of your resources (like KV, D1, or R2). This means you don’t need to manually set up separate local instances for each service. However, newly created local resources won’t contain any data — you’ll need to use Wrangler commands with the –local flag to populate them. Changes made to local resources won’t affect production data.

— Cloudflare, Adding local data

Whether you use Wrangler or the Vite plugin, only the Wrangler CLI can write into those local stores during dev (Adding local data).

By default, both Wrangler and the Vite plugin store local binding data in the same location: the .wrangler/state folder in your project directory. This folder stores data in subdirectories for all local bindings: KV namespaces, R2 buckets, D1 databases, Durable Objects, etc.

— Cloudflare, Adding local data

Delete .wrangler/state to reset everything, or remove subfolders for a partial reset. Add the persistence directory to .gitignore so dev data never lands in git (Adding local data).

persist-to and matching flags on CLI writes

Section titled “persist-to and matching flags on CLI writes”

If you use a custom persistence path, you must pass the same path to every command that touches local data:

npx wrangler dev --persist-to worker-local
npx wrangler kv key put test 12345 --binding MY_KV_NAMESPACE --local --persist-to worker-local

Without --persist-to, Wrangler defaults to .wrangler/state (Adding local data).

Remote bindings: test local code against real D1, KV, and R2

Section titled “Remote bindings: test local code against real D1, KV, and R2”

Remote bindings keep Worker code on your machine but proxy binding calls to resources on your Cloudflare account.

When remote bindings are configured, your Worker still executes locally, but all binding calls are proxied to the deployed resource that runs on Cloudflare’s network.

— Cloudflare, Remote bindings GA

Set remote: true on each binding that should use the live resource (GA in Wrangler, the Vite plugin, and Vitest—Remote bindings GA):

{
"r2_buckets": [
{
"bucket_name": "screenshots-bucket",
"binding": "screenshots_bucket",
"remote": true
}
]
}

Early beta docs used experimental_remote and wrangler dev --x-remote-bindings (Remote bindings public beta); current config uses remote: true per Local development.

When remote bindings fit—and what they cost

Section titled “When remote bindings fit—and what they cost”

Use remote bindings when you need real data, billing-accurate AI/Images/Media behaviour, or APIs with no faithful local mock. Examples from the docs:

  • Workers AI — no local simulation; use remote: true (Local development).
  • Media Transformations — local dev errors unless remote: true (Bind to Workers API).
  • Staging environments — wrangler dev -e staging with a preview bucket and remote: true avoids touching production R2 (Local development).

Writes through remote bindings change real account data and incur normal usage charges; expect network latency (Local development). To force all bindings local for one session, use wrangler dev --local (wrangler dev command).

Some binding types always stay local or reject remote: true—notably Durable Objects, Workflows, Hyperdrive, Rate Limiting, vars, secrets, and static assets (Local development, Supported bindings per development mode). Patterns that still work:

  • Local Durable Objects/Workflows calling other bindings marked remote: true.
  • A remote service binding to a deployed Worker that owns production Durable Objects (Local development, Microfrontends).

Queues do not support wrangler dev --remote (Queues local development).

Automatic provisioning: develop without pre-creating KV, D1, or R2

Section titled “Automatic provisioning: develop without pre-creating KV, D1, or R2”

With Wrangler 4.45.0+, bindings without resource IDs can be auto-created locally and on first deploy:

wrangler dev will then automatically create these resources for you locally, and on your next run of wrangler deploy, Wrangler will call the Cloudflare API to create the requested resources and link them to your Worker.

— Cloudflare, Automatic resource provisioning

Disable with --no-x-provision if you need the old manual flow (Automatic resource provisioning).

Multiple Workers locally: one dev command vs separate terminals

Section titled “Multiple Workers locally: one dev command vs separate terminals”

Service bindings, tail consumers, and Durable Object wiring often need more than one Worker running. Cloudflare documents two main patterns in Developing with multiple Workers.

Pass multiple config files; the first is primary at http://localhost:8787, others are reachable via service bindings:

npx wrangler dev -c ./app/wrangler.jsonc -c ./api/wrangler.jsonc

The Vite plugin equivalent uses auxiliaryWorkers in Developing with multiple Workers. Multi-Worker in one command is still marked experimental in some Pages/Queues docs—report issues on workers-sdk.

Separate dev commands (cross-session service bindings)

Section titled “Separate dev commands (cross-session service bindings)”

Workers in different terminals can now talk across sessions—useful when teams own separate repos or build pipelines:

# Terminal 1
wrangler dev --config ./web/wrangler.jsonc --config ./api/wrangler.jsonc
# Terminal 2
wrangler dev --config ./auth/wrangler.jsonc

That unblocks patterns like env.AUTH.isAuthorized(request) from an API Worker (Improved support for running multiple Workers). The same cross-terminal behaviour applies when mixing vite dev and wrangler dev (Run and connect Workers in separate dev commands).

For Pages Functions, wire Durable Objects, Workers AI, or service bindings via wrangler pages dev flags such as --do, --ai, and --service; CLI flags override Wrangler file bindings (Pages Functions bindings). Programmatic multi-Worker tests use unstable_dev from the Wrangler API—shut down child Workers in afterAll or the parent cannot see them.

When wrangler dev starts, the session lists service bindings as [connected] or [not connected] depending on whether a matching dev session is running (Service bindings).

Wrangler vs Vite vs full remote wrangler dev --remote

Section titled “Wrangler vs Vite vs full remote wrangler dev --remote”

Choosing between Wrangler & Vite states both support local and remote bindings and multi-Worker setups; pick based on your bundler. Astro on Pages can enable platformProxy for local runtime (Deploy an Astro site).

wrangler dev --remote uploads the Worker to a Cloudflare preview environment; all bindings are remote and you cannot opt into local simulations (Local development). Hyperdrive testing often uses this mode, with the warning that DB side effects hit real data (Hyperdrive local development). Python Workers do not support --remote (Local development).

Configure ports, local_protocol, and inspector ports under [dev] in Wrangler configuration; Pages HTTPS locally via --local-protocol=https on wrangler pages dev.

  • Expecting production KV data on first wrangler dev without remote: true or without seeding local KV (KV bindings, Adding local data).
  • Running wrangler kv key get in CI without --remote after upgrading to Wrangler v4 (Migrate from Wrangler v3 to v4).
  • Using persist-to on wrangler dev but not on wrangler kv … --local, so data appears “missing” (Adding local data).
  • Setting remote: true on Durable Objects or Hyperdrive—Wrangler errors; use local DO + remote storage or a remote service binding instead (Local development).
  • Stopping a child Worker in tests before the parent finishes when using unstable_dev.
  • Using Workers AI or email with remote: true against real recipients without test addresses (Local development, Test email sending locally).
  1. Run wrangler dev (or vite dev with the Cloudflare plugin) and confirm the startup banner lists bindings and service targets as [connected] where needed—see Service bindings.
  2. With only local bindings, write a test key using wrangler kv key put … --local (and the same --persist-to as dev if you use one), then read it from your Worker via env—follow Adding local data.
  3. After enabling remote: true on a binding, compare behaviour against the binding matrix in Supported bindings per development mode.
  4. In the Cloudflare dashboard, open your Worker’s Bindings tab (Bindings canvas) to verify bindings match your Wrangler file.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about so it can be corrected quickly.