Skip to content

Cloudflare Workers local dev: .dev.vars from a context

Write .dev.vars for wrangler dev from an encrypted context with npx getmyenv export. Per-environment files, refreshing values, and a no-file option.

Oct 10, 2026 · 4 min read

An encrypted Development context, one export command, a .dev.vars file and wrangler dev.
export writes .dev.vars from Development. wrangler dev reads it.

1. How wrangler dev gets variables

wrangler dev reads local secrets from .dev.vars or .env next to the Wrangler config, in dotenv format. When .dev.vars exists, .env is not loaded. Variables from your shell do not reach the Worker by default, so a file is the plain path.

2. Write .dev.vars

bash
npx getmyenv export -c development -o .dev.vars npx wrangler dev

The Worker reads each value from env, like env.API_KEY. The file is plaintext, readable only by you on macOS and Linux. Inside the project folder, export adds it to .gitignore. Keep it there.

Use an open context like Development here. A Read-only context needs a server token from an allowed IP, on a trusted or approved machine, the same as run.

3. When values change

bash
npx getmyenv export -c development -o .dev.vars

If the file differs, export lists the names that change or go away, never the values, and asks before it overwrites. --yes skips the question. Restart wrangler dev if it keeps the old values.

4. Wrangler environments

For wrangler dev --env staging, write .dev.vars.staging from a Staging context. When that file exists, Wrangler loads only it, not .dev.vars.

bash
npx getmyenv export -c staging -o .dev.vars.staging npx wrangler dev --env staging

5. Without a file, and after deploy

With no .dev.vars present and CLOUDFLARE_INCLUDE_PROCESS_ENV=true, Wrangler passes the process environment to the Worker. Then run supplies the values with no file. Every variable in the process reaches the Worker, not only the context's.

bash
CLOUDFLARE_INCLUDE_PROCESS_ENV=true npx getmyenv run development -- npx wrangler dev

This is local dev only. A deployed Worker reads secrets stored in Cloudflare, set with wrangler secret put or the dashboard. Those values are then held by Cloudflare. More on run: /docs/runtime-injection.

Related docs: How run works, Contexts, CLI reference