agent-instructions
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what…
Use when building realtime features with WebSockets or Server-Sent Events. Covers protocol choice, connection lifecycle, reconnection and backfill, scaling across instances, and backpressure. Trigger on "add live updates", "websocket keeps disconnecting", "websockets or sse",
Claude Code
$ npx -y skills add nimadorostkar/Claude-Skills-collection --skill realtime-websockets --agent claude-code
Codex
$ npx skills add nimadorostkar/Claude-Skills-collection --skill realtime-websockets -a codex -y
Cursor
$ npx skills add nimadorostkar/Claude-Skills-collection --skill realtime-websockets -a cursor -y
Gemini CLI
$ npx skills add nimadorostkar/Claude-Skills-collection --skill realtime-websockets -a gemini-cli -y
GitHub Copilot
$ npx skills add nimadorostkar/Claude-Skills-collection --skill realtime-websockets -a github-copilot -y
OpenCode
$ npx skills add nimadorostkar/Claude-Skills-collection --skill realtime-websockets -a opencode -y
Windsurf
$ npx skills add nimadorostkar/Claude-Skills-collection --skill realtime-websockets -a windsurf -y
name: realtime-websockets description: Use when building realtime features with WebSockets or Server-Sent Events. Covers protocol choice, connection lifecycle, reconnection and backfill, scaling across instances, and backpressure. Trigger on "add live updates", "websocket keeps disconnecting", "websockets or sse", "scale socket.io across servers". Do not use for message queues between backend services — see the event-driven-architecture skill. metadata: category: backend version: 1.0.0 tags: [websockets, sse, realtime, scaling, backpressure]
Build realtime features that behave correctly when the connection drops — which it will, constantly, on mobile networks. The hard part is not the socket; it is the state after the reconnect.
1. **Choose the simplest protocol that works** — Server-to-client only? Use SSE: it is plain HTTP, reconnects automatically, and passes through proxies. Bidirectional and low-latency? WebSockets. Infrequent updates? Polling is not embarrassing. 2. **Authenticate at the handshake** — Validate the token on connect; re-validate periodically for long-lived sockets. A socket opened an hour ago may belong to a revoked session. 3. **Heartbeat both ways** — Ping/pong with a timeout. Without it, half-open connections accumulate and leak memory for hours. 4. **Design the resume** — Every message carries a monotonic sequence number. On reconnect, the client sends its last-seen ID; the server replays the gap or tells it to resynchronize fully. 5. **Fan out via pub/sub** — With more than one instance, a message published on instance A must reach a client connected to instance B. Redis pub/sub, NATS, or the broker you already have. 6. **Apply backpressure** — Bound the per-connection send buffer. When it fills, drop the slow consumer rather than the server.
**Resumable stream with sequence numbers:**
// Client
const ws = new WebSocket(`${URL}?resume_from=${lastSeq ?? ""}`);
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg.seq !== lastSeq + 1 && lastSeq !== null) {
// Gap detected: the server could not replay. Resynchronize from scratch.
return resyncFromSnapshot();
}
lastSeq = msg.seq;
apply(msg);
};
ws.onclose = () => scheduleReconnect(backoff.next()); // exponential + jitter// Server: replay bounded, or instruct a full resync
const from = Number(url.searchParams.get("resume_from"));
const gap = currentSeq - from;
if (Number.isFinite(from) && gap > 0 && gap <= MAX_REPLAY) {
for (const msg of await log.range(from + 1, currentSeq)) send(socket, msg);
} else {
send(socket, { type: "resync_required", seq: currentSeq });
}A curated library of 137 production-grade skills for Claude and other AI coding agents. Every skill follows one structure, speaks with one voice, and earns its place by changing what the agent does.
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what…
Use when an agent needs state that survives a session or a context compaction. Covers what to persist, file-based memory,…
Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should…
Use when packaging skills, commands, hooks, and MCP servers into a distributable plugin. Covers manifest structure, bundling,…
Use when writing a new skill for an AI agent. Covers scoping, description writing for reliable triggering, progressive…
Use when reviewing or improving an existing agent skill. Covers triggering accuracy, content quality, redundancy with the base…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.