workers-best-practices

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Cloudflare Workers APIs, types, and wrangler configuration change frequently, so pre-trained knowledge produces outdated code, broken configs, and subtle anti-patterns like floating promises, global request state, and hardcoded secrets. ## Core Features & Use Cases - Best-Practice Rule Enforcement: Applies canonical rules for compatibility dates, nodejs_compat, streaming, waitUntil, bindings, observability, and Web Crypto security. - Structured Code Review: Runs an eight-step review workflow covering types, config validity, binding-code consistency, serialization boundaries, and severity-ranked findings. - Retrieval-First Grounding: Fetches the latest Cloudflare docs, @cloudflare/workers-types, and the wrangler config schema before writing or reviewing code. - Use Case: When reviewing a pull request that adds a new Worker with KV and Queue bindings, load this Skill to flag a stale compatibility_date, a hand-written Env interface, and an un-awaited fetch call, each with a suggested fix. ## Quick Start Review my Cloudflare Worker code and wrangler.jsonc against the latest Workers 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?▼

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, and report findings with severity levels and suggested fixes.

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 from inside a Worker 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. TOML is legacy and acceptable in existing projects but should be flagged in new ones.

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

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

Why does destructuring ctx throw Illegal invocation in Workers?▼

Destructuring ctx with const { waitUntil } = ctx loses the this binding, causing an Illegal invocation error at runtime. Always call ctx.waitUntil() directly on the ExecutionContext object.

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

Always use Hyperdrive for external PostgreSQL or MySQL connections from a Worker. It maintains a regional connection pool that eliminates per-request TCP, TLS, and auth overhead, and it requires the nodejs_compat flag.