workers-best-practices

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

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

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, and misconfigured bindings that cause runtime failures or security issues. ## Core Features & Use Cases - Best-Practice Rule Enforcement: Checks configuration, streaming, waitUntil usage, bindings, observability, and security rules against current Cloudflare documentation. - Type and Config Validation: Verifies Env interfaces, handler signatures, binding access patterns, and wrangler.jsonc fields against the latest workers-types and wrangler config schema. - Anti-Pattern Detection: Flags issues like await response.text() on unbounded data, Math.random() for tokens, destructured ctx, and implements on platform base classes. - Use Case: When reviewing a pull request that adds a new Worker with KV bindings, load this skill to validate the wrangler config, check binding access patterns, and catch floating promises before merge. ## Quick Start Review my Cloudflare Worker code and wrangler.jsonc for best-practice violations and common 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?

Fetch the latest Workers best practices page, workers-types, and wrangler config schema first, then check types, config, patterns, and security in order. Validate with `npx tsc --noEmit` and lint for no-floating-promises, and report findings with severity levels and line references.

What are common Cloudflare Workers anti-patterns to avoid?

Key anti-patterns include buffering unbounded responses with `await response.text()`, floating promises without await or 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.jsonc or wrangler.toml for new projects?

Use wrangler.jsonc for new projects because newer Workers features are JSON-only and JSONC supports comments for documenting config decisions. TOML is legacy and should be flagged in new projects, though it remains acceptable in existing ones.

Why does destructuring ctx cause Illegal invocation errors in Workers?

Destructuring `const { waitUntil } = ctx` loses the `this` binding that the method depends on, throwing "Illegal invocation" at runtime. Always call `ctx.waitUntil()` directly on the ExecutionContext object passed to your handler.

How do I access bindings in Durable Objects versus module handlers?

Module export handlers like fetch access bindings via the `env` parameter, while classes extending platform base classes like DurableObject or WorkerEntrypoint use `this.env`. Mixing these patterns is the most common binding access error.

When should I use Hyperdrive for database connections in Workers?

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