workers-best-practices

Reviews and writes Cloudflare Workers code against current configuration, runtime, and platform API best practices.

Updated Sep 17, 2026
One-click install
npx skills add https://github.com/bramanda48/skills --skill workers-best-practices-bramanda48
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: workers-best-practices
Source: https://github.com/bramanda48/skills/tree/main/skills/cloudflare-workers-best-practices
Command: npx skills add https://github.com/bramanda48/skills --skill workers-best-practices-bramanda48

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 outdated handler signatures. This Skill grounds Workers code writing and review in the project's installed Wrangler schema, generated types, and current Cloudflare documentation. ## Core Features & Use Cases - Configuration and observability checks: Verify compatibility dates, nodejs_compat flags, generated Env types via wrangler types, secret management, and Workers Logs/Traces setup. - Runtime pattern enforcement: Flag unbounded body buffering, module-level mutable state, floating promises, missing ctx.waitUntil, insecure Math.random() tokens, and passThroughOnException misuse. - Platform API validation: Check handler signatures, binding access patterns (env.X vs this.env.X), platform base class usage, and serialization boundaries for Queues, Workflows, Durable Objects, and WebSockets. - Use Case: While reviewing a pull request that adds a new Worker endpoint, use this Skill to catch a hardcoded API key in wrangler vars, an unawaited webhook fetch, and a hand-written Env interface that has drifted from the actual bindings. ## Quick Start Review my Cloudflare Worker code and wrangler.jsonc for best-practice violations and outdated API usage.

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 the project's wrangler.jsonc for current compatibility_date and nodejs_compat, verify bindings match generated types from wrangler types, and flag anti-patterns like buffered response bodies, floating promises, and hardcoded secrets. Consult current Cloudflare docs when API behavior is uncertain.

How do I enable logging and tracing 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({...})).

Should I use wrangler.toml or wrangler.jsonc for Workers config?

Prefer wrangler.jsonc over wrangler.toml because newer features are JSON-only and JSONC supports comments for documenting configuration decisions. Flag wrangler.toml in new projects.

Why does my Worker crash on large responses?

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

When should I use ctx.waitUntil in a Worker?

Use ctx.waitUntil() for background work like analytics, cache writes, or webhooks that should continue 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.

What are the limitations of passThroughOnException in Workers?

ctx.passThroughOnException() is a fail-open mechanism that forwards requests to the origin when the Worker throws, hiding bugs and complicating debugging. Use explicit try/catch blocks with structured JSON error responses and console.error logging instead.