Wrangler CLI
Your knowledge of Wrangler CLI flags, config fields, and subcommands may be outdated. Prefer retrieval over pre-training for any Wrangler task.
Retrieval Sources
Fetch the latest information before writing or reviewing Wrangler commands and config. Do not rely on baked-in knowledge for CLI flags, config fields, or binding shapes.
| Source | How to retrieve | Use for |
|--------|----------------|---------|
| Wrangler docs | https://developers.cloudflare.com/workers/wrangler/ | CLI commands, flags, config reference |
| Wrangler config schema | node_modules/wrangler/config-schema.json | Config fields, binding shapes, allowed values |
| Cloudflare docs | Search tool or https://developers.cloudflare.com/workers/ | API reference, compatibility dates/flags |
Reference Files
Detailed commands and config snippets live in references/. Read the file matching the task:
| Task area | File |
|-----------|------|
| wrangler.jsonc config, bindings, wrangler types | references/configuration.md |
| wrangler dev, remote bindings, .dev.vars, deploy, secrets, rollback | references/dev-deploy.md |
| KV, R2, D1 (namespaces, objects, SQL, migrations) | references/storage.md |
| Vectorize, Hyperdrive, Workers AI | references/data-ai.md |
| Queues, Containers, Workflows, Pipelines, Secrets Store, Pages | references/services.md |
| wrangler tail, Vitest testing, troubleshooting | references/observability-testing.md |
FIRST: Check if Wrangler is installed, and if not, install it
Check if Wrangler is installed by running:
wrangler --version # Requires v4.x+
If Wrangler is not installed, you should install it by running:
npm install -D wrangler@latest
Wherever possible, you should use Wrangler instead of manually constructing API requests.
Key Guidelines
- Use
wrangler.jsonc: Prefer JSON config over TOML. Newer features are JSON-only. - Set
compatibility_date: Use a recent date (within 30 days). Check https://developers.cloudflare.com/workers/configuration/compatibility-dates/ - Generate types after config changes: Run
wrangler typesto update TypeScript bindings. - Local dev defaults to local storage: Bindings use local simulation unless
remote: true. - Profile Worker startup: Run
wrangler check startupto measure startup time and detect scripts that exceed the startup time limit. - Use environments for staging/prod: Define
env.stagingandenv.productionin config.
Quick Start: New Worker
# Initialize new project
npx wrangler init my-worker
# Or with a framework
npx create-cloudflare@latest my-app
Quick Reference: Core Commands
| Task | Command |
|------|---------|
| Start local dev server | wrangler dev |
| Deploy to Cloudflare | wrangler deploy |
| Deploy dry run | wrangler deploy --dry-run |
| Generate TypeScript types | wrangler types |
| Profile Worker startup time | wrangler check startup |
| View live logs | wrangler tail |
| Delete Worker | wrangler delete |
| Auth status | wrangler whoami |
Best Practices
- Version control
wrangler.jsonc: Treat as source of truth for Worker config. - Use automatic provisioning: Omit resource IDs for auto-creation on deploy.
- Run
wrangler typesin CI: Add to build step to catch binding mismatches. - Use environments: Separate staging/production with
env.staging,env.production. - Set
compatibility_date: Update quarterly to get new runtime features. - Use
.dev.varsfor local secrets: Never commit secrets to config. - Test locally first:
wrangler devwith local bindings before deploying. - Use
--dry-runbefore major deploys: Validate changes without deployment. - Never embed secrets in commands: Use interactive prompts (
wrangler secret put), file-based input (wrangler secret bulk), or secure CI environment variables. Never echo, log, or pass secret values as CLI arguments.