workers-best-practices

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

5|Updated Jan 31, 2026
One-click install
npx skills add https://github.com/nuggocto/dotfiles --skill workers-best-practices-nuggocto
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: workers-best-practices
Source: https://github.com/nuggocto/dotfiles/tree/main/opencode/skills/workers-best-practices
Command: npx skills add https://github.com/nuggocto/dotfiles --skill workers-best-practices-nuggocto

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 misconfigured bindings that cause runtime failures and security issues. ## 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 code, instead of relying on pre-trained knowledge. - Rule-based code 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) against documented rules with code examples. - Anti-pattern detection: Flags concrete issues such as await response.text() on unbounded data, destructured ctx, hand-written Env interfaces, implements on platform base classes, and non-serializable values crossing queue or storage boundaries. - Use Case: When reviewing a pull request that adds a new Worker with a Durable Object and KV binding, load this skill to validate binding access patterns, wrangler.jsonc fields, and type correctness with evidence-backed findings. ## Quick Start Ask the agent to review your Worker code and wrangler.jsonc against the latest Cloudflare 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 with npx tsc --noEmit and a no-floating-promises lint rule, and report findings with severity, file line references, and suggested fixes.

What are common Cloudflare Workers anti-patterns to avoid?

Key anti-patterns include awaiting response.text() on unbounded data, hardcoding secrets in wrangler vars, 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 legacy and acceptable in existing projects but should be flagged in new ones.

Why does destructuring ctx throw Illegal invocation in Workers?

Destructuring ctx with 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 ExecutionContext parameter.

How do I access bindings in Durable Objects versus module handlers?

Module export handlers like fetch and scheduled access bindings via the env parameter as env.X. Classes extending platform base classes such as DurableObject, WorkerEntrypoint, or Workflow must use this.env.X instead, and mixing these patterns is a common review finding.

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. Create a new Client per request using env.HYPERDRIVE.connectionString and enable the nodejs_compat flag.