cloudflare/skills · Official

workers-best-practices

Cloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers.

All-time #380 Trending #290 Hot #6594 First seen Feb 12, 2026
8-week activity · all time api

Installation

$ npx skills add cloudflare/skills --skill workers-best-practices

Summary

  • Cloudflare Workers code review and authoring against production best practices.
  • Retrieves latest Workers APIs, types, and wrangler configuration schema before reviewing or writing code; biases towards live documentation over pre-trained knowledge Covers 40+ best practice rules across configuration, request/response handling, architecture, observability, code patterns, and security Flags 15+ common anti-patterns including unbounded streaming, floating promises, global request state, hardcoded secrets, and unsafe crypto usage Provides structured review workflow: retrieve references, validate types and config, check patterns and security, validate with tools

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Security audits

Partner security reviews for this skill.

agent-trust-hub MEDIUM

Analyzed Feb 17, 2026

The skill is designed for reviewing Cloudflare Workers code and involves downloading packages and fetching external documentation to stay current. These operations, specifically using shell commands like npm and tar to process remote content, present a medium security risk as they involve unverifiable external dependencies and command execution, although they are aligned with the skill's primary purpose.

snyk LOW

Analyzed Feb 15, 2026

No issues detected.

socket Score 0.9000 · 0 alerts

Analyzed Mar 18, 2026

  • license 1
  • maintenance 1
  • quality 0.9
  • supply chain 1
  • vulnerability 1

0 alerts

Also in this package

Other skills from cloudflare/skills · top by installs.

npx skills add cloudflare/skills

Browse all from cloudflare/skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 2.8K
License LICENSE
Default branch main
Open issues 8
Status Active

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 5,507 B
  • docs SUMMARY.md 3,969 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 73,800 installs

SKILL.md

Your knowledge of Cloudflare Workers APIs, types, and configuration may be outdated. Prefer retrieval over pre-training when writing or reviewing Workers code.

Use the project's installed versions, generated types, and Wrangler compatibility settings as the baseline for existing code. Retrieve relevant Cloudflare documentation to verify API, configuration, runtime behavior, and limit claims.

References

Read the sections relevant to the task:

Reference When to use it
[Configuration and observability](references/configuration.md) Compatibility dates, bindings, generated types, secrets, logs, and traces
[Runtime patterns](references/runtime-patterns.md) Streaming, promise lifetime, request state, service calls, security, and runtime tests
[Platform API checks](references/platform-apis.md) Handler signatures, platform classes, binding access, and serialization

For missing evidence, consult Workers best practices or find the affected product in the Cloudflare docs directory. Use the installed Wrangler schema for config fields. A newer type package does not supersede the project's configured target.

Keep Compatibility Dates Current

Use today's date for new Workers. Encourage periodic updates for existing Workers, reviewing compatibility changes and running relevant tests. Assess existing behavior against its configured date and flags; see [compatibility guidance](references/configuration.md#keep-compatibility_date-current).

Enable Observability

Enable Workers Logs and Traces when creating or preparing a Worker for production. Set observability.enabled and observability.traces.enabled to true; the top-level setting alone does not enable traces. Use structured JSON logging and configure sampling for the workload. During reviews, flag missing logs or traces. See the [configuration example](references/configuration.md#enable-workers-logs-and-traces).

Anti-Patterns to Flag

Anti-pattern Consequence and preferred pattern
await response.text() or similar buffering on unbounded data Can exhaust Worker memory; [stream large or unbounded bodies](references/runtime-patterns.md#stream-request-and-response-bodies).
Hardcoded secrets in source or config Leaks credentials through version control; use Wrangler secrets.
Math.random() for security-sensitive tokens or IDs Predictable values; use crypto.randomUUID() or crypto.getRandomValues().
Async work started without awaiting, returning, or attaching it to ctx.waitUntil() Work can be dropped and errors missed; tie it to the request or background-work lifetime.
Module-level mutable request state Leaks data across requests and can cause I/O ownership errors; pass request state explicitly.
Cloudflare REST API calls for operations available through Worker bindings Adds network and authentication overhead; use the available binding.
ctx.passThroughOnException() used as general error handling Can conceal Worker failures by forwarding to the origin; use explicit error handling and structured error responses.
Hand-written Env that duplicates Wrangler bindings Can drift from configuration; generate binding types with wrangler types.
Direct string comparison of secret values Can expose timing differences; use the [Web Crypto comparison pattern](references/runtime-patterns.md#use-web-crypto-for-secure-token-generation).
Destructuring ctx methods, such as const { waitUntil } = ctx Loses the receiver; call ctx.waitUntil(...).
any on Env or handler parameters Hides binding and handler contract errors; use the project's generated and platform types.
as unknown as T to force a platform type match Hides incompatibilities; fix the underlying contract.
implements used in place of extending a platform base class Does not inherit runtime behavior, this.ctx, or this.env; use the appropriate base class.
Unbound env.X in a platform class method Bindings are available through this.env.X; see [binding access patterns](references/platform-apis.md#binding-access--the-most-common-error).
Applying one serialization rule across Queues, Workflow steps, storage, and WebSockets Can reject valid payloads or accept unsupported ones; check the [specific API and encoding](references/platform-apis.md#serialization-boundaries).

Validation

Use the project's existing checks for affected Workers behavior: type-check binding or handler contract changes, and run relevant runtime tests for behavior changes. Preserve required repository checks; a narrow edit does not require a full Workers audit.

Scope

This skill covers Workers-specific best practices and code review. For related topics:

  • Durable Objects: load the durable-objects skill
  • Workflows: see Rules of Workflows
  • Wrangler CLI commands: load the wrangler skill