Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Expert patterns for building Cloudflare Workers applications including Durable Objects for stateful coordination, KV/R2/D1 storage tiers, Workers AI inference, and AI Gateway for LLM routing.
# Development
wrangler dev # Local dev server
wrangler dev --remote # Dev against production bindings# Deployment
wrangler deploy # Deploy to production
wrangler deploy --env staging # Deploy to staging environment# Type generation (ALWAYS run after editing wrangler.toml/wrangler.jsonc)
wrangler types # Generates worker-configuration.d.ts — never hand-write Env interface# Storage management
wrangler kv:key put --binding MY_KV "key""value"
wrangler kv:key get --binding MY_KV "key"
wrangler r2 object put my-bucket/path/file.txt --file ./local-file.txt
wrangler d1 execute my-db --file ./migrations/001.sql
wrangler d1 execute my-db --command"SELECT * FROM users LIMIT 5"# Secrets
wrangler secret put OPENAI_API_KEY # Prompts for value
wrangler secret list
# Durable Objects
wrangler durable-objects migrate apply # Apply pending migrations# Logs and observability
wrangler tail# Stream live logs from production
wrangler tail --format pretty
wrangler tail --json # Structured JSON log stream for analysis
Performance Patterns
// Use ctx.waitUntil() for non-blocking background workexportdefault {
asyncfetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const response = awaithandleRequest(request, env);
// Fire-and-forget: analytics, cache warm, audit logging
ctx.waitUntil(logAnalytics(request, response, env));
return response;
},
};
// Stream large bodies — never buffer fully into memoryasyncfunctionstreamBody(request: Request, env: Env): Promise<Response> {
const { readable, writable } = newTransformStream();
// Pipe without buffering — stays within 128MB Worker limit
request.body?.pipeTo(writable);
returnnewResponse(readable);
}
Durable Objects with SQLite (2025 default):
New Durable Objects should use the SQL API for storage — SQLite-backed DOs provide relational queries, indexes, and transactions:
exportclassRoomDOimplementsDurableObject {
privatesql: SqlStorage;
constructor(state: DurableObjectState, env: Env) {
this.state = state;
this.sql = state.storage.sql;
// Create tables on first initializationthis.sql.exec(
`CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY, ts INTEGER, body TEXT)`
);
}
asyncaddMessage(body: string): Promise<void> {
this.sql.exec('INSERT INTO messages (ts, body) VALUES (?, ?)', Date.now(), body);
}
asyncgetMessages(): Promise<{ id: number; ts: number; body: string }[]> {
return [...this.sql.exec('SELECT * FROM messages ORDER BY ts DESC LIMIT 50')];
}
}
Observability
Enable Workers Logs and Traces before any production deployment:
# Run tests
pnpm vitest run
# Run with Cloudflare runtime (recommended)
pnpm vitest run --pool @cloudflare/vitest-pool-workers
Related Skills
devops — CI/CD pipeline configuration for Cloudflare deployments
terraform-infra — Cloudflare Terraform provider for infrastructure-as-code
database-expert — D1 schema design and query optimization
container-expert — Cloudflare Containers (complementary to Workers)
Search Protocol
Before starting any Cloudflare Workers task, search for existing wrangler configs and worker scripts:
pnpm search:code "wrangler OR DurableObject OR KVNamespace OR R2Bucket"
pnpm search:code "cloudflare workers"
Use Skill({ skill: 'ripgrep' }) for fast search across .toml and .ts files. Use Skill({ skill: 'code-semantic-search' }) to find similar edge function patterns.
Memory Protocol (MANDATORY)
Before starting any task, you must query semantic memory and read recent static memory: