jackspace/claudeskillz/cloudflare-durable-objects
- community
Checking that the SKILL.md file is still in the repository.
Guide to Cloudflare Durable Objects: globally unique, stateful objects for coordination, real- time communication and persistent state. Covers the DurableObject class and bindings, WebSocket Hibernation (ctx.acceptWebSocket, webSocketMessage, serializeAttachment), SQLite storage via ctx.storage.sql, alarms with storage.setAlarm and the alarm() handler, ids from idFromName, newUniqueId and getByName, RPC methods, blockConcurrencyWhile, migrations and location hints. Documents 15+ pitfalls: class not exported, missing or wrong migrations, new_sqlite_classes, constructor work and setTimeout or fetch breaking hibernation, in-memory state lost on hibernation, partial deleteAll on the KV backend, binding mismatches, state size limits and alarm retry failures. Use when building chat rooms, multiplayer games, rate limiters, session stores, queues or per-user state on Workers, or debugging DO migration, hibernation and alarm errors.
Install
npx vskill@latest install jackspace/claudeskillz/cloudflare-durable-objectsSKILL.md
Cloudflare Durable Objects
Status: Production Ready ✅ Last Updated: 2025-10-22 Dependencies: cloudflare-worker-base (recommended) Latest Versions: wrangler@4.43.0+, @cloudflare/workers-types@4.20251014.0+ Official Docs: https://developers.cloudflare.com/durable-objects/
What are Durable Objects?
Cloudflare Durable Objects are globally unique, stateful objects that provide:
- Single-point coordination - Each Durable Object instance is globally unique across Cloudflare's network
- Strong consistency - Transactional, serializable storage (ACID guarantees)
- Real-time communication - WebSocket Hibernation API for thousands of connections per instance
- Persistent state - Built-in SQLite database (up to 1GB) or key-value storage
- Scheduled tasks - Alarms API for future task execution
- Global distribution - Automatically routed to optimal location
- Automatic scaling - Millions of independent instances
Use Cases:
- Chat rooms and real-time collaboration
- Multiplayer game servers
- Rate limiting and session management
- Leader election and coordination
- WebSocket servers with hibernation
- Stateful workflows and queues
- Per-user or per-room logic
Quick Start (10 Minutes)
Option 1: Scaffold New DO Project
What this creates:
- Complete Durable Objects project structure
- TypeScript configuration
- wrangler.jsonc with bindings and migrations
- Example DO class implementation
- Worker to call the DO
Option 2: Add to Existing Worker
Create a Durable Object class (src/counter.ts):
Configure wrangler.jsonc:
Call from Worker (src/index.ts):
Deploy:
Durable Object Class Structure
Base Class Pattern
All Durable Objects MUST extend `DurableObject` from cloudflare:workers:
Constructor Pattern
CRITICAL Rules:
- ✅ Always call `super(ctx, env)` first
- ✅ Keep constructor minimal - heavy work blocks hibernation wake-up
- ✅ Use `ctx.blockConcurrencyWhile()` to initialize from storage before requests
- ❌ Never use `setTimeout` or `setInterval` - breaks hibernation (use alarms instead)
- ❌ Don't rely only on in-memory state with WebSockets - persist to storage
Exporting the Class
In Worker:
State API - Persistent Storage
Durable Objects provide two storage APIs depending on the backend:
- SQL API (SQLite backend) - Recommended
- Key-Value API (KV or SQLite backend)
Enable SQLite Backend (Recommended)
In wrangler.jsonc migrations:
Why SQLite?
- ✅ Up to 1GB storage (vs 128MB for KV backend)
- ✅ Atomic operations (deleteAll is all-or-nothing)
- ✅ SQL queries with transactions
- ✅ Point-in-time recovery (PITR)
- ✅ Synchronous KV API available too
SQL API
Access via ctx.storage.sql:
SQL API Methods:
CRITICAL SQL Rules:
- ✅ Always use parameterized queries with
?placeholders - ✅ Create indexes for frequently queried columns
- ✅ Use transactions for multi-statement operations
- ❌ Don't access the hidden
__cf_kvtable (used internally for KV API) - ❌ Don't enable SQLite on existing deployed KV-backed DOs (not supported)
Key-Value API
Available on both SQLite and KV backends via ctx.storage:
KV API Methods:
Storage Limits:
- SQLite backend: Up to 1GB storage per DO instance
- KV backend: Up to 128MB storage per DO instance
WebSocket Hibernation API
The WebSocket Hibernation API allows Durable Objects to:
- Handle thousands of WebSocket connections per instance
- Hibernate when idle (no messages, no events) to save costs
- Wake up automatically when messages arrive
- Maintain connections without incurring duration charges during idle periods
Use for: Chat rooms, real-time collaboration, multiplayer games, live updates
How Hibernation Works
- Active state - DO is in memory, handling messages
- Idle state - No messages for ~10 seconds, DO can hibernate
- Hibernation - In-memory state cleared, WebSockets stay connected to Cloudflare edge
- Wake up - New message arrives → constructor runs → handler method called
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cloudflare-durable-objects/SKILL.md
Popularity
- Repository stars
- 14
- Repository forks
- 6
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 9 May 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jackspace/claudeskillz/cloudflare-durable-objects)