workers-best-practices

Reviews and validates Cloudflare Workers code against production best practices and platform APIs.

Updated Sep 21, 2026
One-click install
npx skills add https://github.com/maxentr/la-cuisine-de-mm --skill workers-best-practices-maxentr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: workers-best-practices
Source: https://github.com/maxentr/la-cuisine-de-mm/tree/main/.agents/skills/workers-best-practices
Command: npx skills add https://github.com/maxentr/la-cuisine-de-mm --skill workers-best-practices-maxentr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Cloudflare Workers APIs, types, and configuration options change frequently, so code written from stale knowledge often contains anti-patterns like buffered response bodies, hardcoded secrets, floating promises, or missing observability settings that cause production failures. ## Core Features & Use Cases - Anti-Pattern Detection: Flags common Workers mistakes such as unbounded body buffering, Math.random() for security tokens, module-level mutable state, and misused ctx.passThroughOnException(). - Configuration Review: Validates wrangler.jsonc settings including compatibility dates, nodejs_compat flags, generated Env types, secrets management, and observability (logs and traces) enablement. - Platform API Verification: Checks handler signatures, binding access patterns (env.X vs this.env.X), serialization boundaries for Queues, Durable Objects, and WebSockets, and stale class patterns. - Use Case: Before deploying a new Worker to production, run a review to confirm streaming is used for large payloads, ctx.waitUntil() handles background work, and Workers Logs and Traces are enabled with structured JSON logging. ## Quick Start Review my Cloudflare Worker code and wrangler configuration for production best practices and flag any anti-patterns.

Frequently Asked Questions about workers-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I review Cloudflare Workers code for best practices?

Check code against known anti-patterns: buffered unbounded response bodies, hardcoded secrets, Math.random() for tokens, floating promises, and module-level mutable state. Verify wrangler config uses current compatibility dates, nodejs_compat, and generated Env types from wrangler types.

How to enable observability for Cloudflare Workers?

Set observability.enabled and observability.traces.enabled to true in wrangler.jsonc; the top-level setting alone does not enable traces. Use head_sampling_rate to control volume and emit structured JSON logs via console.log(JSON.stringify({...})).

Why does my Cloudflare Worker crash on large responses?

Workers have a 128 MB memory limit, and buffering entire bodies with await response.text() or response.arrayBuffer() exhausts it on large payloads. Stream data through using TransformStream or pass response.body directly to the new Response.

Should I use bindings or the REST API in a Cloudflare Worker?

Use bindings for Cloudflare services like KV, R2, D1, and Queues instead of REST API calls. Bindings are direct in-process references with no network hop or authentication overhead, while REST calls add latency and credential management complexity.

What is the difference between env.X and this.env.X in Workers?

Module export handlers like fetch and scheduled access bindings via the env parameter, while platform base classes like WorkerEntrypoint, DurableObject, and Workflow access them via this.env.X. Using the wrong pattern is the most common binding error.

When should I use ctx.waitUntil in a Worker?

Use ctx.waitUntil() for background work like analytics, cache writes, or webhooks that should complete after the response is sent, with a 30-second post-response limit. Never destructure ctx, as it loses the this binding and throws Illegal invocation.