Skip to main content
skill CX Codex

websocket-development — Claude Code skill: WebSocket real-time rules

A rule set that steers the agent through building WebSocket servers and clients: connections, messages, scaling, security.

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

What websocket-development does

The skill gives the agent a frame for real-time work. It covers connection management, message handling, scaling patterns, security, testing and observability. The instructions are concrete: use wss:// with SSL/TLS in production, validate the handshake before accepting a connection, set timeouts so sockets do not eat resources.

Connection lifecycle gets its own section — heartbeat and ping-pong to catch stale sockets, reconnection with exponential backoff, state tracking, resource cleanup on close. Messages should be structured: JSON with a type and payload, IDs to correlate request and response, versioning for backward compatibility, small payloads to keep latency down. For horizontal scaling the skill names Redis Pub/Sub and RabbitMQ, plus MessagePack and Protocol Buffers when bandwidth matters.

Separate notes cover Node.js 21+ with its built-in WebSocket client, Bun with Bun.serve(), and browser clients with graceful degradation and offline queuing. Authentication belongs in the handshake, JWT tokens get validated on connect and at intervals, rate limits apply per connection and per user. The skill also insists the implementation ship complete, with no todos or placeholders. If your project already has a message layer, some advice will fight it — adding versioning on top of a settled schema just creates parsing branches to maintain.

What it helps with

  • stand up a WebSocket server with handshake checks and timeouts
  • add reconnection with exponential backoff
  • fan out across servers with Redis Pub/Sub
  • gate connections with JWT and rate limits
  • test the connection lifecycle and failure modes

Example prompts for the agent

  • Design a Node.js WebSocket server with handshake, heartbeat and backoff reconnection
  • Set up Redis pub/sub across instances and clean up subscriptions on disconnect
  • Review my message handler for request IDs, versioning and error paths

How to install websocket-development

1Skills CLI (Vercel)

npx skills add Mindrally/skills --skill websocket-development -a claude-code

2Manually: put the files in place

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

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

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

Questions about websocket-development

How do I install websocket-development in Claude?

Run npx skills add Mindrally/skills --skill websocket-development -a claude-code. The skill lands at ~/.claude/skills/websocket-development/SKILL.md.

What does websocket-development do?

It gives the agent guidelines for real-time WebSocket work: connection handling, message format, scaling, security, testing and metrics.

Which platforms can use this skill?

Install instructions exist for Claude, Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode. Inside there are separate notes for Node.js 21+, Bun and browser clients.

Source text

SKILL.md · Apache-2.0
---
name: websocket-development
description: Best practices and guidelines for building real-time applications with WebSocket communication
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# WebSocket Development

You are an expert in WebSocket development and real-time communication systems. Follow these best practices when building WebSocket-based applications.

## Core Principles

- Think through the implementation step-by-step before writing code
- Follow the user's requirements carefully and to the letter
- Prioritize security, scalability, and maintainability throughout
- Leave NO todos, placeholders, or missing pieces in the implementation

## Connection Management

### Establishing Connections

- Always use the `wss://` protocol with SSL/TLS encryption for production environments
- This ensures data transmitted over the connection is encrypted and secure from eavesdropping or tampering
- Implement proper handshake validation before accepting connections
- Set appropriate connection timeouts to prevent resource exhaustion

### Connection Lifecycle

- Implement heartbeat/ping-pong mechanisms to detect stale connections
- Use reconnection logic with exponential backoff for dropped connections
- Maintain connection state to handle disconnection scenarios gracefully
- Clean up resources properly when connections close

## Message Handling

### Message Design

- Use structured message formats (JSON with type/payload pattern)
- Include message IDs for request-response correlation
- Implement message versioning for backward compatibility
- Keep message payloads small to reduce latency

### Error Handling

- Always include error handling logic for WebSocket connections
- Manage potential disconnections or message failures gracefully
- Implement dead letter handling for unprocessable messages
- Log errors with sufficient context for debugging

## Scalability Patterns

### Horizontal Scaling

- Use a message broker (Redis Pub/Sub, RabbitMQ) for cross-server communication
- Implement sticky sessions or connection affinity when needed
- Design stateless handlers where possible
- Consider using a dedicated WebSocket gateway service

### Performance Optimization

- Buffer messages during brief disconnections
- Implement message batching for high-frequency updates
- Use binary protocols (MessagePack, Protocol Buffers) for bandwidth-sensitive applications
- Monitor connection counts and message throughput

## Security Best Practices

### Authentication

- Authenticate connections during the handshake phase
- Use token-based authentication (JWT) with proper expiration
- Validate tokens on both connection and periodic intervals
- Implement rate limiting per connection and per user

### Authorization

- Validate permissions for each message type/channel
- Implement channel-based access control for pub/sub patterns
- Never trust client-provided data without validation
- Sanitize all incoming message payloads

## Framework-Specific Guidelines

### Node.js Native WebSocket (v21+)

- Utilize Node.js's built-in WebSocket client for real-time communication to reduce dependencies
- The built-in client simplifies real-time communication and ensures better interoperability
- For servers, use established libraries like `ws` or framework-specific solutions

### Bun Runtime

- Prefer Bun's native capabilities over third-party alternatives
- Use `Bun.serve()` with WebSocket support instead of separate WebSocket libraries
- Leverage Bun's built-in stream handling and fetch implementation

### Browser Clients

- Implement graceful degradation for older browsers
- Use the standard WebSocket API for broad compatibility
- Handle visibility changes to manage connection state
- Implement offline detection and queuing

## Testing Strategies

### Unit Testing

- Mock WebSocket connections for isolated testing
- Test message serialization/deserialization independently
- Verify error handling paths

### Integration Testing

- Test full connection lifecycle scenarios
- Verify reconnection behavior under various failure modes
- Load test with realistic connection counts and message rates

## Monitoring and Observability

- Track connection count metrics
- Monitor message latency and throughput
- Alert on connection error rates
- Log connection lifecycle events for debugging

## Common Patterns

### Pub/Sub Pattern

- Implement channel subscription management
- Use efficient data structures for subscriber lookup
- Handle subscription cleanup on disconnect

### Request/Response Pattern

- Correlate requests and responses with unique IDs
- Implement timeout handling for pending requests
- Consider using acknowledgment messages for reliability

### Broadcast Pattern

- Optimize for one-to-many message delivery
- Consider message deduplication strategies
- Implement backpressure for slow consumers

© Mindrally · Apache-2.0 · Mindrally/skills

Similar skills

Everything for Backend and APIs →

From the same set168

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor