Skip to main content
skill CX Codex

cloudflare-workers-dev-experience — Claude Code skill: how to install

Guides local Cloudflare Workers development using Wrangler and Miniflare. Helps fix broken bindings for KV, D1, or R2, configure HMR, and set up tsconfig.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add secondsky/claude-skills --skill cloudflare-workers-dev-experience -a claude-code
Open on GitHub

What cloudflare-workers-dev-experience does

This skill provides rules and templates for developing Cloudflare Workers locally. It includes a wrangler.jsonc blueprint with separated bindings for KV, D1 databases, and R2 buckets. TypeScript configuration targets ES2022 using bundler module resolution. Files include the scripts/dev-setup.sh script.

Missing preview_id causes env.KV is undefined during local testing. D1 migrations must run locally. The guide also tackles port conflicts blocking HMR, missing types, and CORS issues. For inspection, it configures .vscode/launch.json targeting port 9229.

Supply chain security is addressed directly. The instructions advise blocking install scripts via ignore-scripts and auditing dependencies with Socket CLI before running bunx create-cloudflare.

What it helps with

  • configure wrangler.jsonc with bindings for KV, D1, and R2
  • prevent env.KV is undefined errors by specifying preview_id
  • set up VS Code debugging via inspector port 9229
  • align tsconfig.json with @cloudflare/workers-types

Example prompts for the agent

  • Help me set up wrangler.jsonc with local D1 and R2 bindings
  • Why does env.KV return undefined during local wrangler dev?
  • Generate a launch.json config to debug my worker on port 9229

How to install cloudflare-workers-dev-experience

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --skill cloudflare-workers-dev-experience -a claude-code

2Manually: put the files in place

~/.claude/skills/cloudflare-workers-dev-experience/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/cloudflare-workers-dev-experience/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about cloudflare-workers-dev-experience

How to install cloudflare-workers-dev-experience in Claude Code?

Run the command npx skills add secondsky/claude-skills --skill cloudflare-workers-dev-experience -a claude-code.

What does cloudflare-workers-dev-experience do?

It provides reference files, wrangler.jsonc templates, and troubleshooting steps for running Cloudflare Workers locally. It guides developers through setting up Miniflare, TypeScript bindings, and debugger ports.

Why is preview_id required for KV namespaces?

Without preview_id, Miniflare cannot initialize the storage locally, causing env.KV to resolve as undefined. Adding this ID keeps local dev data separate from production.

Source text

SKILL.md · MIT
---
name: cloudflare-workers-dev-experience
description: Cloudflare Workers local development with Wrangler, Miniflare, hot reload, debugging. Use for project setup, wrangler.jsonc configuration, or encountering local dev, HMR, binding simulation errors.
license: MIT
---

# Cloudflare Workers Developer Experience

Local development setup with Wrangler, Miniflare, and modern tooling.

## Quick Start

```bash
# Create new project
bunx create-cloudflare@latest my-worker

# Or from scratch
mkdir my-worker && cd my-worker
bun init -y
bun add -d wrangler @cloudflare/workers-types

# Start local development
bunx wrangler dev
```

## Secure Installation

Scaffolding tools like `bunx create-cloudflare` download and execute remote code. Before running, follow supply chain security best practices:

- **Block post-install scripts** — `npm config set ignore-scripts true` (or Bun: disabled by default)
- **Cooldown period** — Wait 7 days for new package versions to be vetted by the community
- **Audit before installing** — Run `socket package score npm <pkg>` or use `socket npm install <pkg>` to check packages

Load the `dependency-upgrade` skill for full security configuration including Socket CLI integration, cooldown setup, lockfile validation, and CI enforcement.

## Essential wrangler.jsonc

```jsonc
{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "my-worker",
  "main": "src/index.ts",
  "compatibility_date": "2024-12-01",

  // Development settings
  "dev": {
    "port": 8787,
    "local_protocol": "http"
  },

  // Environment variables (non-secret)
  "vars": {
    "ENVIRONMENT": "development"
  },

  // Bindings
  "kv_namespaces": [
    { "binding": "KV", "id": "abc123", "preview_id": "def456" }
  ],

  "d1_databases": [
    { "binding": "DB", "database_id": "xyz789", "database_name": "my-db" }
  ],

  "r2_buckets": [
    { "binding": "BUCKET", "bucket_name": "my-bucket" }
  ]
}
```

## Critical Rules

1. **Always use `wrangler dev` for local testing** - Simulates Cloudflare runtime accurately
2. **Set `compatibility_date`** - Controls runtime behavior, update quarterly
3. **Use preview IDs for local dev** - Separate from production bindings
4. **Configure TypeScript properly** - Use `@cloudflare/workers-types`
5. **Enable source maps** - Better error stacks in development

## Top 6 Errors Prevented

| Error | Symptom | Prevention |
|-------|---------|------------|
| Module not found | Import errors on deploy | Set `"moduleResolution": "bundler"` in tsconfig |
| Binding undefined | `env.KV is undefined` locally | Add `preview_id` to KV namespace config |
| HMR not working | Changes not reflecting | Check port conflicts, use `--local` flag |
| D1 schema mismatch | Queries fail locally | Run migrations on local DB |
| Type errors | Missing binding types | Generate types with `wrangler types` |
| CORS issues | Browser blocking requests | Add CORS headers in dev handler |

## Local Development Workflow

```bash
# Start dev server (recommended)
bunx wrangler dev

# With live reload
bunx wrangler dev --live-reload

# Remote mode (use actual Cloudflare services)
bunx wrangler dev --remote

# Specify environment
bunx wrangler dev --env staging

# Custom port
bunx wrangler dev --port 3000
```

## TypeScript Configuration

**tsconfig.json**:
```json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "bundler",
    "lib": ["ES2022"],
    "types": ["@cloudflare/workers-types"],
    "strict": true,
    "noEmit": true,
    "skipLibCheck": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
```

## Package.json Scripts

```json
{
  "scripts": {
    "dev": "wrangler dev",
    "deploy": "wrangler deploy",
    "deploy:staging": "wrangler deploy --env staging",
    "deploy:production": "wrangler deploy --env production",
    "test": "vitest",
    "test:watch": "vitest --watch",
    "type-check": "tsc --noEmit",
    "lint": "eslint src/",
    "types": "wrangler types",
    "tail": "wrangler tail",
    "db:migrate": "wrangler d1 migrations apply DB",
    "db:studio": "wrangler d1 execute DB --local --command 'SELECT 1'"
  }
}
```

## Debugging

### Console Logging

```typescript
// Development-only logging
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    if (env.ENVIRONMENT === 'development') {
      console.log('Request:', request.method, request.url);
      console.log('Headers:', Object.fromEntries(request.headers));
    }

    // Handler logic...
  }
};
```

### Using wrangler tail

```bash
# Real-time logs from deployed worker
wrangler tail

# Filter by status
wrangler tail --status error

# Filter by method
wrangler tail --method POST

# JSON format for parsing
wrangler tail --format json
```

### VS Code Debugging

**.vscode/launch.json**:
```json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Wrangler Dev",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "bunx",
      "runtimeArgs": ["wrangler", "dev", "--inspector-port", "9229"],
      "skipFiles": ["<node_internals>/**"],
      "sourceMaps": true
    }
  ]
}
```

## When to Load References

Load specific references based on the task:

- **Setting up project?** → Load `references/local-development.md` for complete setup guide
- **Configuring wrangler?** → Load `references/wrangler-config.md` for all configuration options
- **Debugging issues?** → Load `references/debugging-tools.md` for debugging techniques

## Templates

| Template | Purpose | Use When |
|----------|---------|----------|
| `templates/wrangler-config.jsonc` | Complete wrangler config | Starting new project |
| `templates/dev-script.ts` | Development utilities | Adding dev helpers |

## Scripts

| Script | Purpose | Command |
|--------|---------|---------|
| `scripts/dev-setup.sh` | Initialize dev environment | `./dev-setup.sh` |

## Resources

- Wrangler CLI: https://developers.cloudflare.com/workers/wrangler/
- Configuration: https://developers.cloudflare.com/workers/wrangler/configuration/
- Local Development: https://developers.cloudflare.com/workers/testing/local-development/

© secondsky · MIT · secondsky/claude-skills

Similar skills

All skills for Backend and APIs →

From the same set128

cloudflare-workers-security Authentication, CORS, rate limiting and input validation patterns for Cloudflare Workers. Install when you need JWT or API key checks, CORS fixes, or protection from injection attacks. CX Codex +1 343installs cloudflare-workers-testing A skill for writing Cloudflare Workers tests with Vitest and real D1, KV, R2 and Durable Objects bindings. Useful when tests break on mocks or can't see the environment. CX Codex +1 325installs nuxt-seo A skill covering the eight Nuxt SEO v5 modules: robots.txt, sitemaps, OG images, Schema.org and meta tags. Useful when a Nuxt app needs SEO wired up. CX Codex +1 324installs cloudflare-workers-performance A Claude skill for Cloudflare Workers performance: CPU, memory, caching, bundle size. Useful when a worker is slow or hitting limits. CX Codex +1 315installs cloudflare-workers-runtime-apis A skill covering the Cloudflare Workers runtime APIs: Fetch, Streams, Crypto, Cache, WebSockets and text encoding. Handy when a worker trips over requests, streams or cache. CX Codex +1 311installs cloudflare-workers-frameworks Tells your agent how to run Hono, Remix, Next.js, Astro, SvelteKit, Qwik or Nuxt on Cloudflare Workers, and walks through the usual build errors. CX Codex +1 309installs cloudflare-workers-ci-cd A skill that walks your agent through CI/CD for Cloudflare Workers on GitHub Actions or GitLab CI. Useful when a pipeline breaks or every pull request needs its own preview. CX Codex +1 303installs cloudflare-workers-observability A skill for Cloudflare Workers observability: structured logging, Analytics Engine, Tail Workers, metrics and alerting. Useful when a worker fails in production and you can't see why. CX Codex +1 302installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor