agentleFS
Rikinshah787Rikinshah787/agent-skills-production-skills/skills/cloudflare-workers/SKILL.md

cloudflare-workers

Skill2 starsChanged 4 months agoMITView on GitHub

Use to build and deploy edge functions/APIs with Wrangler, and bind KV, R2, and D1 storage to your Worker.

  • Reads credentials

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use when: you need a fast, globally-distributed API, proxy, or edge middleware.

    line 19
  2. Very specific:

    Use when: you want serverless with minimal cold starts and edge KV/object/SQL storage.

    line 20
  3. Distinctive:

    Don't use for: long-running processes, big Node-native deps, or heavy CPU jobs (use a VM host).

    line 21
  4. Very specific:

    Always parameterize D1 SQL (.bind(...)) — never string-concatenate user input.

    line 106

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cloudflare Workers — Skillship

Run code on Cloudflare's global edge network with near-zero cold starts. A Worker is a fetch handler; storage comes from bindings — KV (key-value), R2 (S3-like objects), D1 (SQLite).

🧭 When to use this skill

  • Use when: you need a fast, globally-distributed API, proxy, or edge middleware.
  • Use when: you want serverless with minimal cold starts and edge KV/object/SQL storage.
  • Don't use for: long-running processes, big Node-native deps, or heavy CPU jobs (use a VM host).

⚡ Quickstart

1. Create a project (C3)

npm create cloudflare@latest -- my-worker
# choose: Hello World example → Worker only → JavaScript/TypeScript
cd my-worker

2. Develop locally

npx wrangler dev      # http://localhost:8787 ; first run opens browser to log in

3. Deploy

npx wrangler deploy   # publishes to <worker>.<subdomain>.workers.dev

The handler

export default {
  async fetch(request, env, ctx) {
    return new Response("Hello Worker!");
  },
};

env holds your bindings/secrets; ctx.waitUntil(promise) lets background work finish after the response.

🧩 Common recipes

Recipe: wrangler config with bindings (wrangler.jsonc)

{
  "name": "my-worker",
  "main": "src/index.ts",
  "compatibility_date": "2026-08-01",
  "kv_namespaces": [{ "binding": "CACHE", "id": "<kv-namespace-id>" }],
  "r2_buckets": [{ "binding": "BUCKET", "bucket_name": "my-bucket" }],
  "d1_databases": [{ "binding": "DB", "database_name": "app", "database_id": "<d1-id>" }],
  "vars": { "PUBLIC_FLAG": "true" }
}

Recipe: Use KV, R2, D1 from the handler

export default {
  async fetch(req, env) {
    await env.CACHE.put("k", "v", { expirationTtl: 60 });   // KV
    const obj = await env.BUCKET.get("file.png");           // R2
    const { results } = await env.DB.prepare(
      "SELECT * FROM users WHERE id = ?"                    // D1 (parameterized)
    ).bind(1).all();
    return Response.json({ results });
  },
};

Recipe: Secrets (encrypted, not in wrangler config)

npx wrangler secret put STRIPE_SECRET_KEY   # prompts for the value; access via env.STRIPE_SECRET_KEY

Recipe: Scheduled (cron) Worker

// wrangler.jsonc: "triggers": { "crons": ["0 * * * *"] }
export default {
  async scheduled(event, env, ctx) { /* runs on the cron schedule */ },
};

🚀 Ship to production

  • Secrets set with wrangler secret put — never in wrangler.jsonc vars (those are public).
  • compatibility_date pinned; bindings (KV/R2/D1) created and IDs referenced correctly.
  • Custom domain/route configured (or accept the workers.dev subdomain).
  • Background work wrapped in ctx.waitUntil() so it completes after the response.
  • Stay within Workers CPU-time/size limits; avoid Node-only APIs unless nodejs_compat is enabled.
  • For push-to-deploy, connect the repo to Workers Builds.

🔐 Security & secrets

  • vars in wrangler.jsonc are plaintext/public config; real secrets go through wrangler secret put (encrypted) and are read from env.
  • Always parameterize D1 SQL (.bind(...)) — never string-concatenate user input.
  • Scope KV/R2/D1 bindings to only what the Worker needs.

🐛 Common errors & fixes

SymptomLikely causeFix
env.X is undefinedBinding not declared in wrangler.jsoncAdd the kv_namespaces/r2_buckets/d1_databases entry
Background work didn't runPromise not awaited before responsectx.waitUntil(promise)
Node.js API not availableUsing Node built-insEnable nodejs_compat flag or avoid the API
Secret visible in dashboard configPut in varsMove to wrangler secret put
523 errors on first workers.dev deployNew subdomain warming upWait ~1 minute and retry

📚 Sources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.