Agent Native

durable-objects

Build and debug Cloudflare Durable Objects applications for stateful coordination and persistent storage on the edge.

by CloudflareOfficial publisherNot reviewed

Identity proven by a skills index on cloudflare.com

Agents
Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode, claude.ai and API
License
Apache-2.0 (permissive)
Pin
a84b615pinned Oct 9, 2026
Context cost
about 1,500 tokenswhen the skill loads
GitHub stars
3,012on cloudflare/skills
Scripts
None found

What it does

“Build, debug, or review Cloudflare Durable Objects code for persistent state and coordination.”
The author's description, from SKILL.md

Generated summary from the skill's own text

Build and debug Cloudflare Durable Objects applications for stateful coordination and persistent storage on the edge. The skill guides agent implementation of RPC methods, alarms, WebSocket handlers, SQLite schema setup, and wrangler configuration. It includes anti-patterns to avoid and references to official API documentation.

When to use it

  • Creating stateful coordination systems like chat rooms or multiplayer games
  • Implementing strong consistency requirements for inventory or booking systems
  • Designing per-entity storage for multi-tenant SaaS applications
  • Setting up Durable Object bindings and SQLite migrations in wrangler config

When not to

  • Building stateless request handlers that don't need persistence
  • Requiring maximum global distribution without edge state coordination
  • Needing multiple independent Durable Objects for a single logical entity

Install

These commands install from the publisher's repository and need no account.

skills CLI

npx skills add cloudflare/skills --skill durable-objects

Installs from the repository's default branch, which may have changed since the commit we checked.

GitHub CLI 2.90 or later

gh skill install cloudflare/skills durable-objects@a84b615ff9d40e7f99755aea23d65e52d645bd42

Installs the commit we checked (a84b615).

Copy by hand

Download the folder at a84b615 and put it in .claude/skills/durable-objects for Claude Code and in .agents/skills/durable-objects for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.

Skill folder on GitHub at a84b615

Claude Code plugin

/plugin install cloudflare@claude-plugins-official

The publisher's plugin in Claude's official marketplace. It may hold more than this skill, and we have not pinned it.

Copy for your agent

A prompt for any coding agent. It installs this skill from GitHub at the pinned commit, copies the files as they are, and runs nothing unless you ask.

Prompt

Install the agent skill "durable-objects" by Cloudflare.

Source, pinned to commit a84b615ff9d40e7f99755aea23d65e52d645bd42:
https://github.com/cloudflare/skills/tree/a84b615ff9d40e7f99755aea23d65e52d645bd42/skills/durable-objects

1. Download that folder at exactly this commit. Do not use the default branch.
2. Copy every file unchanged, keeping the folder structure, into .claude/skills/durable-objects/ for Claude Code and .agents/skills/durable-objects/ for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode. Create the folders if they do not exist.
3. Do not edit the files, and do not run any script in the folder unless I ask you to.
4. When you are done, list the files you copied and where you put them.

Listing and checks: https://www.agentnative.dev/skills/cloudflare/durable-objects

SKILL.md at the pin

---
name: durable-objects
description: Build, debug, or review Cloudflare Durable Objects code for persistent state and coordination.
---

# Durable Objects

Build stateful, coordinated applications on Cloudflare's edge using Durable Objects.

## Retrieval Sources

Your knowledge of Durable Objects APIs and configuration may be outdated. **Prefer retrieval over pre-training** for any Durable Objects task.

| Resource | URL |
|----------|-----|
| Docs | https://developers.cloudflare.com/durable-objects/index.md |
| API Reference | https://developers.cloudflare.com/durable-objects/api/index.md |
| Best Practices | https://developers.cloudflare.com/durable-objects/best-practices/index.md |
| Examples | https://developers.cloudflare.com/durable-objects/examples/index.md |
| Roles and permissions | https://developers.cloudflare.com/workers/authorization/durable-objects/index.md |

Fetch the relevant doc page when implementing features.

## When to Use

- Creating new Durable Object classes for stateful coordination
- Implementing RPC methods, alarms, or WebSocket handlers
- Reviewing existing DO code for best practices
- Configuring wrangler.jsonc/toml for DO bindings and migrations
- Writing tests with Cloudflare’s Vitest integration
- Designing sharding strategies and parent-child relationships

## Reference Documentation

- `./references/rules.md` - Core rules, storage, concurrency, RPC, alarms
- [Testing reference](./references/testing.md) - Current Vitest documentation, migration choices, and test selection
- `./references/workers.md` - Workers handlers, types, wrangler config, observability

Search: `blockConcurrencyWhile`, `idFromName`, `getByName`, `setAlarm`, `sql.exec`

## Core Principles

### Use Durable Objects For

| Need | Example |
|------|---------|
| Coordination | Chat rooms, multiplayer games, collaborative docs |
| Strong consistency | Inventory, booking systems, turn-based games |
| Per-entity storage | Multi-tenant SaaS, per-user data |
| Persistent connections | WebSockets, real-time notifications |
| Scheduled work per entity | Subscription renewals, game timeouts |

### Do NOT Use For

- Stateless request handling (use plain Workers)
- Maximum global distribution needs
- High fan-out independent requests

## Quick Reference

### Wrangler Configuration

```jsonc
// wrangler.jsonc
{
  "durable_objects": {
    "bindings": [{ "name": "MY_DO", "class_name": "MyDurableObject" }]
  },
  "migrations": [{ "tag": "v1", "new_sqlite_classes": ["MyDurableObject"] }]
}
```

### Basic Durable Object Pattern

```typescript
import { DurableObject } from "cloudflare:workers";

export interface Env {
  MY_DO: DurableObjectNamespace<MyDurableObject>;
}

export class MyDurableObject extends DurableObject<Env> {
  constructor(ctx: DurableObjectState, env: Env) {
    super(ctx, env);
    ctx.blockConcurrencyWhile(async () => {
      this.ctx.storage.sql.exec(`
        CREATE TABLE IF NOT EXISTS items (
          id INTEGER PRIMARY KEY AUTOINCREMENT,
          data TEXT NOT NULL
        )
      `);
    });
  }

  async addItem(data: string): Promise<number> {
    const result = this.ctx.storage.sql.exec<{ id: number }>(
      "INSERT INTO items (data) VALUES (?) RETURNING id",
      data
    );
    return result.one().id;
  }
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const stub = env.MY_DO.getByName("my-instance");
    const id = await stub.addItem("hello");
    return Response.json({ id });
  },
};
```

## Critical Rules

1. **Model around coordination atoms** - One DO per chat room/game/user, not one global DO
2. **Use `getByName()` for deterministic routing** - Same input = same DO instance
3. **Use SQLite storage** - Configure `new_sqlite_classes` in migrations
4. **Initialize in constructor** - Use `blockConcurrencyWhile()` for schema setup only
5. **Use RPC methods** - Not fetch() handler (compatibility date >= 2024-04-03)
6. **Persist first, cache second** - Always write to storage before updating in-memory state
7. **One alarm per DO** - `setAlarm()` replaces any existing alarm

## Authorization

Durable Objects do not have separate roles or permissions; access follows the Worker that implements them. Retrieve the current [Durable Objects authorization guidance](https://developers.cloudflare.com/workers/authorization/durable-objects/index.md) before granting observability or Data Studio access, and scope the Workers role to the intended Worker or Workers product.

## Anti-Patterns (NEVER)

- Single global DO handling all requests (bottleneck)
- Using `blockConcurrencyWhile()` on every request (kills throughput)
- Storing critical state only in memory (lost on eviction/crash)
- Using `await` between related storage writes (breaks atomicity)
- Holding `blockConcurrencyWhile()` across `fetch()` or external I/O

## Stub Creation

```typescript
// Deterministic - preferred for most cases
const stub = env.MY_DO.getByName("room-123");

// From existing ID string
const id = env.MY_DO.idFromString(storedIdString);
const stub = env.MY_DO.get(id);

// New unique ID - store mapping externally
const id = env.MY_DO.newUniqueId();
const stub = env.MY_DO.get(id);
```

## Storage Operations

```typescript
// SQL (synchronous, recommended)
this.ctx.storage.sql.exec("INSERT INTO t (c) VALUES (?)", value);
const rows = this.ctx.storage.sql.exec<Row>("SELECT * FROM t").toArray();

// KV (async)
await this.ctx.storage.put("key", value);
const val = await this.ctx.storage.get<Type>("key");
```

## Alarms

```typescript
// Schedule (replaces existing)
await this.ctx.storage.setAlarm(Date.now() + 60_000);

// Handler
async alarm(): Promise<void> {
  // Process scheduled work
  // Optionally reschedule: await this.ctx.storage.setAlarm(...)
}

// Cancel
await this.ctx.storage.deleteAlarm();
```

## Testing

Read the [testing reference](./references/testing.md) before configuring a suite or writing Durable Object tests. It routes to current setup, APIs, and examples and identifies the behavior to cover.

From cloudflare/skills at a84b615, shown as plain text under its license: Apache-2.0 (permissive). The license text is in LICENSE.

View SKILL.md on GitHub at a84b615

Files

4 files, 19 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.

Skill folder on GitHub at a84b615
All 18 skills from Cloudflare

More from Cloudflare

  • security-audit

    This skill guides security audits of codebases, APIs, and services by finding vulnerabilities that cross real trust boundaries.

    Contains scripts

    Claude Code · about 5.4K tokens · pinned 6 days ago

  • kumo-design

    Provides design rules for Cloudflare dashboard interfaces and Kumo UI components, covering text sizing, typography, spacing, borders, icons, animations, and…

    Claude Code, Codex, Cursor +4 · about 1.5K tokens · pinned 6 days ago

  • agents-sdk

    This skill helps build and debug Cloudflare Agents SDK applications, enabling creation of persistent agents with state management, RPC methods, scheduling…

    Claude Code, Codex, Cursor +4 · about 3K tokens · pinned 6 days ago

  • basin

    This skill helps agents build and troubleshoot Cloudflare Basin analytics workflows, which ingest events, transform data, manage Apache Iceberg tables in R2…

    Claude Code, Codex, Cursor +4 · about 600 tokens · pinned 6 days ago

  • cloudflare

    This skill helps agents discover Cloudflare products that match stated requirements and recommend the right combination for architecture and implementation.

    Claude Code, Codex, Cursor +4 · about 6.4K tokens · pinned 6 days ago

  • cloudflare-email-service

    This skill enables agents to send transactional emails and route incoming emails using Cloudflare's Email Service platform.

    Claude Code, Codex, Cursor +4 · about 1.6K tokens · pinned 6 days ago

All Backend and APIs skills
  • workers-best-practices

    This skill guides code review and development of Cloudflare Workers by applying best practices for production readiness.

    by CloudflareOfficial publisher

    Claude Code, Codex, Cursor +4 · about 1.3K tokens · pinned 6 days ago

  • upstash-ratelimit-js

    This skill adds rate limiting to serverless and edge applications using the Upstash Rate Limit TypeScript SDK backed by Upstash Redis.

    by upstashCommunity

    Claude Code, Codex, Cursor +4 · about 250 tokens · pinned 6 days ago

  • nvflare-orient

    Routes NVFLARE requests to appropriate downstream skills based on user intent and preliminary source inspection findings.

    by NVIDIAOfficial publisher

    Claude Code, Codex, Cursor +4 · about 600 tokens · pinned 6 days ago

  • supabase

    This skill enables the agent to work with Supabase products including Database, Auth, Edge Functions, Realtime, Storage, and Vectors.

    by SupabaseOfficial publisher

    Claude Code, Codex, Cursor +4 · about 3.3K tokens · pinned 6 days ago

  • apple

    This skill emulates Apple's OAuth and OIDC services for local development and testing.

    by VercelOfficial publisher

    Claude Code, Codex, Cursor +4 · about 1.9K tokens · pinned 6 days ago

  • custom-apis

    Build custom HTTP API emulators to simulate third-party providers in local development and tests.

    by VercelOfficial publisher

    Claude Code, Codex, Cursor +4 · about 1.4K tokens · pinned 6 days ago

The skills listed here are third-party software, collected from public GitHub repositories as a catalog of recent skills and provided as is. Agent Native does not write or control them and is not responsible for any harm, loss or damage caused by installing or using them. Labels and checks describe what we saw at one commit and are not a guarantee. Read a skill's files before you run it. Terms of use