workers-best-practices

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

Updated Dec 9, 2025
One-click install
npx skills add https://github.com/Aki2022/skills --skill workers-best-practices-aki2022
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: workers-best-practices
Source: https://github.com/Aki2022/skills/tree/main/workers-best-practices
Command: npx skills add https://github.com/Aki2022/skills --skill workers-best-practices-aki2022

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, bindings, observability, security, and type safety, with severity-ranked findings. - Config Validation: Verifies wrangler.jsonc fields including compatibility_date, nodejs_compat, observability, secrets handling, and binding-code consistency against the official wrangler schema. - Retrieval-First Workflow: Fetches the latest Cloudflare docs, @cloudflare/workers-types, and wrangler config schema before reviewing, avoiding outdated API assumptions. - 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 nodejs_compat flag, and a public-HTTP Worker-to-Worker call that should be a service binding. ## 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 read full files and 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 line references.

What are common Cloudflare Workers anti-patterns to avoid?

Key anti-patterns include awaiting response.text() on unbounded data, hardcoding secrets, using 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 for documenting config decisions. TOML is acceptable in existing projects but should be flagged in new ones.

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

Inside classes extending platform base classes like DurableObject or WorkerEntrypoint, access bindings via this.env.X, not the env parameter. In module export handlers like fetch, use the env parameter directly, and always extend rather than implement platform base classes.

Why does destructuring ctx cause Illegal invocation in Workers?

Destructuring ctx with 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, since it maintains a regional connection pool that eliminates per-request TCP, TLS, and auth overhead. It requires the nodejs_compat compatibility flag.