infra-platform-cloudflare-workers
Cloudflare Workersのエッジコンピューティング環境を、Wrangler CLIなどのツールで活用し、KV、D1、R2、Durable Objects、Queues、Workers AIといった様々な機能を利用して、高速で柔軟なアプリケーションを構築・実行するSkill。
📜 元の英語説明(参考)
Cloudflare Workers edge compute platform — Wrangler CLI, KV, D1, R2, Durable Objects, Queues, Workers AI
🇯🇵 日本人クリエイター向け解説
Cloudflare Workersのエッジコンピューティング環境を、Wrangler CLIなどのツールで活用し、KV、D1、R2、Durable Objects、Queues、Workers AIといった様々な機能を利用して、高速で柔軟なアプリケーションを構築・実行するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o infra-platform-cloudflare-workers.zip https://jpskill.com/download/10255.zip && unzip -o infra-platform-cloudflare-workers.zip && rm infra-platform-cloudflare-workers.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10255.zip -OutFile "$d\infra-platform-cloudflare-workers.zip"; Expand-Archive "$d\infra-platform-cloudflare-workers.zip" -DestinationPath $d -Force; ri "$d\infra-platform-cloudflare-workers.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
infra-platform-cloudflare-workers.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
infra-platform-cloudflare-workersフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Cloudflare Workers のパターン
クイックガイド: Cloudflare Workers は、Cloudflare のグローバルエッジネットワーク上で、V8 isolate (コンテナではない) を用いて TypeScript/JavaScript を実行します。設定には
wrangler.jsoncを、ローカル開発にはwrangler devを、本番環境へのデプロイにはwrangler deployを使用します。envパラメータ上の型安全なバインディングを通して、KV、D1、R2、Queues、Durable Objects、Workers AI にアクセスします。wrangler typesを実行して、Envインターフェースを自動生成します。大きなペイロードはストリーム処理してください。Workers には 128 MB のメモリ制限があります。リクエストスコープの状態をモジュールレベルの変数に決して保存しないでください。
<critical_requirements>
重要: この Skill を使用する前に
すべてのコードは CLAUDE.md のプロジェクト規約に従う必要があります (kebab-case、名前付きエクスポート、インポート順序、
import type、名前付き定数)
(Env インターフェースを生成するために wrangler types を必ず実行してください — バインディングの型を手書きしないでください)
(新しいプロジェクトには wrangler.jsonc を必ず使用してください — Cloudflare は JSON 形式の設定を推奨しており、一部の機能は JSON 形式のみに対応しています)
(大きなリクエスト/レスポンスボディは必ずストリーム処理してください — ペイロード全体をメモリにバッファリングしないでください (128 MB の制限があります))
(モジュールレベルの可変状態は必ず避けてください — Workers はリクエスト間で V8 isolate を再利用するため、リクエストを跨いでのデータリークが発生します)
(Cloudflare サービス (KV、D1、R2、Queues) には必ずバインディングを使用してください — Workers 内から REST API を決して使用しないでください)
</critical_requirements>
例
- コア設定と構成 — wrangler.jsonc、プロジェクトの初期化、fetch ハンドラ、シークレット、マルチ環境、CI/CD、テスト
- KV ストレージ — KV バインディング、型付き get/put、TTL、stale-while-revalidate キャッシング
- D1 データベース — D1 バインディング、パラメータ化されたクエリ、バッチ処理、マイグレーション、CRUD API
- R2 オブジェクトストレージ — R2 バインディング、ストリーミングによるファイルのアップロード/ダウンロード/削除
- Durable Objects — DO クラス、SQLite、RPC、レートリミッター、WebSocket チャット
- ルーティングとミドルウェア — API フレームワークの統合、ミドルウェア、キュー、cron、サービスバインディング、AI、ストリーミング
- クイックリファレンス — Wrangler CLI コマンド、バインディングの型シグネチャ、設定テンプレート、CPU 制限
自動検出: Cloudflare Workers, wrangler, wrangler.toml, wrangler.jsonc, Workers KV, Cloudflare KV, D1 database, R2 bucket, Durable Objects, Cloudflare Queues, Workers AI, service binding, miniflare, compatibility_date, compatibility_flags, nodejs_compat, cloudflare:workers, ExportedHandler, DurableObject, wrangler dev, wrangler deploy, wrangler types, Cloudflare Pages Functions, edge worker, CF Worker
いつ使うべきか:
- TypeScript/JavaScript を Cloudflare のエッジネットワークにデプロイする場合
- ローカル開発とデプロイのために Wrangler CLI を構成する場合
- Cloudflare バインディング (KV、D1、R2、Queues、Durable Objects、Workers AI) を使用する場合
- フレームワーク (例: Hono) を使用して Workers 上に API を構築する場合
- Durable Objects と WebSockets を使用してリアルタイム機能を実装する場合
- cron トリガーとスケジュールされたハンドラを設定する場合
- worker 間通信のためにサービスバインディングを構成する場合
- 環境変数、シークレット、およびマルチ環境デプロイを管理する場合
いつ使うべきでないか:
- CPU 時間制限を超える長時間実行の計算タスク (従来のサーバーまたは Workflows を使用)
- Hyperdrive なしで外部データベースへの永続的な TCP 接続を必要とするアプリケーション
- リクエストごとに 128 MB を超えるメモリを必要とするワークロード
カバーする主なパターン:
- Wrangler の構成 (
wrangler.jsonc) とプロジェクトのセットアップ - Fetch ハンドラ、スケジュールされたハンドラ、およびキューハンドラ
- KV キーバリューストレージ (キャッシング、設定、セッションデータ)
- D1 SQLite データベース (エッジでのリレーショナルデータ)
- R2 S3 互換オブジェクトストレージ (ファイル、アップロード、アセット)
- Durable Objects (ステートフルなエッジコンピューティング、WebSockets、連携)
- Cloudflare Queues (非同期メッセージ処理)
- Workers AI (エッジでの推論)
- 型付きバインディングによるフレームワーク統合 (Hono の例)
- 環境変数、シークレット、およびマルチ環境構成
- サービスバインディング (worker 間 RPC)
- Cron トリガーとスケジュールされたワーカー
- ストリーミングとパフォーマンスの最適化
- Workers ネイティブのテストプールを使用したテスト
<philosophy>
哲学
Cloudflare Workers は、世界中の 300 以上のデータセンターで、V8 isolate (コンテナではない) 上で実行されます。コールドスタートなしで 5ms 未満で起動します。プログラミングモデルは、従来のサーバーとは根本的に異なります。
- API よりもバインディング - Cloudflare サービス (KV、D1、R2、Queues) には、REST API 呼び出しではなく、
envパラメータ上の直接インプロセスバインディングを通してアクセスします。バインディングには、ネットワークホップや認証のオーバーヘッドがありません。 - デフォルトでステートレス - 各リクエストは、新しい実行コンテキストを取得します。Workers は V8 isolate を再利用するため、モジュールレベルの変数はリクエスト間で永続化されます — これはバグの元であり、機能ではありません。
- すべてをストリーム処理 - Workers には 128 MB のメモリ制限があります。何もバッファリングせず、
TransformStreamとpipeToを使用してリクエストとレスポンスのボディをストリーム処理します。 - エッジファーストアーキテクチャ - コードはユーザーに最も近い場所で実行されます。連携または状態が必要な場合は Durable Objects を使用し、永続化には D1/KV/R2 を使用します。
Workers をいつ使うべきか:
- API エンドポイント、ミドルウェア、およびリクエストルーティング
- キャッシュレイヤーとコンテンツ変換
- Webhook レシーバーとイベントプロセッサ
- リアルタイムコラボレーション (Durable Objects を使用)
- フルスタックアプリケーション (Workers Static Assets または Pages を使用)
Workers をいつ使うべきでないか:
- 制限を超える CPU 集中型の計算 (リクエストごとに 10ms 無料 / 30s 有料)
- 128 MB を超えるメモリを必要とするワークロード
- 永続的なデータベース接続を必要とするアプリケーション (プロキシとして Hyperdrive を使用)
- 制限を超える長時間実行のバックグラウンドジョブ (永続的な実行のために Workflows を使用)
</philosophy>
<patterns>
コアパターン
パターン 1: プロジェクトのセットアップと Wrangler の構成
すべての Workers プロジェクトは wrangler.jsonc から始まります。Cloudflare は JSON 形式を推奨しています — 一部の新しい機能は JSON 形式のみに対応しています。バインディングを変更した後は、wrangler types を実行して Env インターフェースを再生成してください。
(原文はここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Cloudflare Workers Patterns
Quick Guide: Cloudflare Workers run TypeScript/JavaScript on Cloudflare's global edge network with V8 isolates (not containers). Use
wrangler.jsoncfor configuration,wrangler devfor local development, andwrangler deployfor production. Access KV, D1, R2, Queues, Durable Objects, and Workers AI through type-safe bindings on theenvparameter. Runwrangler typesto auto-generate yourEnvinterface. Stream large payloads — Workers have a 128 MB memory limit. Never store request-scoped state in module-level variables.
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST run wrangler types to generate your Env interface — NEVER hand-write binding types)
(You MUST use wrangler.jsonc for new projects — Cloudflare recommends JSON config and some features are JSON-only)
(You MUST stream large request/response bodies — NEVER buffer entire payloads in memory (128 MB limit))
(You MUST avoid module-level mutable state — Workers reuse V8 isolates across requests, causing cross-request data leaks)
(You MUST use bindings for Cloudflare services (KV, D1, R2, Queues) — NEVER use REST APIs from within Workers)
</critical_requirements>
Examples
- Core Setup & Configuration — wrangler.jsonc, project init, fetch handler, secrets, multi-env, CI/CD, testing
- KV Storage — KV binding, typed get/put, TTL, stale-while-revalidate caching
- D1 Database — D1 binding, parameterized queries, batch ops, migrations, CRUD API
- R2 Object Storage — R2 binding, file upload/download/delete with streaming
- Durable Objects — DO classes, SQLite, RPC, rate limiter, WebSocket chat
- Routing & Middleware — API framework integration, middleware, queues, cron, service bindings, AI, streaming
- Quick Reference — Wrangler CLI commands, binding type signatures, config template, CPU limits
Auto-detection: Cloudflare Workers, wrangler, wrangler.toml, wrangler.jsonc, Workers KV, Cloudflare KV, D1 database, R2 bucket, Durable Objects, Cloudflare Queues, Workers AI, service binding, miniflare, compatibility_date, compatibility_flags, nodejs_compat, cloudflare:workers, ExportedHandler, DurableObject, wrangler dev, wrangler deploy, wrangler types, Cloudflare Pages Functions, edge worker, CF Worker
When to use:
- Deploying TypeScript/JavaScript to Cloudflare's edge network
- Configuring Wrangler CLI for local development and deployment
- Using Cloudflare bindings: KV, D1, R2, Queues, Durable Objects, Workers AI
- Building APIs on Workers with a framework (e.g., Hono)
- Implementing real-time features with Durable Objects and WebSockets
- Setting up cron triggers and scheduled handlers
- Configuring service bindings for worker-to-worker communication
- Managing environment variables, secrets, and multi-environment deploys
When NOT to use:
- Long-running compute tasks exceeding CPU time limits (use traditional servers or Workflows)
- Applications requiring persistent TCP connections to external databases without Hyperdrive
- Workloads needing more than 128 MB memory per request
Key patterns covered:
- Wrangler configuration (
wrangler.jsonc) and project setup - Fetch handler, scheduled handler, and queue handler
- KV key-value storage (caching, config, session data)
- D1 SQLite database (relational data at the edge)
- R2 S3-compatible object storage (files, uploads, assets)
- Durable Objects (stateful edge compute, WebSockets, coordination)
- Cloudflare Queues (async message processing)
- Workers AI (inference at the edge)
- Framework integration (Hono examples) with typed bindings
- Environment variables, secrets, and multi-environment config
- Service bindings (worker-to-worker RPC)
- Cron triggers and scheduled workers
- Streaming and performance optimization
- Testing with Workers-native test pool
<philosophy>
Philosophy
Cloudflare Workers run on V8 isolates (not containers) across 300+ data centers worldwide. They start in under 5ms with zero cold starts. The programming model is fundamentally different from traditional servers:
- Bindings over APIs - Access Cloudflare services (KV, D1, R2, Queues) through direct in-process bindings on the
envparameter, not REST API calls. Bindings have zero network hop and zero auth overhead. - Stateless by default - Each request gets a fresh execution context. Workers reuse V8 isolates, so module-level variables persist across requests — this is a bug source, not a feature.
- Stream everything - Workers have a 128 MB memory limit. Buffer nothing; stream request and response bodies using
TransformStreamandpipeTo. - Edge-first architecture - Code runs closest to the user. Use Durable Objects when you need coordination or state; use D1/KV/R2 for persistence.
When to use Workers:
- API endpoints, middleware, and request routing
- Caching layers and content transformation
- Webhook receivers and event processors
- Real-time collaboration (with Durable Objects)
- Full-stack applications (with Workers Static Assets or Pages)
When NOT to use Workers:
- CPU-intensive compute exceeding limits (10ms free / 30s paid per request)
- Workloads requiring more than 128 MB memory
- Applications needing persistent database connections (use Hyperdrive as a proxy)
- Long-running background jobs exceeding limits (use Workflows for durable execution)
</philosophy>
<patterns>
Core Patterns
Pattern 1: Project Setup and Wrangler Configuration
Every Workers project starts with wrangler.jsonc. Cloudflare recommends JSON format — some newer features are JSON-only. Run wrangler types after changing bindings to regenerate the Env interface.
// wrangler.jsonc
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "my-api",
"main": "src/index.ts",
"compatibility_date": "2025-09-15",
"compatibility_flags": ["nodejs_compat"],
"observability": { "enabled": true },
"placement": { "mode": "smart" },
"upload_source_maps": true,
}
See examples/core.md for full project initialization, multi-environment config, secrets management, CI/CD, and testing setup.
Pattern 2: Fetch Handler (Request/Response)
The fetch handler is the entry point for HTTP requests. Use satisfies ExportedHandler<Env> for type safety.
import type { ExportedHandler } from "cloudflare:workers";
export default {
async fetch(request, env, ctx): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === "/health") {
return Response.json({ status: "healthy" });
}
return new Response("Not Found", { status: 404 });
},
} satisfies ExportedHandler<Env>;
Never store mutable state in module-level variables — V8 isolate reuse causes cross-request data leaks. See examples/core.md for complete handler with CORS and routing.
Pattern 3: KV Key-Value Storage
KV is an eventually-consistent key-value store for read-heavy workloads. Use typed get<T>(key, "json"), always set expirationTtl, and use ctx.waitUntil() for non-blocking writes.
const CACHE_TTL_SECONDS = 3_600;
const profile = await env.CACHE.get<UserProfile>(`user:${id}`, "json");
ctx.waitUntil(
env.CACHE.put(`user:${id}`, JSON.stringify(data), {
expirationTtl: CACHE_TTL_SECONDS,
}),
);
When to use: Read-heavy workloads (config, cache, feature flags) where eventual consistency is acceptable (~60s propagation).
When not to use: Relational data (use D1), frequent writes to same key, strong consistency (use Durable Objects).
See examples/kv.md for stale-while-revalidate pattern and full caching examples.
Pattern 4: D1 SQLite Database
D1 is serverless SQLite at the edge. Always use parameterized queries via prepare().bind() to prevent SQL injection. Use batch() for atomic multi-statement operations. Use withSession() for read replica consistency when read replication is enabled.
const user = await db
.prepare("SELECT * FROM users WHERE email = ?")
.bind(email)
.first<User>();
const { results } = await db
.prepare("SELECT * FROM users LIMIT ? OFFSET ?")
.bind(DEFAULT_PAGE_SIZE, offset)
.all<User>();
See examples/d1.md for migrations, batch operations, and full CRUD API.
Pattern 5: R2 Object Storage
R2 is S3-compatible storage with zero egress fees. Always stream R2 bodies directly to responses — never call .arrayBuffer() or .text() on large objects.
const object = await env.BUCKET.get(key);
if (!object) return new Response("Not Found", { status: 404 });
const headers = new Headers();
object.writeHttpMetadata(headers);
return new Response(object.body, { headers }); // Stream directly
See examples/r2.md for file service with content-type validation and list operations.
Pattern 6: Durable Objects (Stateful Edge Compute)
Durable Objects provide single-threaded, strongly consistent compute. Each instance has SQLite storage. Use RPC methods (not fetch) and blockConcurrencyWhile for schema migrations.
import { DurableObject } from "cloudflare:workers";
export class Counter extends DurableObject<Env> {
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
ctx.blockConcurrencyWhile(async () => {
this.ctx.storage.sql.exec("CREATE TABLE IF NOT EXISTS ...");
});
}
async increment(name: string): Promise<number> {
/* RPC method */
}
}
When to use: Coordination (chat, collaboration), per-entity state (sessions, game instances), WebSocket connections, rate limiting.
When not to use: Stateless requests, high fan-out, global rate limiting (bottleneck).
See examples/durable-objects.md for rate limiter and WebSocket chat with hibernation.
Pattern 7: Queues, Cron, Service Bindings, Workers AI
Queues decouple producers from consumers with at-least-once delivery and configurable retries. Cron triggers invoke Workers on a schedule. Service bindings enable zero-cost worker-to-worker calls. Workers AI runs inference on Cloudflare's GPU network.
See examples/routing.md for all these patterns with full configuration and code examples.
Pattern 8: API Framework Integration
For structured APIs, use a routing framework with typed bindings. Export the framework's fetch handler alongside scheduled/queue handlers.
import { Hono } from "hono";
const app = new Hono<{ Bindings: Env }>();
app.get("/users/:id", async (c) => {
const user = await c.env.DB.prepare("SELECT * FROM users WHERE id = ?")
.bind(c.req.param("id"))
.first();
return user ? c.json(user) : c.json({ error: "Not found" }, 404);
});
export default app;
See examples/routing.md for production API with middleware, error handling, and multi-handler setup.
</patterns>
<performance>
Performance Optimization
Request Processing
| Technique | Impact |
|---|---|
Smart Placement ("mode": "smart") |
Routes to optimal data center based on binding locations |
| Streaming responses | Avoids 128 MB memory limit, improves TTFB |
ctx.waitUntil() for background work |
Returns response immediately, processes async work after |
nodejs_compat flag |
Access Node.js built-in modules (crypto, buffer, stream) |
Storage Performance
| Storage | Reads | Writes | Consistency | Best For |
|---|---|---|---|---|
| KV | Fast (edge cached) | Slow (~60s propagation) | Eventually consistent | Cache, config, flags |
| D1 | Medium | Medium | Strong (per-region) | Relational data, queries |
| R2 | Medium | Medium | Strong | Files, blobs, uploads |
| Durable Objects | Fast (in-memory) | Fast (SQLite) | Strong (single-threaded) | Coordination, real-time |
Hyperdrive for External Databases
When connecting to PostgreSQL/MySQL outside Cloudflare, always use Hyperdrive. It maintains a connection pool close to your database, eliminating per-request TCP/TLS overhead.
CPU Time Limits
| Plan | CPU Time per Request |
|---|---|
| Free | 10 ms |
| Paid | 30 seconds (default), configurable up to 15 minutes |
| Cron Triggers | 15 minutes |
</performance>
<decision_framework>
Decision Framework
Choosing a Storage Primitive
What kind of data?
|
+-- Key-value pairs (cache, config, sessions)
| +-- Read-heavy, eventual consistency OK --> KV
| +-- Strong consistency needed --> Durable Objects
|
+-- Relational data with queries
| +-- Edge-native SQLite --> D1
| +-- External PostgreSQL/MySQL --> Hyperdrive
|
+-- Files and blobs (images, documents)
| +-- S3-compatible storage --> R2
|
+-- Coordination state (chat, multiplayer, collaboration)
| +-- Single-threaded consistency --> Durable Objects
|
+-- Message passing / background work
+-- Simple fan-out, buffering --> Queues
+-- Multi-step durable execution --> Workflows
Choosing Between Workers and Pages
What are you building?
|
+-- API only (no frontend) --> Workers
|
+-- Static site + API --> Pages with Functions
|
+-- Full-stack with SSR --> Pages (framework) or Workers + Static Assets
|
+-- Background processing / cron --> Workers (Pages lacks cron support)
|
+-- Real-time / WebSockets --> Workers + Durable Objects
When to Use Durable Objects vs D1
Do you need coordination between concurrent requests?
|
+-- YES (chat, game, collaboration) --> Durable Objects
| +-- Single-threaded, no race conditions
| +-- WebSocket support with hibernation
| +-- Per-entity sharding (one DO per room/session)
|
+-- NO (CRUD, reporting, querying) --> D1
+-- Full SQL support
+-- Cross-entity queries
+-- Traditional database patterns
</decision_framework>
<integration>
Integration Guide
Cloudflare Platform Services:
- Hyperdrive: Connection pooling proxy for external PostgreSQL/MySQL — eliminates per-request TCP/TLS overhead
- Vectorize: Vector database for embeddings and semantic search with Workers AI
- Cloudflare Pages: Static site hosting with Workers-powered functions for full-stack apps
- GitHub Actions:
cloudflare/wrangler-action@v3for CI/CD deployment
Framework & ORM Compatibility:
Workers are compatible with edge-optimized frameworks and ORMs that support the V8 runtime. Any framework that exports a fetch handler works (Hono, itty-router, etc.). D1 works with any ORM that supports SQLite (check your ORM's Workers compatibility docs).
Testing:
Use @cloudflare/vitest-pool-workers to run tests inside the actual Workers runtime with real bindings (KV, D1, R2). See examples/core.md for test configuration.
</integration>
<red_flags>
RED FLAGS
High Priority Issues:
- Storing request-scoped data in module-level variables (V8 isolate reuse causes cross-request leaks)
- Buffering entire request/response bodies with
.text()/.arrayBuffer()(128 MB memory limit) - Hand-writing
Envinterface instead of runningwrangler types(mismatches between config and code) - Using REST APIs for KV/D1/R2/Queues from within Workers instead of bindings (unnecessary latency and auth overhead)
- Putting secrets in
wrangler.jsonc, source code, or environment variables (usewrangler secret put) - Creating a single global Durable Object for all traffic (bottleneck at ~1000 req/sec)
Medium Priority Issues:
- Using
wrangler.tomlfor new projects (JSON format recommended, some features JSON-only) - Outdated
compatibility_date(misses runtime improvements and bug fixes) - Missing
observabilityconfig (production Workers are a black box without logs/traces) - Destructuring
ctxin fetch handler (losesthisbinding,ctx.waitUntilthrows "Illegal invocation") - Using
exec()for D1 queries instead ofprepare().bind()(no parameterization, SQL injection risk) - Not reciprocating WebSocket close in Durable Objects (causes 1006 errors)
Common Mistakes:
- Forgetting that KV is eventually consistent (~60s propagation) and expecting instant reads after writes
- Using
Math.random()for security-sensitive tokens (usecrypto.randomUUID()orcrypto.getRandomValues()) - Not using
ctx.waitUntil()for post-response background work (work may be cancelled when response is sent) - Comparing secrets with
===instead ofcrypto.subtle.timingSafeEqual()(timing side-channel attack) - Using
passThroughOnException()as error handling (hides bugs, use explicit try/catch) - Floating promises (not awaited, not returned, not passed to
waitUntil()) causing silent failures — enable@typescript-eslint/no-floating-promisesto catch at dev time
Gotchas and Edge Cases:
- Bindings (KV, D1, R2, etc.) are NOT inherited across Wrangler environments — you must re-declare them per environment
wrangler devuses local simulation by default; use--remoteto test against real Cloudflare services- D1 batch operations execute sequentially (not in parallel) but atomically
- Durable Objects in-memory state is lost on eviction — always persist important data to SQLite first
- Unnecessary
awaitbetween DO storage writes breaks write coalescing — batch writes happen atomically when you don't await between them - DO alarm handlers may fire multiple times — design them to be idempotent
- Using
blockConcurrencyWhile()on every request limits throughput to ~200 req/sec — use it only for initialization - Workers on the free plan have a 10ms CPU time limit per request (not wall-clock time — I/O waiting is free)
- Cron trigger changes take up to 15 minutes to propagate globally
.dev.varsfile is for local secrets only and must be gitignored- The
envparameter is provided per-request by the runtime; avoid caching binding references or derived objects at module scope
</red_flags>
<critical_reminders>
CRITICAL REMINDERS
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST run wrangler types to generate your Env interface — NEVER hand-write binding types)
(You MUST use wrangler.jsonc for new projects — Cloudflare recommends JSON config and some features are JSON-only)
(You MUST stream large request/response bodies — NEVER buffer entire payloads in memory (128 MB limit))
(You MUST avoid module-level mutable state — Workers reuse V8 isolates across requests, causing cross-request data leaks)
(You MUST use bindings for Cloudflare services (KV, D1, R2, Queues) — NEVER use REST APIs from within Workers)
Failure to follow these rules will result in memory crashes (buffering), data leaks (module state), type mismatches (hand-written Env), unnecessary latency (REST over bindings), and secret exposure (secrets in config).
</critical_reminders>