# capnweb RPC Patterns

Applies capnweb stub lifecycle and disposal rules across RPC boundaries.

- Repository: https://github.com/cloudflare/computer (9770 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-10-29
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add cloudflare/computer --skill capnweb -g -a claude-code -y`
Codex: `npx skills add cloudflare/computer --skill capnweb -g -a codex -y`
Cursor: `npx skills add cloudflare/computer --skill capnweb -g -a cursor -y`
Gemini CLI: `npx skills add cloudflare/computer --skill capnweb -g -a gemini-cli -y`

## Description

capnweb RPC patterns for this repo, with a heavy focus on stub lifecycle and disposal. Load when touching anything that crosses the Durable Object ↔ computerd boundary: packages/rpc, packages/computer, the computerd client, or the Durable Object server. Triggers include "capnweb", "RpcTarget", "stub", "RPC wire", "promise pipelining", "stub disposal", "RpcPromise".

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# capnweb in this repo

[capnweb](https://github.com/cloudflare/capnweb) is the RPC framing
between the Durable Object and `computerd`. It's an object-capability RPC
system with promise pipelining, structured-clone-style transfer of
stubs, and bidirectional calls. The wire format used here is text
JSON over a long-lived WebSocket. That is the only carrier: capnweb's
HTTP batch transport cannot deliver a stream returned from a call,
which is what every read on this interface is.

## Where things live

- [`packages/rpc/src/interface.ts`](../../../packages/rpc/src/interface.ts), typed wire surface. `WorkspaceRPC` is the root stub and composes
  `SyncRPC` and `ShellRPC`. Add new methods here first.
- [`packages/rpc/src/server.ts`](../../../packages/rpc/src/server.ts), `Database`-backed implementation. Imported by the Durable Object
  and the in-container computerd.
- [`packages/rpc/src/client.ts`](../../../packages/rpc/src/client.ts), typed stubs over a WebSocket carrier. The Durable Object uses a
  deferred transport so the stub can be created before the upgrade
  completes.
- [`packages/rpc/src/sync-driver.ts`](../../../packages/rpc/src/sync-driver.ts), `pullOnce`, `pushOnce`, `tick`. These wrap streaming methods and
  handle disposal internally.
- [`packages/rpc/src/debug.ts`](../../../packages/rpc/src/debug.ts), `enableStubTracking`, `stubSnapshot` for leak hunting.
- [`docs/08_capnweb_interface.md`](../../../docs/08_capnweb_interface.md), design intent for the wire.
- [`docs/11_lifecycle.md`](../../../docs/11_lifecycle.md#stub-disposal-contract), the repo's stub disposal contract.

## The mental model

The rest: https://github.com/cloudflare/computer/blob/HEAD/.agents/skills/capnweb/SKILL.md
