workers-best-practices

Reviews and authors Cloudflare Workers code against production best practices and anti-patterns.

Updated May 5, 2026
One-click install
npx skills add https://github.com/Rocktown-Labs/reluxury --skill workers-best-practices-rocktown-labs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: workers-best-practices
Source: https://github.com/Rocktown-Labs/reluxury/tree/main/.agents/skills/workers-best-practices
Command: npx skills add https://github.com/Rocktown-Labs/reluxury --skill workers-best-practices-rocktown-labs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Cloudflare Workers APIs, types, and wrangler configuration change frequently, so code written from stale knowledge often contains anti-patterns like floating promises, global request state, hardcoded secrets, or incorrect binding access that cause runtime failures and security issues. ## Core Features & Use Cases - Best-Practice Rule Enforcement: Applies canonical rules for streaming, waitUntil, bindings, observability, Web Crypto, and error handling, with correct patterns and anti-patterns for each. - Type and Config Validation: Checks Env interfaces, handler signatures, binding-code consistency, compatibility_date, nodejs_compat, and secrets handling against the latest workers-types and wrangler config schema. - Structured Code Review Workflow: Runs an 8-step review process with severity-rated findings (CRITICAL/HIGH/MEDIUM/LOW) including file, line, evidence, and suggested fixes. - Use Case: Before deploying a new Worker that reads from R2 and calls another Worker, run a review to catch a hand-written Env interface, a missing service binding, and an unawaited fetch that would silently drop webhook deliveries. ## Quick Start Review my Cloudflare Worker code and wrangler.jsonc for best-practice violations and anti-patterns before I deploy.

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?

Fetch the latest best practices page, workers-types, and wrangler schema first, then check types, config, patterns, and security in that order. Validate findings with npx tsc --noEmit and a no-floating-promises lint rule, and report issues with severity, file, line, and a suggested fix.

What are common Cloudflare Workers anti-patterns to avoid?

Frequent issues include awaiting response.text() on unbounded data, floating promises without await or ctx.waitUntil, module-level mutable request state, hardcoded secrets, Math.random() for tokens, and calling the Cloudflare REST API instead of using bindings.

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

Use wrangler.jsonc for new projects because newer Wrangler features are JSON-only and JSONC supports comments. TOML is acceptable in existing projects but should be flagged when authoring new configuration.

Why does destructuring ctx throw Illegal invocation in Workers?

Destructuring ctx, such as const { waitUntil } = ctx, loses the this binding that waitUntil depends on, causing an Illegal invocation error at runtime. Always call ctx.waitUntil() directly on the context object.

How do I access bindings inside a Durable Object or WorkerEntrypoint class?

Classes extending platform base classes like DurableObject or WorkerEntrypoint access bindings via this.env.X, while module export handlers use the env parameter. Mixing these patterns is one of the most common binding access errors.

When should I use Hyperdrive instead of a direct database connection?

Use Hyperdrive for any external PostgreSQL or MySQL connection from a Worker, since it maintains a regional connection pool that eliminates per-request TCP, TLS, and auth overhead of often 300-500ms. It requires the nodejs_compat compatibility flag.