Skip to main content
skill CX Codex

websocket-realtime — Claude Code skill: what it does, how to install

websocket-realtime provides real-time communication patterns for Claude Code, covering raw WebSocket implementations, Socket.io rooms, SSE, and Redis scaling.

Apache-2.0 ★ 2,858 updated 2026-05-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add rohitg00/awesome-claude-code-toolkit --skill websocket-realtime -a claude-code
Open on GitHub

What websocket-realtime does

This skill gives Claude Code architecture blueprints for bidirectional communication and event streaming. It covers rooms with the ws library, token validation during handshakes, and unidirectional Server-Sent Events.

A client reconnection class with exponential backoff handles broken network links. Multi-server Socket.io setups fail without a message broker, making a Redis adapter mandatory when scaling horizontally.

What it helps with

  • implement chat rooms and broadcasting with raw WebSocket
  • scale Socket.io across multiple instances using Redis
  • stream server events unidirectionally with Server-Sent Events
  • handle automatic client reconnection with backoff delays

Example prompts for the agent

  • Create a WebSocket server in TypeScript with authentication and rooms
  • Set up an SSE endpoint with heartbeat pings and Redis subscription
  • Write a reconnecting WebSocket client class in TypeScript

How to install websocket-realtime

1Skills CLI (Vercel)

npx skills add rohitg00/awesome-claude-code-toolkit --skill websocket-realtime -a claude-code

2Manually: put the files in place

~/.claude/skills/websocket-realtime/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/websocket-realtime/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about websocket-realtime

How to install websocket-realtime in Claude Code?

Run npx skills add rohitg00/awesome-claude-code-toolkit --skill websocket-realtime -a claude-code. You can also place it directly into ~/.claude/skills/websocket-realtime/SKILL.md.

What does websocket-realtime do?

It provides Claude Code with implementation patterns for real-time networking. The skill covers WebSocket servers, Socket.io adapters, and Server-Sent Events.

Why choose Server-Sent Events over WebSocket?

SSE works over standard HTTP proxies without custom network tuning. It is the simpler choice whenever data flows solely from server to browser.

Source text

SKILL.md · Apache-2.0
---
name: websocket-realtime
description: Real-time communication patterns with WebSocket, Socket.io, Server-Sent Events, and scaling strategies
---

# WebSocket & Real-Time

## WebSocket Server

```typescript
import { WebSocketServer, WebSocket } from "ws";

const wss = new WebSocketServer({ port: 8080 });

const rooms = new Map<string, Set<WebSocket>>();

wss.on("connection", (ws, req) => {
  const userId = authenticateFromUrl(req.url);
  if (!userId) {
    ws.close(4001, "Unauthorized");
    return;
  }

  ws.on("message", (data) => {
    const message = JSON.parse(data.toString());

    switch (message.type) {
      case "join":
        joinRoom(message.room, ws);
        break;
      case "leave":
        leaveRoom(message.room, ws);
        break;
      case "broadcast":
        broadcastToRoom(message.room, message.payload, ws);
        break;
    }
  });

  ws.on("close", () => {
    rooms.forEach((members) => members.delete(ws));
  });

  ws.send(JSON.stringify({ type: "connected", userId }));
});

function joinRoom(room: string, ws: WebSocket) {
  if (!rooms.has(room)) rooms.set(room, new Set());
  rooms.get(room)!.add(ws);
}

function broadcastToRoom(room: string, payload: unknown, sender: WebSocket) {
  const members = rooms.get(room);
  if (!members) return;
  const message = JSON.stringify({ type: "message", room, payload });
  members.forEach((client) => {
    if (client !== sender && client.readyState === WebSocket.OPEN) {
      client.send(message);
    }
  });
}
```

## Socket.io with Rooms

```typescript
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/redis-adapter";
import { createClient } from "redis";

const io = new Server(httpServer, {
  cors: { origin: "https://app.example.com" },
  pingTimeout: 20000,
  pingInterval: 25000,
});

const pubClient = createClient({ url: "redis://localhost:6379" });
const subClient = pubClient.duplicate();
await Promise.all([pubClient.connect(), subClient.connect()]);
io.adapter(createAdapter(pubClient, subClient));

io.use(async (socket, next) => {
  const token = socket.handshake.auth.token;
  try {
    socket.data.user = verifyToken(token);
    next();
  } catch {
    next(new Error("Authentication failed"));
  }
});

io.on("connection", (socket) => {
  socket.join(`user:${socket.data.user.id}`);

  socket.on("chat:join", (roomId) => {
    socket.join(`chat:${roomId}`);
    socket.to(`chat:${roomId}`).emit("chat:userJoined", socket.data.user);
  });

  socket.on("chat:message", async ({ roomId, text }) => {
    const message = await saveMessage(roomId, socket.data.user.id, text);
    io.to(`chat:${roomId}`).emit("chat:message", message);
  });

  socket.on("disconnect", () => {
    console.log(`User ${socket.data.user.id} disconnected`);
  });
});
```

## Server-Sent Events (SSE)

```typescript
app.get("/events/:userId", authenticate, (req, res) => {
  res.writeHead(200, {
    "Content-Type": "text/event-stream",
    "Cache-Control": "no-cache",
    Connection: "keep-alive",
  });

  const sendEvent = (event: string, data: unknown) => {
    res.write(`event: ${event}\n`);
    res.write(`data: ${JSON.stringify(data)}\n\n`);
  };

  sendEvent("connected", { userId: req.params.userId });

  const interval = setInterval(() => {
    res.write(":heartbeat\n\n");
  }, 30000);

  const listener = (message: string) => {
    const event = JSON.parse(message);
    sendEvent(event.type, event.data);
  };

  redis.subscribe(`user:${req.params.userId}`, listener);

  req.on("close", () => {
    clearInterval(interval);
    redis.unsubscribe(`user:${req.params.userId}`, listener);
  });
});
```

SSE is simpler than WebSocket for server-to-client unidirectional streaming. Works through HTTP proxies and load balancers without special configuration.

## Client Reconnection

```typescript
class ReconnectingWebSocket {
  private ws: WebSocket | null = null;
  private retryCount = 0;
  private maxRetries = 10;

  constructor(private url: string) {
    this.connect();
  }

  private connect() {
    this.ws = new WebSocket(this.url);
    this.ws.onopen = () => { this.retryCount = 0; };
    this.ws.onclose = () => { this.scheduleReconnect(); };
    this.ws.onerror = () => { this.ws?.close(); };
  }

  private scheduleReconnect() {
    if (this.retryCount >= this.maxRetries) return;
    const delay = Math.min(1000 * 2 ** this.retryCount, 30000);
    this.retryCount++;
    setTimeout(() => this.connect(), delay);
  }

  send(data: string) {
    if (this.ws?.readyState === WebSocket.OPEN) {
      this.ws.send(data);
    }
  }
}
```

## Anti-Patterns

- Not authenticating WebSocket connections during the handshake
- Sending unbounded payloads without message size limits
- Missing heartbeat/ping-pong to detect stale connections
- Using WebSocket when SSE would suffice (server-to-client only)
- Not using a Redis adapter for horizontal scaling with Socket.io
- Blocking the event loop with synchronous processing of messages

## Checklist

- [ ] WebSocket connections authenticated during handshake
- [ ] Message size limits enforced on incoming data
- [ ] Heartbeat mechanism detects and closes stale connections
- [ ] Client implements exponential backoff reconnection
- [ ] Redis pub/sub adapter used for multi-server deployment
- [ ] SSE used when communication is server-to-client only
- [ ] Room/channel membership cleaned up on disconnect
- [ ] Rate limiting applied to prevent message flooding

© rohitg00 · Apache-2.0 · rohitg00/awesome-claude-code-toolkit

Similar skills

All skills for Backend and APIs →

From the same set178

The whole set →
testing-infrastructure testing-infrastructure — a subagent that designs test infrastructure: splits tests across parallel runners, detects and quarantines flaky tests, optimizes execution time. For teams where CI is a bottleneck or tests fail unpredictably. CX Codex ★ 2,858repo stars healthcare-engineer healthcare-engineer designs HIPAA-compliant architectures and HL7 FHIR interfaces. Useful when connecting EHR platforms, mapping clinical vocabularies, or de-identifying records. CX Codex ★ 2,858repo stars continuous-learning The continuous-learning skill turns session corrections and successful approaches into reusable project knowledge. It helps when you want the agent to account for earlier feedback. CX Codex +1 ★ 2,858repo stars developer-portal Subagent for building internal developer portals using Backstage with service catalogs, project templates, and self-service infrastructure provisioning. Replaces scattered wikis and manual setup with unified discovery and CI/CD integration. CX Codex ★ 2,858repo stars monitoring-observability monitoring-observability is a Claude Code skill that adds tracing, metrics, structured logs, and alert rules to Node.js services. It connects application signals to dashboards and SLOs. CX Codex +1 ★ 2,858repo stars database-optimizer database-optimizer — a subagent that diagnoses slow queries, designs indexes, implements partitioning schemes, and plans capacity for PostgreSQL, MySQL, and distributed databases. CX Codex ★ 2,858repo stars accessibility-wcag The accessibility-wcag skill for Claude Code provides WCAG 2.2 patterns for semantic HTML, ARIA dialogs, keyboard navigation, and color contrast. CX Codex +1 ★ 2,858repo stars content-strategist The content-strategist subagent plans SEO content, groups topics into clusters, and connects publishing work to performance metrics. It targets technical products and developer audiences. CX Codex ★ 2,858repo stars

Project sponsors

Companies that keep this analytics open