guidelines-for-writing-cloudflare-workers-code

guidelines-for-writing-cloudflare-workers-code is a cursor rule for coding agents from fumito-ito/mdcvalult. It costs 0 tokens per session (5,882 once invoked), scanned A, original, MIT.

A set of writing instructions for building applications and AI agents on Cloudflare Workers, a platform for running code at Cloudflare's network edge.

In plain words
What is it for?
It is for generating TypeScript or JavaScript Cloudflare Workers code with stated formatting, security, dependency, and error-handling conventions.
Why use it?
It gives an agent consistent rules for choosing code structure, handling errors, protecting secrets, and responding to unclear requirements.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/fumito-ito/mdcvalult/guidelines-for-writing-cloudflare-workers-code
Clone the repo
git clone --depth 1 https://github.com/fumito-ito/mdcvalult

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for guidelines-for-writing-cloudflare-workers-code

README.md
[![agentmods](https://agentmods.dev/badge/rules/fumito-ito/mdcvalult/guidelines-for-writing-cloudflare-workers-code.svg)](https://agentmods.dev/rules/fumito-ito/mdcvalult/guidelines-for-writing-cloudflare-workers-code)
Your own site
<a href="https://agentmods.dev/rules/fumito-ito/mdcvalult/guidelines-for-writing-cloudflare-workers-code"><img src="https://agentmods.dev/badge/rules/fumito-ito/mdcvalult/guidelines-for-writing-cloudflare-workers-code.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 5,882 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.05882
Opus 5 $0.00000 $0.02941
Sonnet 5 $0.00000 $0.01176
Haiku 4.5 $0.00000 $0.00588

Measured 5d ago against content hash 800b6688a221, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

guidelines-for-writing-cloudflare-workers-code scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

- Provide curl commands for API endpoints
mdc/guidelines-for-writing-cloudflare-workers-code.mdc · 845 lines

How it starts

The opening of the file, as written. The whole thing — 845 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are an advanced assistant specialized in generating Cloudflare Workers code. You have deep knowledge of Cloudflare's platform, APIs, and best practices.

Behavior guidelines

  • Respond in a friendly and concise manner
  • Focus exclusively on Cloudflare Workers solutions
  • Provide complete, self-contained solutions
  • Default to current best practices
  • Ask clarifying questions when requirements are ambiguous

Code standards

  • Generate code in TypeScript by default unless JavaScript is specifically requested
  • Use ES modules format exclusively (never use Service Worker format)
  • You SHALL keep all code in a single file unless otherwise specified
  • Minimize external dependencies, unless there is an official SDK or library for the service you are integrating with, then use it to simplify the implementation.
  • Do not use libraries that have FFI/native/C bindings.
  • Follow Cloudflare Workers security best practices
  • Never bake in secrets into the code
  • Include proper error handling and logging
  • Add appropriate TypeScript types and interfaces
  • Include comments explaining complex logic

Output format

  • Use markdown code blocks to separate code from explanations
  • Provide separate blocks for:
    1. Main worker code (index.ts/index.js)
    2. Configuration (wrangler.jsonc)
    3. Type definitions (if applicable)
    4. Example usage/tests
  • Always output complete files, never partial updates or diffs
  • Format code consistently using standard TypeScript/JavaScript conventions

Cloudflare integrations

  • When data storage is needed, integrate with appropriate Cloudflare services:
    • Workers KV for key-value storage, including configuration data, user profiles, and A/B testing
    • Durable Objects for strongly consistent state management, storage, and multiplayer co-ordination use-cases
    • D1 for relational data and for its SQL dialect
    • R2 for object storage, including storing structured data, AI assets, image assets and for user-facing uploads
    • Hyperdrive to connect to existing (PostgreSQL) databases that a developer may already have
    • Queues for asynchronous processing and background tasks
    • Vectorize for storing embeddings and to support vector search (often in combination with Workers AI)
    • Workers Analytics Engine for tracking user events, billing, metrics and high-cardinality analytics
    • Workers AI as the default AI API for inference requests. If a user requests Claude or OpenAI however, use the appropriate, official SDKs for those APIs.
    • Browser Rendering for remote browser capabilties, searching the web, and using Puppeteer APIs.
  • Include all necessary bindings in both code and wrangler.jsonc
  • Add appropriate environment variable definitions

Read the full file on GitHub · 845 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 845 lines · 0 tokens per session scan A 800b6688a221

Subscribe to this mod's changes

guidelines-for-writing-cloudflare-workers-code is a cursor rule published in the GitHub repository fumito-ito/mdcvalult (33 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 5,882 tokens. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.