workers-best-practices
This skill guides code review and development of Cloudflare Workers by applying best practices for production readiness.
Identity proven by a skills index on cloudflare.com
- Agents
- Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode, claude.ai and API
- License
- Apache-2.0 (permissive)
- Pin
- a84b615pinned Oct 9, 2026
- Context cost
- about 1,300 tokenswhen the skill loads
- GitHub stars
- 3,012on cloudflare/skills
- Scripts
- None found
What it does
“Cloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers.”
Generated summary from the skill's own text
This skill guides code review and development of Cloudflare Workers by applying best practices for production readiness. It covers configuration patterns, runtime behaviors, observability setup, and flags anti-patterns that can cause memory leaks, security issues, or data corruption. The agent references project-specific types, Wrangler configuration, and Cloudflare documentation to verify Workers APIs and compatibility.
When to use it
- Writing or reviewing Cloudflare Workers code for production
- Configuring observability, bindings, or compatibility dates in wrangler.toml
- Assessing runtime patterns like streaming, async work, or request state
- Identifying security issues like hardcoded secrets or weak token generation
When not to
- Managing Durable Objects, Workflows, or Wrangler CLI commands separately
- Guidance needed outside Workers-specific best practices domain
Install
These commands install from the publisher's repository and need no account.
skills CLI
npx skills add cloudflare/skills --skill workers-best-practicesInstalls from the repository's default branch, which may have changed since the commit we checked.
GitHub CLI 2.90 or later
gh skill install cloudflare/skills workers-best-practices@a84b615ff9d40e7f99755aea23d65e52d645bd42Installs the commit we checked (a84b615).
Copy by hand
Download the folder at a84b615 and put it in .claude/skills/workers-best-practices for Claude Code and in .agents/skills/workers-best-practices for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.
Claude Code plugin
/plugin install cloudflare@claude-plugins-officialThe publisher's plugin in Claude's official marketplace. It may hold more than this skill, and we have not pinned it.
Copy for your agent
A prompt for any coding agent. It installs this skill from GitHub at the pinned commit, copies the files as they are, and runs nothing unless you ask.
Prompt
Install the agent skill "workers-best-practices" by Cloudflare. Source, pinned to commit a84b615ff9d40e7f99755aea23d65e52d645bd42: https://github.com/cloudflare/skills/tree/a84b615ff9d40e7f99755aea23d65e52d645bd42/skills/workers-best-practices 1. Download that folder at exactly this commit. Do not use the default branch. 2. Copy every file unchanged, keeping the folder structure, into .claude/skills/workers-best-practices/ for Claude Code and .agents/skills/workers-best-practices/ for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode. Create the folders if they do not exist. 3. Do not edit the files, and do not run any script in the folder unless I ask you to. 4. When you are done, list the files you copied and where you put them. Listing and checks: https://www.agentnative.dev/skills/cloudflare/workers-best-practices
SKILL.md at the pin
---
name: workers-best-practices
description: Cloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers.
---
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](https://developers.cloudflare.com/workers/best-practices/workers-best-practices/index.md) or find the affected product in the [Cloudflare docs directory](https://developers.cloudflare.com/directory/index.md). 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](https://developers.cloudflare.com/workers/observability/logs/workers-logs/index.md) and [Traces](https://developers.cloudflare.com/workers/observability/traces/index.md) 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](https://developers.cloudflare.com/workflows/build/rules-of-workflows/index.md)
- **Wrangler CLI commands**: load the `wrangler` skill
From cloudflare/skills at a84b615, shown as plain text under its license: Apache-2.0 (permissive). The license text is in LICENSE.
View SKILL.md on GitHub at a84b615Files
- SKILL.md5.5 KB · 8ae8c6e73591
- references/
- configuration.md5.7 KB · cdb5c9cd5168
- platform-apis.md3.9 KB · 9ca9f5a7a82f
- runtime-patterns.md14 KB · 704ce8d4ff62
4 files, 29 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.
Skill folder on GitHub at a84b615More from Cloudflare
security-audit
This skill guides security audits of codebases, APIs, and services by finding vulnerabilities that cross real trust boundaries.
Contains scripts
Claude Code · about 5.4K tokens · pinned 6 days ago
kumo-design
Provides design rules for Cloudflare dashboard interfaces and Kumo UI components, covering text sizing, typography, spacing, borders, icons, animations, and…
Claude Code, Codex, Cursor +4 · about 1.5K tokens · pinned 6 days ago
agents-sdk
This skill helps build and debug Cloudflare Agents SDK applications, enabling creation of persistent agents with state management, RPC methods, scheduling…
Claude Code, Codex, Cursor +4 · about 3K tokens · pinned 6 days ago
basin
This skill helps agents build and troubleshoot Cloudflare Basin analytics workflows, which ingest events, transform data, manage Apache Iceberg tables in R2…
Claude Code, Codex, Cursor +4 · about 600 tokens · pinned 6 days ago
cloudflare
This skill helps agents discover Cloudflare products that match stated requirements and recommend the right combination for architecture and implementation.
Claude Code, Codex, Cursor +4 · about 6.4K tokens · pinned 6 days ago
cloudflare-email-service
This skill enables agents to send transactional emails and route incoming emails using Cloudflare's Email Service platform.
Claude Code, Codex, Cursor +4 · about 1.6K tokens · pinned 6 days ago
Related in Backend and APIs
durable-objects
Build and debug Cloudflare Durable Objects applications for stateful coordination and persistent storage on the edge.
by CloudflareOfficial publisher
Claude Code, Codex, Cursor +4 · about 1.5K tokens · pinned 6 days ago
upstash-ratelimit-js
This skill adds rate limiting to serverless and edge applications using the Upstash Rate Limit TypeScript SDK backed by Upstash Redis.
by upstashCommunity
Claude Code, Codex, Cursor +4 · about 250 tokens · pinned 6 days ago
nvflare-orient
Routes NVFLARE requests to appropriate downstream skills based on user intent and preliminary source inspection findings.
by NVIDIAOfficial publisher
Claude Code, Codex, Cursor +4 · about 600 tokens · pinned 6 days ago
supabase
This skill enables the agent to work with Supabase products including Database, Auth, Edge Functions, Realtime, Storage, and Vectors.
by SupabaseOfficial publisher
Claude Code, Codex, Cursor +4 · about 3.3K tokens · pinned 6 days ago
apple
This skill emulates Apple's OAuth and OIDC services for local development and testing.
by VercelOfficial publisher
Claude Code, Codex, Cursor +4 · about 1.9K tokens · pinned 6 days ago
custom-apis
Build custom HTTP API emulators to simulate third-party providers in local development and tests.
by VercelOfficial publisher
Claude Code, Codex, Cursor +4 · about 1.4K tokens · pinned 6 days ago