npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bridge-ws

v2.0.2

Published

WebSocket bridge for CLI AI agents — stream Claude, Codex, and Ollama responses over WebSocket

Readme

bridge-ws

WebSocket bridge for CLI AI agents — stream Claude, Codex, and Ollama responses over a persistent connection.

Install

npm install -g bridge-ws

Or run without installing:

npx bridge-ws

Quick start

1. Start the server:

bridge-ws
╔═══════════════════════════════════════╗
║          bridge-ws v2.0.2            ║
║     CLI AI Agent Bridge              ║
╚═══════════════════════════════════════╝

Found Claude CLI: 1.x.x
bridge-ws running on ws://localhost:9999
Health check: http://localhost:9999/healthz
Press Ctrl+C to stop

2. Connect and send a prompt:

import WebSocket from "ws";

const ws = new WebSocket("ws://localhost:9999");

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

  if (msg.type === "connected") {
    ws.send(JSON.stringify({
      type: "prompt",
      prompt: "Say hello in one sentence.",
      requestId: "req-1",
    }));
  }

  if (msg.type === "chunk") process.stdout.write(msg.content);
  if (msg.type === "complete") ws.close();
  if (msg.type === "error") { console.error(msg.message); ws.close(); }
});

Requirements

  • Node.js ≥ 20
  • Claude Code CLI (npm install -g @anthropic-ai/claude-code)
  • Codex CLI (optional, for provider: "codex")
  • Ollama (optional, for provider: "ollama" — no API key needed)

Features

  • Request multiplexing — send multiple prompts on a single connection; responses are tagged by requestId
  • Streaming — response chunks arrive as they are produced, not after completion
  • Cancellation — cancel any in-flight request by requestId
  • Three providers — Claude (claude), Codex (codex), and Ollama (ollama) on the same server
  • Optional auth — Bearer token authentication via BRIDGE_WS_API_KEY
  • Health checkGET /healthz on the same port
  • Library-ready — import AgentWebSocketServer directly and inject custom runners

CLI options

| Flag | Default | Description | |------|---------|-------------| | -p, --port <port> | 9999 | Listen port | | -H, --host <host> | localhost | Bind address | | -c, --claude-path <path> | claude | Path to Claude CLI | | --codex-path <path> | codex | Path to Codex CLI | | --ollama-url <url> | http://localhost:11434 | Ollama base URL | | -t, --timeout <seconds> | 300 | Per-request CLI timeout | | --log-level <level> | info | debug, info, warn, error | | --origins <origins> | (any) | Comma-separated allowed origins | | --max-turns <n> | (unlimited) | Max Claude agentic turns | | --tools <tools> | (all) | Comma-separated Claude tools to enable |

Environment variables:

| Variable | Description | |----------|-------------| | BRIDGE_WS_API_KEY | Required Bearer token for connecting clients |

Protocol

Client → Server

// Send a prompt (provider: "claude" | "codex" | "ollama", defaults to "claude")
{ "type": "prompt", "prompt": "...", "requestId": "req-1", "provider": "claude" }

// Cancel a request
{ "type": "cancel", "requestId": "req-1" }

Server → Client

// On connect
{ "type": "connected", "version": "2.0", "agent": "bridge-ws" }

// Response fragments
{ "type": "chunk", "content": "...", "requestId": "req-1" }

// On completion
{ "type": "complete", "requestId": "req-1" }

// On error or cancellation
{ "type": "error", "message": "...", "requestId": "req-1" }

Full protocol details: docs/reference.md

Concurrent requests

// Both requests run concurrently on the same connection
ws.send(JSON.stringify({ type: "prompt", prompt: "First task", requestId: "a" }));
ws.send(JSON.stringify({ type: "prompt", prompt: "Second task", requestId: "b" }));

ws.on("message", (data) => {
  const msg = JSON.parse(data.toString());
  if (msg.type === "chunk") {
    console.log(`[${msg.requestId}] ${msg.content}`);
  }
});

Authentication

BRIDGE_WS_API_KEY=my-secret bridge-ws
const ws = new WebSocket("ws://localhost:9999", {
  headers: { Authorization: "Bearer my-secret" },
});

Library usage

import { AgentWebSocketServer } from "bridge-ws";
import pino from "pino";

const server = new AgentWebSocketServer({
  port: 9999,
  host: "127.0.0.1",
  logger: pino(),
  apiKey: process.env.BRIDGE_WS_API_KEY,
  maxTurns: 5,
});

await server.start();

Documentation

  • Tutorial — step-by-step first run
  • How-to guides — auth, tools, cancellation, reverse proxy, library usage
  • Reference — all CLI flags, message types, HTTP endpoints
  • Explanation — design decisions and architecture

License

MIT