workers-best-practices

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @cloudflare/workers-types, wrangler, and 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 the latest Cloudflare documentation. - Type and Config Validation: Verifies Env interfaces, handler signatures, binding access patterns, and wrangler.jsonc fields against current @cloudflare/workers-types and the 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, use this Skill to validate the wrangler.jsonc config, confirm binding names match code, and flag any floating promises or missing nodejs_compat flags. ## 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 schema first, then check types, config, patterns, and security in order. Validate with `npx tsc --noEmit` and lint for no-floating-promises, citing line numbers and docs links as evidence.

What are common Cloudflare Workers anti-patterns to avoid?▼

Key anti-patterns include awaiting response.text() on unbounded data, hardcoded secrets, Math.random() for tokens, floating promises, module-level request state, and calling the Cloudflare REST API instead of using bindings. Each causes memory exhaustion, leaks, or dropped work.

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

Use wrangler.jsonc for new projects because newer Workers features are JSON-only and JSONC supports comments. TOML is legacy and acceptable in existing projects but should be flagged in new ones.

Why does destructuring ctx throw Illegal invocation in Workers?▼

Destructuring `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 in Durable Objects versus module handlers?▼

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

When should I use Hyperdrive for database connections in Workers?▼

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