workers-best-practices

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

3|Updated Nov 8, 2014
One-click install
npx skills add https://github.com/mintuz/.dotfiles --skill workers-best-practices-mintuz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: workers-best-practices
Source: https://github.com/mintuz/.dotfiles/tree/main/agents/.agents/skills/workers-best-practices
Command: npx skills add https://github.com/mintuz/.dotfiles --skill workers-best-practices-mintuz

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 Code Review: Checks Workers code against canonical rules covering streaming, waitUntil usage, bindings, observability, security, and type safety, with severity-rated findings. - Retrieval-First Workflow: Fetches the latest Cloudflare docs, @cloudflare/workers-types, and the wrangler config schema before reviewing, avoiding outdated API assumptions. - Config Validation: Verifies wrangler.jsonc fields such as compatibility_date, nodejs_compat, observability, secrets handling, and binding-code consistency. - Use Case: Before deploying a new Worker, ask for a review and receive flagged anti-patterns like Math.random() for tokens, missing ctx.waitUntil(), or a hand-written Env interface, each with a suggested fix. ## Quick Start Review my Cloudflare Worker code and wrangler.jsonc for best-practice violations and 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 findings with npx tsc --noEmit and a no-floating-promises lint rule, and report issues 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 without await or waitUntil, module-level mutable request state, and calling the Cloudflare REST API instead of using bindings.

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.

How do I access bindings in 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.

Why does destructuring ctx cause Illegal invocation errors in Workers?

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

When should I use Hyperdrive for database connections in Workers?

Use Hyperdrive whenever a Worker connects to an external PostgreSQL or MySQL database. It maintains a regional connection pool that eliminates per-request TCP, TLS, and auth overhead, and requires the nodejs_compat compatibility flag.