workers-best-practices

Reviews and authors Cloudflare Workers code against current production best practices and type definitions.

Updated Oct 15, 2019
One-click install
npx skills add https://github.com/kkkaoru/dotfiles --skill workers-best-practices-kkkaoru
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: workers-best-practices
Source: https://github.com/kkkaoru/dotfiles/tree/main/.agents/skills-stroage/workers-best-practices
Command: npx skills add https://github.com/kkkaoru/dotfiles --skill workers-best-practices-kkkaoru

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Cloudflare Workers APIs, types, and wrangler configuration evolve constantly, so code written from stale knowledge ships with anti-patterns like floating promises, global request state, hardcoded secrets, and outdated binding access. This Skill grounds Workers authoring and code review in freshly retrieved official documentation and type definitions. ## Core Features & Use Cases - Retrieval-first workflow: Fetches the latest Workers best practices page, @cloudflare/workers-types, and the wrangler config schema before writing or reviewing any code. - Rule-based review: Checks configuration (compatibility_date, nodejs_compat, secrets, observability), request handling (streaming, waitUntil), architecture (bindings, Queues, Workflows, Hyperdrive), and security (Web Crypto, timing-safe comparisons). - Anti-pattern detection: Flags concrete issues such as await response.text() on unbounded data, destructured ctx, implements on platform base classes, and env.X misuse inside DurableObject or WorkerEntrypoint classes. - Use Case: When reviewing a pull request that adds a new Worker with KV and Queue bindings, load this Skill to validate the wrangler.jsonc config, verify binding access patterns against the latest types, and catch floating promises before merge. ## 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?

Retrieve 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 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 DurableObject or WorkerEntrypoint class?

Use this.env.X inside classes extending platform base classes like DurableObject, WorkerEntrypoint, or Workflow. Use the env.X parameter only in module export handlers such as fetch, scheduled, and queue.

Why does destructuring ctx cause Illegal invocation in Workers?

Destructuring ctx with const { waitUntil } = ctx loses the this binding, so calling waitUntil throws Illegal invocation at runtime. Always call ctx.waitUntil() directly on the context 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 requires the nodejs_compat compatibility flag.