| name | Wrangler Workflows |
| description | This skill should be used when the user mentions "wrangler", "wrangler.toml", "wrangler.jsonc", "wrangler commands", "local development", "wrangler dev", "wrangler deploy", "wrangler publish", "secrets management", "wrangler tail", "wrangler d1", "wrangler kv", or discusses Cloudflare Workers CLI, configuration files, or deployment workflows. |
| version | 0.1.0 |
Wrangler Workflows
Purpose
This skill provides comprehensive guidance for using Wrangler, the Cloudflare Workers CLI tool. It covers common commands, configuration file management, local development workflows, secrets handling, and deployment processes. Use this skill when working with Wrangler CLI operations, configuring Workers projects, or managing Workers deployments.
Wrangler Overview
Wrangler is the official CLI tool for Cloudflare Workers. It handles:
- Project initialization and scaffolding
- Local development and testing
- Configuration management
- Deployment and publishing
- Resource management (KV, D1, R2, etc.)
- Secrets and environment variables
- Logs and debugging
Installation
npm install -g wrangler
npx wrangler
wrangler --version
Authentication
wrangler login
export CLOUDFLARE_API_TOKEN=your-token
wrangler whoami
Common Commands
Development Commands
Start local development server:
wrangler dev
wrangler dev --remote
wrangler dev --port 3000
wrangler dev --live-reload
Tail logs (real-time):
wrangler tail
wrangler tail --status error
wrangler tail --method POST
wrangler tail --search "user-id"
wrangler tail --format pretty
Deployment Commands
Deploy to Cloudflare:
wrangler deploy
wrangler deploy --env staging
wrangler deploy --env production
wrangler deploy --dry-run
wrangler publish
Manage deployments:
wrangler deployments list
wrangler deployments view [deployment-id]
wrangler rollback [deployment-id]
Resource Management
KV Commands:
wrangler kv:namespace create NAMESPACE_NAME
wrangler kv:namespace list
wrangler kv:key put KEY "value" --namespace-id=xxx
wrangler kv:key get KEY --namespace-id=xxx
wrangler kv:key delete KEY --namespace-id=xxx
wrangler kv:key list --namespace-id=xxx
wrangler kv:bulk put data.json --namespace-id=xxx
wrangler kv:bulk delete keys.json --namespace-id=xxx
D1 Commands:
wrangler d1 create DATABASE_NAME
wrangler d1 list
wrangler d1 execute DB_NAME --command="SELECT * FROM users"
wrangler d1 execute DB_NAME --file=query.sql
wrangler d1 execute DB_NAME --remote --command="SELECT * FROM users"
wrangler d1 migrations create DB_NAME migration_name
wrangler d1 migrations list DB_NAME
wrangler d1 migrations apply DB_NAME
wrangler d1 migrations apply DB_NAME --remote
R2 Commands:
wrangler r2 bucket create BUCKET_NAME
wrangler r2 bucket list
wrangler r2 object put BUCKET_NAME/key.txt --file=local-file.txt
wrangler r2 object get BUCKET_NAME/key.txt --file=output.txt
wrangler r2 object delete BUCKET_NAME/key.txt
wrangler r2 object list BUCKET_NAME
Secrets Management
wrangler secret put SECRET_NAME
wrangler secret list
wrangler secret delete SECRET_NAME
wrangler secret bulk data.json
See references/wrangler-commands-cheatsheet.md for complete command reference.
Configuration Files
Wrangler supports two configuration formats:
- wrangler.toml - TOML format (traditional)
- wrangler.jsonc - JSON with comments (modern, recommended)
Basic wrangler.jsonc Structure
{
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2024-01-01",
"vars": {
"ENVIRONMENT": "production"
},
"kv_namespaces": [
{
"binding": "MY_KV",
"id": "abc123..."
}
],
"d1_databases": [
{
"binding": "DB",
"database_name": "my-db",
"database_id": "xyz789..."
}
],
"r2_buckets": [
{
"binding": "MY_BUCKET",
"bucket_name": "uploads"
}
],
"ai": {
"binding": "AI"
}
}
Multi-Environment Configuration
{
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2024-01-01",
"vars": {
"ENVIRONMENT": "production"
},
"kv_namespaces": [
{
"binding": "CACHE",
"id": "prod-id"
}
],
"env": {
"staging": {
"vars": {
"ENVIRONMENT": "staging"
},
"kv_namespaces": [
{
"binding": "CACHE",
"id": "staging-id"
}
]
},
"development": {
"vars": {
"ENVIRONMENT": "development"
},
"kv_namespaces": [
{
"binding": "CACHE",
"id": "dev-id"
}
]
}
}
}
Deploy to specific environment:
wrangler deploy --env staging
wrangler deploy --env development
See references/wrangler-config-options.md for all configuration options and examples/wrangler-jsonc-template.jsonc for annotated template.
Local Development Workflow
Step 1: Initialize Project
npm create cloudflare@latest
npm init cloudflare
Step 2: Configure wrangler.jsonc
Create or update wrangler.jsonc with bindings, environment variables, and settings.
Step 3: Develop Locally
wrangler dev
Step 4: Test Locally
wrangler dev
wrangler dev --remote
Step 5: Deploy
wrangler deploy
Remote vs Local Mode
Local Mode (Default)
- Bindings are simulated locally where possible
- KV, Cache API work with local storage
- D1 uses local SQLite
- Vectorize and Workflows require
--remote
wrangler dev
Remote Mode
- Uses actual Cloudflare resources
- All bindings work as in production
- May incur charges (AI, etc.)
- Required for Vectorize, Workflows, AI Gateway
wrangler dev --remote
Important: Some bindings like Vectorize don't support local mode and always require --remote.
Secrets Best Practices
Adding Secrets
wrangler secret put API_KEY
wrangler secret put DB_PASSWORD < password.txt
cat secrets.json | wrangler secret bulk
Secrets vs Environment Variables
| Feature | Secrets | Environment Variables |
|---|
| Storage | Encrypted, not in config | Plain text in wrangler.jsonc |
| Use case | API keys, passwords | Non-sensitive config |
| Deployment | Set via CLI | Committed to git |
| Access | Same as env vars in code | Same as secrets in code |
Rule: Never commit secrets to version control. Use wrangler secret put for sensitive data.
Debugging and Logs
Real-Time Logs
wrangler tail
wrangler tail --status error
wrangler tail --status ok
wrangler tail --method POST
wrangler tail --search "user-123"
wrangler tail --status error --method POST
Local Development Debugging
wrangler dev
Console Output
In Worker code:
console.log('Info message', { data: 'value' });
console.error('Error:', error);
console.warn('Warning');
Visible in:
wrangler dev terminal output
wrangler tail for production
- Cloudflare Dashboard → Workers → Logs
TypeScript Support
Wrangler automatically supports TypeScript:
export interface Env {
MY_KV: KVNamespace;
DB: D1Database;
API_KEY: string;
}
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
const value = await env.MY_KV.get('key');
return new Response(value);
}
};
Install types:
npm install -D @cloudflare/workers-types
Update tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"lib": ["ES2022"],
"types": ["@cloudflare/workers-types"]
}
}
Common Workflows
New Project Setup
npm create cloudflare@latest my-worker
cd my-worker
npm install
wrangler dev
wrangler deploy
Adding D1 Database
wrangler d1 create my-database
wrangler d1 migrations create my-database create_users_table
wrangler d1 migrations apply my-database
wrangler d1 migrations apply my-database --remote
Managing Multiple Environments
wrangler deploy --env staging
wrangler tail --env staging
wrangler d1 execute DB --env staging --remote --command="SELECT COUNT(*) FROM users"
wrangler deploy --env production
Troubleshooting
Common Issues
Issue: "Vectorize bindings not working in local dev"
- Solution: Use
wrangler dev --remote, Vectorize doesn't support local mode
Issue: "Authentication failed"
- Solution: Run
wrangler login or set CLOUDFLARE_API_TOKEN
Issue: "Binding not found in env"
- Solution: Check wrangler.jsonc configuration, ensure binding name matches
Issue: "D1 migrations not applying"
- Solution: Ensure you're using
--remote flag for production: wrangler d1 migrations apply DB --remote
Issue: "Secrets not updating"
- Solution: Secrets require redeployment:
wrangler secret put KEY then wrangler deploy
Getting Help
wrangler --help
wrangler dev --help
wrangler deploy --help
wrangler d1 --help
wrangler --version
Best Practices
Configuration Management
- Use
wrangler.jsonc for modern projects (JSON with comments)
- Commit wrangler.jsonc to version control
- Never commit secrets to git
- Use environment-specific configurations for staging/production
- Keep compatibility_date current
Development Workflow
- Always test with
wrangler dev before deploying
- Use
--remote when testing bindings that don't support local mode
- Run
wrangler deploy --dry-run to validate before deploying
- Use
wrangler tail to debug production issues
- Version control migrations (D1, Durable Objects)
Deployment Strategy
- Use environments for staging/production separation
- Test migrations in staging before production
- Use
wrangler deployments list to track deployment history
- Keep Workers small and focused
- Monitor logs with
wrangler tail after deployment
Security
- Always use
wrangler secret put for sensitive data
- Rotate secrets regularly
- Use service bindings for internal-only Workers
- Validate all user input in Worker code
- Use HTTPS for external API calls
Additional Resources
Reference Files
For detailed information, consult:
references/wrangler-commands-cheatsheet.md - Complete command reference with examples
references/wrangler-config-options.md - All configuration options for wrangler.jsonc
Example Files
Working examples in examples/:
wrangler-jsonc-template.jsonc - Comprehensive annotated configuration template
Documentation Links
For the latest Wrangler documentation:
Use the cloudflare-docs-specialist agent to search documentation and fetch the latest Wrangler information.