Cloudflare Workers Skill
Quick Start
Use this skill when the user is implementing or configuring Cloudflare Workers, D1, R2, KV, Wrangler, or bindings. Terraform is out of scope until explicitly introduced as a feature; see AGENTS.md.
Scope
- •In scope: Worker code (TypeScript),
wrangler.toml, bindings (D1, R2, KV), Wrangler CLI (dev, deploy), secrets (.dev.vars), D1 migrations, R2 S3-compatible API, KV get/put. Worker and Docker are 1:1 (same app, same config). - •Out of scope: Terraform (ignore
infra/terraform/unless the user explicitly asks for it); Discord/SimHub (use their skills).
Conventions (this repo)
- •Secrets: Keep in
.dev.vars(or env-specific files). Never commit secrets;.dev.varsis in.gitignore. - •Bindings: Wire D1/R2/KV in
wrangler.toml; names/IDs from Cloudflare Dashboard or your own automation. Same config for Docker andwrangler dev. - •CPU: Workers have a 50ms CPU limit per request; design handlers to stay under or offload to Queues/Cron.
- •Stack: Workers (TypeScript), D1 (SQLite), R2 (S3-compatible), KV (caching). See ADR-001 and cost-optimized ADR.
Key Resources
- •Wrangler: Local dev
wrangler dev; deploywrangler deploy. Usewrangler d1 executefor migrations. - •D1: SQLite at the edge; use prepared statements and migrations. Free tier: 5M reads/day, 100K writes/day.
- •R2: S3-compatible; use AWS SDK or R2 API for plugin binaries and static assets. Zero egress fees.
- •KV: Key-value cache; use for hot data to reduce D1 reads (e.g. session or config cache).
Documentation
- •Prefer Cloudflare official docs and Cloudflare MCP (e.g.
search_cloudflare_documentation) or Context7 for current API and examples. - •ContextStream (when available): Before Grep/Read in
apps/api/, use ContextStreamsearch(mode=hybrid) for "Worker", "D1", "auth", "wrangler". After Worker/ADR decisions, capture in ContextStream (event_type=decision) with path to wrangler.toml or ADR. Use graph(action="impact", target="...") before refactoring Worker code. See development guide. - •Project docs: infrastructure, database schema, API. API docs: Each Worker endpoint is documented in docs/api/openapi.yaml and served in Swagger at /api-docs (local and Docker). When adding or changing routes, update the OpenAPI spec; smoke test ensures API documentation loads.
Checklist (when adding or changing a Worker)
- •
wrangler.tomldefines name, compatibility date, and bindings (d1_databases, r2_buckets, kv_namespaces). - • Secrets are in
.dev.varsand not committed. - • D1 migrations (if any) live in the Worker app and are run via
wrangler d1 executeor CI. - • Bindings in
wrangler.tomlmatch your D1/R2/KV resources (Dashboard or automation); Worker and Docker use the same config.