Skip to content
Web apps

Cloudflare Workers rules

Workers rules for agents: bindings from env, wrangler types, prepared D1 queries, waitUntil, secrets via wrangler secret, no deploys or --remote writes unasked.

Verified install Not agent-tested v1.0.0 MIT updated cloudflarecloudflare-workerstypescript
Equips
  • 1 1 Rules
  • 1 1 Skills
  • 1 1 MCP

Agents can scaffold a Worker in a minute; the trouble is what they do next: deploy to production to test a change, apply D1 migrations with --remote, keep request data in module scope, call the REST API instead of a binding, or put a token in vars. This loadout sets the rules we use on our own Workers and D1 project, connects Cloudflare's public documentation MCP server so the agent checks current APIs and limits, and includes an endpoint skill whose example Worker the verifier type-checks against the Workers runtime types.

What's in it

  • No wrangler deploy or --remote writes unless asked in the session
  • wrangler types after binding changes; strict type-check
  • Prepared D1 statements and migrations applied --local first
  • No request state in module scope; ctx.waitUntil for background work
  • Cloudflare docs MCP server (public, no auth)

You'll need

  • Tools: node, wrangler
  • MCP servers: cloudflare-docs
Level 1 · automated

Verification

Verified install

Checked at commit c77eea0 · 10 passed, 0 failed

CheckResultWhat we found
Listinglisting.yaml matches the schema and declares every file in the folder. Pass
Schema valid; 6 files declared, none missing or extra
  • tested.status: untested (agent tests are separate from Level 1)
Files parseJSON parses; SKILL.md and .mdc front matter is valid YAML with the fields each agent needs; code fences are closed. Pass All 6 files parse; front matter valid
AdaptersCLAUDE.md imports @AGENTS.md, GEMINI.md imports @./AGENTS.md, and both match the generator. Pass
CLAUDE.md and GEMINI.md import AGENTS.md and are up to date
  • CLAUDE.md: matches the generator
  • GEMINI.md: matches the generator
Install pathsEvery file lands where each agent documents it, with no collisions, and the laid-out project is re-discovered correctly. Pass
Correct paths for all 6 agents; layouts re-discovered
  • Claude Code: 5 files, 1 skill in .claude/skills/, MCP at .mcp.json
  • Codex CLI: 3 files, 1 skill in .agents/skills/, MCP manual step
  • Cursor: 4 files, 1 skill in .agents/skills/, MCP at .cursor/mcp.json
  • Gemini CLI: 4 files, 1 skill in .agents/skills/, MCP manual step
  • Antigravity CLI: 4 files, 1 skill in .agents/skills/, MCP at .agents/mcp_config.json
  • GitHub Copilot: 3 files, 1 skill in .agents/skills/, MCP manual step
MCP configmcp.json is structurally valid, converts to each agent's format, declares no literal secrets, and referenced packages exist on npm/PyPI. Pass
1 server valid: cloudflare-docs
  • mcp.json → cloudflare-docs: docs.mcp.cloudflare.com is reachable over HTTPS
  • Converts to Codex config.toml, Gemini CLI settings.json, VS Code mcp.json and Antigravity CLI .agents/mcp_config.json (serverUrl)
Safety scanThe intake scanner finds no credentials, risky shell, hidden Unicode or prompt-injection wording, and the listing's network flag is honest. Pass
Clean: no credentials, risky shell or hidden text
  • Scanner intake-precheck/1: verdict clean; network yes (listing says yes)
  • info mcp-server in mcp.json: cloudflare-docs: url https://docs.mcp.cloudflare.com/mcp
ReferencesLinks and file paths between the loadout's files resolve, including for each agent's installed layout. Pass 2 references between files resolve for every agent
Size limitsFile count and sizes are within the submission limits; SKILL.md bodies stay under 500 lines. Pass
6 files, 6.5 KB total; largest skills/worker-endpoint/references/index.ts 2.3 KB
  • Limits: 30 files, 32 KB per file, 128 KB total, 500 lines per skill or rule
LicenceA recognised SPDX licence, with the licence text available. Pass MIT, by Agent Loadout; text in the repository LICENSE
Starter buildA minimal fixture project with the loadout applied installs and builds or type-checks, and the loadout's own code examples compile. Pass
The worker-endpoint skill's example Worker type-checks under strict TypeScript against the Workers runtime types: D1 prepared statements, KV, waitUntil and ExportedHandler<Env>
  • Applied 10 loadout files at every agent's paths
  • ✓ place the example Worker: bash -c mkdir -p src && cp .agents/skills/worker-endpoint/references/index.ts src/index.ts && echo placed
  • ✓ install: npm ci --no-audit --no-fund
  • ✓ tsc --noEmit (strict): npm run check
  • ✓ no secrets in vars or code: bash -c ! grep -nE '(api[_-]?key|secret|token)\s*[:=]\s*"[^"]+"' src/index.ts && echo clean
  • Covers: ExportedHandler<Env> with bindings from env (D1, KV, a var)
  • Covers: D1 statements use prepare().bind(); no interpolated SQL
  • Covers: ctx.waitUntil for the cache write after the response
  • Covers: Validated input with 400 and 404 responses and JSON Content-Type

What this means: a script checked the files themselves: they parse, they install where each agent looks, any MCP config is sound, the safety scan is clean, references between files resolve, and, where a free and repeatable fixture exists, a small starter project builds with the loadout applied. No AI agent was run. Per-agent results ("tested with agent") are separate and stay untested until an agent actually runs.

Install

Choose your agent. Run the commands from your project root, or download a zip already laid out in the right folders.

Claude Code reads CLAUDE.md (imports AGENTS.md with @AGENTS.md) and skills from .claude/skills/.

Download zip
curl -fsSL --create-dirs -o AGENTS.md https://loadout.jnw-it.com/raw/cloudflare-workers/1.0.0/AGENTS.md
curl -fsSL --create-dirs -o CLAUDE.md https://loadout.jnw-it.com/raw/cloudflare-workers/1.0.0/CLAUDE.md
curl -fsSL --create-dirs -o .claude/skills/worker-endpoint/SKILL.md https://loadout.jnw-it.com/raw/cloudflare-workers/1.0.0/skills/worker-endpoint/SKILL.md
curl -fsSL --create-dirs -o .claude/skills/worker-endpoint/references/index.ts https://loadout.jnw-it.com/raw/cloudflare-workers/1.0.0/skills/worker-endpoint/references/index.ts
curl -fsSL --create-dirs -o .mcp.json https://loadout.jnw-it.com/raw/cloudflare-workers/1.0.0/mcp.json
FileGoes to
AGENTS.mdAGENTS.md
CLAUDE.mdCLAUDE.md
skills/worker-endpoint/SKILL.md.claude/skills/worker-endpoint/SKILL.md
skills/worker-endpoint/references/index.ts.claude/skills/worker-endpoint/references/index.ts
mcp.json.mcp.json

Already have an AGENTS.md or CLAUDE.md? The commands above overwrite it — download the file instead and merge the sections you want.

Files

Rules AGENTS.md Workers runtime, Wrangler, D1 and secrets rules. 33 lines
Download Raw
# AGENTS.md: Cloudflare Workers

TypeScript Worker deployed with Wrangler. Config is in `wrangler.jsonc` (or `wrangler.toml` in older projects).

## Commands
- Local dev: `npx wrangler dev`. Logs from a deployed Worker: `npx wrangler tail`.
- After changing bindings or config: `npx wrangler types` to regenerate the `Env` types, then `npx tsc --noEmit`.
- Tests: `npx vitest run` with `@cloudflare/vitest-pool-workers` if configured.
- Done means: types regenerated if bindings changed, type-check and tests pass, and the route works under `wrangler dev`.

## Never without the human asking in this session
- `npx wrangler deploy`, `wrangler versions deploy` or any command with `--remote` against production data.
- `wrangler d1 migrations apply <db> --remote`, `wrangler kv` writes or `wrangler r2 object` writes on production namespaces.
- Changing `compatibility_date`, routes, custom domains or account settings.

## Runtime rules
- No request data in module scope. Isolates are reused across requests; globals leak between users.
- Use bindings (KV, D1, R2, Queues, Durable Objects, service bindings) from `env`, not the REST API with a token.
- Background work after the response goes in `ctx.waitUntil(promise)`. Never leave a promise floating.
- D1: always `env.DB.prepare(sql).bind(...)`; never interpolate values into SQL. Schema changes are migration files
  (`npx wrangler d1 migrations create <db> <name>`), applied with `--local` first.
- Large bodies: stream them; do not buffer whole files in memory.
- Node APIs need the `nodejs_compat` compatibility flag. Check before importing `node:*` modules.
- Validate input and return proper status codes and `Content-Type`. Set CORS headers only for listed origins.

## Secrets
- Secrets with `npx wrangler secret put <NAME>`; local values in `.dev.vars`, which stays gitignored.
- Never put secrets in `vars` in `wrangler.jsonc`, in code or in test fixtures.

## Docs
- The Cloudflare docs MCP server (`cloudflare-docs`) searches current Workers, D1, R2 and Wrangler docs. Check APIs
  and limits there instead of relying on memory. New endpoints: use the `worker-endpoint` skill.
Adapter CLAUDE.md Imports AGENTS.md for Claude Code. 11 lines
Download Raw
# CLAUDE.md

@AGENTS.md

## Claude Code notes
- Skills from this loadout live in `.claude/skills/`: `worker-endpoint`. Use them when their description matches the task.
- MCP servers for this project are in `.mcp.json`. If a server is not connected, tell the human rather than working around it.
- Follow AGENTS.md above; where this file and AGENTS.md disagree, AGENTS.md wins.

<!-- From the Agent Loadout "Cloudflare Workers rules" v1.0.0 — https://loadout.jnw-it.com/loadouts/cloudflare-workers/ -->
Adapter GEMINI.md Imports AGENTS.md for Gemini CLI. 10 lines
Download Raw
# GEMINI.md

@./AGENTS.md

## Gemini CLI notes
- Skills from this loadout live in `.agents/skills/`: `worker-endpoint`. Use them when their description matches the task.
- Follow AGENTS.md above; where this file and AGENTS.md disagree, AGENTS.md wins.

<!-- From the Agent Loadout "Cloudflare Workers rules" v1.0.0 — https://loadout.jnw-it.com/loadouts/cloudflare-workers/ -->
Skill skills/worker-endpoint/SKILL.md Add a Worker route with bindings and checks. 16 lines
Download Raw
---
name: worker-endpoint
description: Add an endpoint to a Cloudflare Worker using bindings from env, validated input, parameterised D1 queries, waitUntil for background work and a local check. Use when adding or changing a Worker route.
---

# Worker endpoint

1. Read `wrangler.jsonc` for bindings and flags, and the Worker's router or `fetch` handler.
2. If you need a new binding, add it to `wrangler.jsonc` and run `npx wrangler types`. Ask before creating remote
   resources (`wrangler d1 create`, `wrangler kv namespace create`).
3. Write the handler like `references/index.ts`: parse and validate input, use `env` bindings, prepared D1 statements,
   JSON responses with the right status, and `ctx.waitUntil` for work that can finish after the response.
4. If the schema changes: `npx wrangler d1 migrations create <db> <name>`, write the SQL, apply with `--local`.
5. Run `npx tsc --noEmit` and the tests. Start `npx wrangler dev` and call the route once with curl or the test client.
6. Report the route, bindings used, migrations added and check results. Do not deploy.
Skill file skills/worker-endpoint/references/index.ts Example Worker with D1, KV and waitUntil. 57 lines
Download Raw
// Example Worker: bindings from env, validated input, prepared D1 statements, waitUntil for background work.
// The Env interface is what `npx wrangler types` generates for these bindings.

export interface Env {
  DB: D1Database;
  CACHE: KVNamespace;
  ALLOWED_ORIGIN: string;
}

type Note = { id: number; text: string; created_at: string };

const json = (data: unknown, status = 200, origin?: string): Response =>
  new Response(JSON.stringify(data), {
    status,
    headers: {
      "Content-Type": "application/json; charset=utf-8",
      ...(origin ? { "Access-Control-Allow-Origin": origin, Vary: "Origin" } : {}),
    },
  });

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const url = new URL(request.url);
    const origin = request.headers.get("Origin") === env.ALLOWED_ORIGIN ? env.ALLOWED_ORIGIN : undefined;

    if (request.method === "GET" && url.pathname.startsWith("/notes/")) {
      const id = Number(url.pathname.slice("/notes/".length));
      if (!Number.isInteger(id) || id < 1) return json({ error: "id must be a positive integer" }, 400, origin);
      const cached = await env.CACHE.get<Note>(`note:${id}`, "json");
      if (cached) return json(cached, 200, origin);
      const note = await env.DB.prepare("SELECT id, text, created_at FROM notes WHERE id = ?").bind(id).first<Note>();
      if (!note) return json({ error: "not found" }, 404, origin);
      ctx.waitUntil(env.CACHE.put(`note:${id}`, JSON.stringify(note), { expirationTtl: 300 }));
      return json(note, 200, origin);
    }

    if (request.method === "POST" && url.pathname === "/notes") {
      let body: unknown;
      try {
        body = await request.json();
      } catch {
        return json({ error: "invalid JSON" }, 400, origin);
      }
      const text = typeof body === "object" && body !== null && "text" in body ? (body as { text: unknown }).text : undefined;
      if (typeof text !== "string" || text.length === 0 || text.length > 2000) {
        return json({ error: "text must be 1 to 2000 characters" }, 400, origin);
      }
      const row = await env.DB.prepare("INSERT INTO notes (text) VALUES (?) RETURNING id, text, created_at")
        .bind(text)
        .first<Note>();
      return json(row, 201, origin);
    }

    return json({ error: "not found" }, 404, origin);
  },
} satisfies ExportedHandler<Env>;
MCP config mcp.json Cloudflare documentation MCP server (remote, public). 9 lines
Download Raw
{
  "mcpServers": {
    "cloudflare-docs": {
      "type": "http",
      "url": "https://docs.mcp.cloudflare.com/mcp"
    }
  }
}

All files: source zip · Licence MIT · By Agent Loadout · First listed

Credits

Public work that inspired this loadout. The wording here is our own; follow the links for the originals.

Installing and testing

How do I install Cloudflare Workers rules in Claude Code?

From your project root, put AGENTS.md, CLAUDE.md, skills/worker-endpoint/SKILL.md at .claude/skills/worker-endpoint/SKILL.md, skills/worker-endpoint/references/index.ts at .claude/skills/worker-endpoint/references/index.ts, mcp.json at .mcp.json. The "Claude Code" tab on this page has the curl commands, or download https://loadout.jnw-it.com/download/cloudflare-workers/claude-code.zip, which is already laid out. Do not overwrite an existing AGENTS.md or CLAUDE.md; merge it.

How do I install Cloudflare Workers rules in Codex CLI?

From your project root, put AGENTS.md, skills/worker-endpoint/SKILL.md at .agents/skills/worker-endpoint/SKILL.md, skills/worker-endpoint/references/index.ts at .agents/skills/worker-endpoint/references/index.ts. The "Codex CLI" tab on this page has the curl commands, or download https://loadout.jnw-it.com/download/cloudflare-workers/codex.zip, which is already laid out. mcp.json needs a manual step: Codex reads MCP servers from ~/.codex/config.toml (TOML, not JSON). Add each server with `codex mcp add` or copy the URL into an [mcp_servers.<name>] table. Do not overwrite an existing AGENTS.md or CLAUDE.md; merge it.

How do I install Cloudflare Workers rules in Cursor?

From your project root, put AGENTS.md, skills/worker-endpoint/SKILL.md at .agents/skills/worker-endpoint/SKILL.md, skills/worker-endpoint/references/index.ts at .agents/skills/worker-endpoint/references/index.ts, mcp.json at .cursor/mcp.json. The "Cursor" tab on this page has the curl commands, or download https://loadout.jnw-it.com/download/cloudflare-workers/cursor.zip, which is already laid out. Do not overwrite an existing AGENTS.md or CLAUDE.md; merge it.

How do I install Cloudflare Workers rules in Gemini CLI?

From your project root, put AGENTS.md, GEMINI.md, skills/worker-endpoint/SKILL.md at .agents/skills/worker-endpoint/SKILL.md, skills/worker-endpoint/references/index.ts at .agents/skills/worker-endpoint/references/index.ts. The "Gemini CLI" tab on this page has the curl commands, or download https://loadout.jnw-it.com/download/cloudflare-workers/gemini-cli.zip, which is already laid out. mcp.json needs a manual step: Gemini CLI reads MCP servers from the mcpServers block of .gemini/settings.json. Merge the servers in by hand, and use httpUrl instead of url for HTTP servers. Since 18 June 2026 Gemini CLI serves only Gemini Code Assist Standard/Enterprise licences and paid API keys; personal accounts use Antigravity CLI. Do not overwrite an existing AGENTS.md or CLAUDE.md; merge it.

How do I install Cloudflare Workers rules in Antigravity CLI?

From your project root, put AGENTS.md, skills/worker-endpoint/SKILL.md at .agents/skills/worker-endpoint/SKILL.md, skills/worker-endpoint/references/index.ts at .agents/skills/worker-endpoint/references/index.ts, mcp.json at .agents/mcp_config.json. The "Antigravity CLI" tab on this page has the curl commands, or download https://loadout.jnw-it.com/download/cloudflare-workers/antigravity-cli.zip, which is already laid out. Do not overwrite an existing AGENTS.md or CLAUDE.md; merge it.

How do I install Cloudflare Workers rules in GitHub Copilot?

From your project root, put AGENTS.md, skills/worker-endpoint/SKILL.md at .agents/skills/worker-endpoint/SKILL.md, skills/worker-endpoint/references/index.ts at .agents/skills/worker-endpoint/references/index.ts. The "GitHub Copilot" tab on this page has the curl commands, or download https://loadout.jnw-it.com/download/cloudflare-workers/copilot.zip, which is already laid out. mcp.json needs a manual step: In VS Code, MCP servers go in .vscode/mcp.json under a "servers" key (not "mcpServers"). Copilot CLI uses ~/.copilot/mcp-config.json. Do not overwrite an existing AGENTS.md or CLAUDE.md; merge it.

Has Cloudflare Workers rules been tested?

It passed the Level 1 automated install checks on 2026-10-17: the files parse, install to each agent's documented paths, and pass the safety scan. No AI agent has run it yet, so no agent pass or fail is claimed.

More for Claude Code, Codex, Cursor, Gemini CLI, Antigravity CLI and GitHub Copilot.