cloudflare-durable-objects
Design and write Cloudflare Durable Objects.
Skill by codewhale-hq
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/codewhale-hq-cloudflare-durable-objects
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: design, testing, cloud, writing
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/cloudflare-durable-objects
What's inside
- Skill name
cloudflare-durable-objects- Description
- Design and write Cloudflare Durable Objects. SQLite storage, RPC methods, WebSocket hibernation, alarms, class lifecycle (exports or migrations), and testing. Use for stateful coordination, rooms, per-user state, counters, rate limiters.
- License
- MIT
- Instructions
- 130 lines in SKILL.md · view on GitHub
Before installing
- Instructions call the network
Files (1)
- SKILL.md
SKILL.md (first lines)
# Cloudflare Durable Objects
A Durable Object is a class whose named instances each run in one place with
their own storage. Use one object per coordination unit (a chat room, a
document, a user, a game): that unit is the "atom". A single global object is a
bottleneck and almost always the wrong design.
Check current syntax with the `cloudflare-docs` plugin or
https://developers.cloudflare.com/durable-objects/ before relying on memory;
class lifecycle configuration changed recently (see below).
## Minimal SQLite-backed object with RPC
```ts
import { DurableObject } from "cloudflare:workers";
export class Counter extends DurableObject<Env> {
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
// Runs on every wake-up: keep it cheap and idempotent.
ctx.blockConcurrencyWhile(async () => {
ctx.storage.sql.exec("CREATE TABLE IF NOT EXISTS hits (n INTEGER NOT NULL)");
ctx.storage.sql.exec("INSERT INTO hits (n) SELECT 0 WHERE NOT EXISTS (SELECT 1 FROM hits)");
});
}
increment(): number {
this.ctx.storage.sql.exec("UPDATE hits SET n = n + 1");
return this.ctx.storage.sql.exec("SELECT n FROM hits").one().n as number;
}
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const stub = env.COUNTER.getByName(new URL(request.url).searchParams.get("id") ?? "default");
return Response.json({ n: await stub.increment() }); // RPC call
},
} satisfies ExportedHandler<Env>;
```
Binding and SQLite lifecycle are declared together in typed config:
```ts
import { bindings, defineConfig, exports } from "cf/config";
export default defineConfig({
worker: {
name: "counter", entrypoint: "src/index.ts", compatibilityDate: "2026-10-01",
env: { COUNTER: bindings.durableObject({ worker: "counter", exportName: "Counter" }) },
exports: { Counter: exports.durableObject({ storage: "sqlite" }) },
},
});
```
Review `cf migrate --dry-run` for legacy configurations and preserve the
existing class identity, storage and imperative migration history. Never mix
an existing migrations lifecycle with a new exports lifecycle. Use SQLite for
new namespaces; do not claim a deployed key-value class can be switched to it.
Check current cf/config helpers and generated lifecycle output against the
[configuration reference](https://developers.cloudflare.com/cf/projects/cloudflare-config/).
Do not infer correctness solely from a successful dry run: an ignored lifecycle
entry can pass packaging and still deploy the wrong storage.
## Lifecycle changes are dangerous
Defining a class locally is safe. Renaming, deleting or transferring a class is a
data-affecting operation:
- It is atomic: it cannot be uploaded as a version or deployed gradually, and
you cannot roll back past it. After approval, deploy it alone with
`cf deploy`.
- Deleting a class deletes its stored data. Renaming without a rename entry
orphans data.
- Always show the diff of the `exports` / `migrations` block to the user, name
the class and say whether data is lost, and wait for approval, as described
in `cloudflare-deploy`.
## WebSockets: use hibernation
```ts
async fetch(request: Request) {
if (request.headers.get("Upgrade") !== "websocket") return new Response("Expected WebSocket", { status: 426 });
const [client, server] = Object.values(new WebSocketPair());
this.ctx.acceptWebSocket(server); // not server.accept(): this allows hibernation
server.serializeAttachment({ joinedAt: Date.now() }); // survives hibernation
return new Response(null, { status: 101, webSocket: client });
}
async webSocketMessage(ws: WebSocket, message: string | ArrayBuffer) {
for (const peer of this.ctx.getWebSockets()) peer.send(message);
}
async webSocketClose(ws: WebSocket, code: number, reason: string) { ws.close(code, reason); }
```
- Do not use `addEventListener` for server-side sockets in a Durable Object.
- Memory is lost on hibernation. Anything needed after wake-up goes in storage or
`serializeAttachment`.
- A pending `setTimeout`/`setInterval` or an outbound WebSocket keeps the object
awake and billing; use alarms instead.
## Alarms
```ts
await this.ctx.storage.setAlarm(Date.now() + 60_000);
async alarm() { /* do work; call setAlarm again to repeat */ }
```
Alarms do not repeat on their own, and each object has one pending alarm. Only
schedule one when there is work to do; waking many objects every few seconds is
expensive.
## Rules of thumb
- Methods on the object are RPC: arguments and results must be structured-
cloneable; throw errors you want the caller to see.
- Reads and writes inside one request are protected by input/output gates; use
`blockConcurrencyWhile` only for initialization.
- Derive the object name from something stable (`getByName(userId)`), and
validate it; a user-supplied name creates an object.
- Test with `@cloudflare/vitest-pool-workers`: call RPC methods on a stub and
trigger alarms with `runDurableObjectAlarm(stub)`. Run `cf dev` to tryFrom codewhale-hq/codewhale-plugin-marketplace, MIT.
More from codewhale-hq/codewhale-plugin-marketplace
- 0.621score
computer-use
codewhale-hq
Operate desktop apps and isolated browsers on registered computers.
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
issue-triage
codewhale-hq
Triage and draft GitHub issues with the GitHub MCP tools - search for duplicates, classify and prioritize, and draft a well-formed new issue for the user to…
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
cloudflare-pages-to-workers
codewhale-hq
Migrate a Cloudflare Pages project to Workers with static assets.
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
issue-triage
codewhale-hq
Triage Linear issues and claim work with the Linear MCP tools - find the triage queue or your assigned work, check for duplicates and existing owners, set…
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
cloudflare-storage
codewhale-hq
Use Cloudflare KV, R2 and D1 from a Worker.
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
cloudflare-workers
codewhale-hq
Build, configure and test a Cloudflare Worker locally with cf (cloudflare.config.ts, typed bindings, static assets, cf dev, vitest).
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
review-panel
codewhale-hq
Fan six specialist reviewers (general correctness, silent failures, type design, test gaps, comment accuracy, simplification) out over the current diff, a…
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
iterate-until-done
codewhale-hq
Set up a bounded iterate-until-done run with the loop plugin's /loop command.
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
status-update
codewhale-hq
Write an evidence-based status update from Linear data - summarize what shipped, what is in progress, what is blocked or stale for a project, cycle, or a…
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
ui-critique
codewhale-hq
Critique a user interface (screenshot, running page, HTML/CSS, mockup or description) and return severity-ranked findings with evidence and a concrete fix for…
SkillAFreshness: A★ 5Claude Code +9 - 0.616score
chromewhale
codewhale-hq
Read and act on selected Chrome tabs and frames — their real browser, their logged-in sessions.
SkillAFreshness: A★ 5Claude Code +9 - 0.616score
cloudflare-deploy
codewhale-hq
Deploy or change a Cloudflare Worker with cf.
SkillAFreshness: A★ 5Claude Code +9
Signals
- Stars
- 5
- Forks
- 2
- Open issues
- 0
- Last commit (this folder)
- Oct 6, 2026 (22 days ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Website
- codewhale.net
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from codewhale-hq
- 0.724score
AGENTS.md · codewhale-hq/Codewhale
codewhale-hq
AGENTS.md from codewhale-hq/Codewhale: 266 lines covering The ponytail method, Working rules, Landing other people's work, Merging under a gate and more.
TemplateAFreshness: A★ 41.1KCodex +5 - 0.724score
Codewhale
codewhale-hq
Open-source Rust coding agent for the terminal that works with more than 40 model providers or local models
AgentAFreshness: A★ 41.1K - 0.621score
computer-use
codewhale-hq
Operate desktop apps and isolated browsers on registered computers.
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
cloudflare-storage
codewhale-hq
Use Cloudflare KV, R2 and D1 from a Worker.
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
cloudflare-pages-to-workers
codewhale-hq
Migrate a Cloudflare Pages project to Workers with static assets.
SkillAFreshness: A★ 5Claude Code +9 - 0.619score
cloudflare-workers
codewhale-hq
Build, configure and test a Cloudflare Worker locally with cf (cloudflare.config.ts, typed bindings, static assets, cf dev, vitest).
SkillAFreshness: A★ 5Claude Code +9
Cite this page
cloudflare-durable-objects skill. Agent Mart. https://agentmart.dev/skills/codewhale-hq-cloudflare-durable-objects (last updated 2026-10-24)