Skip to content
secondsky avatar

Bun Websocket Server

Bun-native WebSocket server built on Bun.serve, with pub/sub topics, typed connection data, and tuning options.

CCM score
58 of 100
skills.sh installs
414
GitHub stars
257
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers the connection lifecycle: upgrade during fetch, open, message, drain, ping, pong, and close handlers
  • Includes send patterns for text, JSON, binary, and compressed frames, plus attaching typed data to each connection
  • Provides topic broadcasting via subscribe, publish, and server-level publish, with options like maxPayloadLength, idleTimeout, and perMessageDeflate
  • Designed for real-time chat, live updates, and authenticated socket servers, with reference files for compression and horizontal scaling

Install

$ npx -y skills add secondsky/claude-skills --skill bun-websocket-server -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Bun WebSocket Server

Bun has built-in WebSocket support integrated with Bun.serve().

Quick Start

const server = Bun.serve({
  fetch(req, server) {
    // Upgrade to WebSocket
    if (server.upgrade(req)) {
      return; // Upgraded successfully
    }
    return new Response("Not a WebSocket request", { status: 400 });
  },
  websocket: {
    open(ws) {
      console.log("Client connected");
    },
    message(ws, message) {
      console.log("Received:", message);
      ws.send(`Echo: ${message}`);
    },
    close(ws) {
      console.log("Client disconnected");
    },
  },
});

console.log(`WebSocket server running on ws://localhost:${server.port}`);

WebSocket Handlers

Bun.serve({
  fetch(req, server) {
    server.upgrade(req);
  },
  websocket: {
    // Client connected
    open(ws) {
      console.log("New connection");
    },

    // Message received
    message(ws, message) {
      // message is string | Buffer
      if (typeof message === "string") {
        console.log("Text:", message);
      } else {
        console.log("Binary:", message);
      }
    },

Details

Repository
github.com/secondsky/claude-skills
Categories
Backend & APIs, Frontend & UI Code
First seen
Jun 3, 2026

Questions

What does the bun-websocket-server skill do?

It teaches an agent how to build WebSocket servers with Bun using the built-in support in Bun.serve(). It covers connection handlers, sending text and binary messages, attaching data to connections, and pub/sub topics for broadcasting.

How do I install the bun-websocket-server skill?

Run npx -y skills add secondsky/claude-skills --skill bun-websocket-server -y inside your project. Once installed, the agent can write Bun WebSocket code that upgrades requests, handles open, message and close events, and publishes to rooms.

Which skills does bun-websocket-server sit alongside in Backend & APIs?

It is listed in the Backend & APIs category, where entra-app-registration, neon, firebase-basics, firebase-auth-basics and workers-best-practices are also found. This skill focuses specifically on real-time WebSocket communication built on Bun.serve().

Does bun-websocket-server cover authentication and scaling?

Yes, the skill shows how to verify a token before upgrading a connection and how to attach user data to a socket. Its reference notes also cover Redis pub/sub integration and horizontal scaling across multiple server instances.

More from secondsky/claude-skills

All 116

Similar to Bun Websocket Server

More Backend & APIs