Kkrpc
A TypeScript RPC protocol for multiple environments (iframe, web worker, stdio, http, WebSocket)
Install / Use
/learn @kunkunsh/KkrpcREADME
🚀 kkrpc
TypeScript-First RPC Library
</div>This project was created for building extension system for a Tauri app (kunkun).
It can potentially be used in other types of apps, so I open sourced it as a standalone package.
Seamless bi-directional communication between processes, workers, and contexts
Call remote functions as if they were local, with full TypeScript type safety and autocompletion support.
Similar to Comlink but with bidirectional communication and support for multiple environments - both client and server can expose functions for the other to call across Node.js, Deno, Bun, and browser environments.
Quick Start • Documentation • Examples • API Reference • LLM Docs • 中文文档
🎥 Video Tutorial
Watch this video for a comprehensive introduction to kkrpc and how to use it in your projects.
🤖 AI Support
Working with kkrpc in your AI-powered editor? Add these skills to your Claude Code configuration to get intelligent assistance:
# Copy kkrpc skills to your global Claude Code skills folder
cp -r skills/kkrpc ~/.claude/skills/
cp -r skills/interop ~/.claude/skills/
This provides your AI assistant with:
- kkrpc skill: How to use kkrpc in TypeScript projects
- interop skill: How to implement kkrpc clients/servers in other languages (Go, Python, Rust, Swift)
See skills/ directory for details.
🌟 Why kkrpc?
kkrpc stands out in the crowded RPC landscape by offering true cross-runtime compatibility without sacrificing type safety or developer experience. Unlike tRPC (HTTP-only) or Comlink (browser-only), kkrpc enables seamless communication across Node.js, Deno, Bun, and browser environments.
✨ Features
<div align="center">| Feature | Description |
| --------------------------- | -------------------------------------------------------------- |
| 🔄 Cross-runtime | Works seamlessly across Node.js, Deno, Bun, browsers, and more |
| 🛡️ Type-safe | Full TypeScript inference and IDE autocompletion support |
| ↔️ Bidirectional | Both endpoints can expose and call APIs simultaneously |
| 🏠 Property Access | Remote getters/setters with dot notation (await api.prop) |
| 💥 Error Preservation | Complete error objects across RPC boundaries |
| 🌐 Multiple Transports | stdio, HTTP, WebSocket, postMessage, Chrome extensions |
| 📞 Callback Support | Remote functions can accept callback functions |
| 🔗 Nested Calls | Deep method chaining like api.math.operations.calculate() |
| 📦 Auto Serialization | Intelligent JSON/superjson detection |
| ⚡ Zero Config | No schema files or code generation required |
| 🔒 Data Validation | Optional runtime validation with Zod, Valibot, ArkType, etc. |
| 🔌 Middleware | Interceptor chain for logging, auth, timing, and more |
| ⏱️ Request Timeout | Auto-reject pending calls after a configurable deadline |
| 🔁 Streaming | Return AsyncIterable from methods, consume with for await |
| 🚀 Transferable Objects | Zero-copy transfers for large data (40-100x faster) |
🌍 Supported Environments
<div align="center">graph LR
A[kkrpc] --> B[Node.js]
A --> C[Deno]
A --> D[Bun]
A --> E[Browser]
A --> F[Chrome Extension]
A --> G[Tauri]
B -.-> H[stdio]
C -.-> H
D -.-> H
E -.-> I[postMessage]
E -.-> J[Web Workers]
E -.-> K[iframes]
F -.-> L[Chrome Ports]
G -.-> M[Shell Plugin]
style A fill:#ff6b6b,stroke:#333,stroke-width:2px
</div>
📡 Transport Protocols
| Transport | Use Case | Supported Runtimes | | -------------------- | ----------------------------------------------------- | -------------------------------------- | | stdio | Process-to-process communication | Node.js ↔ Deno ↔ Bun | | postMessage | Browser context communication | Browser ↔ Web Workers ↔ iframes | | HTTP | Web API communication | All runtimes | | WebSocket | Real-time communication | All runtimes | | Hono WebSocket | High-performance WebSocket with Hono framework | Node.js, Deno, Bun, Cloudflare Workers | | Socket.IO | Enhanced real-time with rooms/namespaces | All runtimes | | Elysia WebSocket | Modern TypeScript framework WebSocket integration | Bun, Node.js, Deno | | Chrome Extension | Extension component communication | Chrome Extension contexts | | RabbitMQ | Message queue communication | Node.js, Deno, Bun | | Redis Streams | Stream-based messaging with persistence | Node.js, Deno, Bun | | Kafka | Distributed streaming platform | Node.js, Deno, Bun | | NATS | High-performance messaging system | Node.js, Deno, Bun | | Electron | Desktop app IPC (Renderer ↔ Main ↔ Utility Process) | Electron |
The core of kkrpc design is in RPCChannel and IoInterface.
RPCChannelis the bidirectional RPC channelLocalAPIis the APIs to be exposed to the other side of the channelRemoteAPIis the APIs exposed by the other side of the channel, and callable on the local siderpc.getAPI()returns an object that isRemoteAPItyped, and is callable on the local side like a normal local function call.IoInterfaceis the interface for implementing the IO for different environments. The implementations are called adapters.- For example, for a Node process to communicate with a Deno process, we need
NodeIoandDenoIoadapters which implementsIoInterface. They share the same stdio pipe (stdin/stdout). - In web, we have
WorkerChildIOandWorkerParentIOadapters for web worker,
- For example, for a Node process to communicate with a Deno process, we need
Related Skills
canvas
345.9kCanvas Skill Display HTML content on connected OpenClaw nodes (Mac app, iOS, Android). Overview The canvas tool lets you present web content on any connected node's canvas view. Great for: -
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).

