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

@tormentalabs/claude-code-wire-compat

v0.5.0

Published

Runtime-neutral Claude Code Messages wire compatibility primitives

Readme

claude-code-wire-compat

Claude Wire Compat

An ESM-only, runtime-neutral TypeScript package for constructing a pinned Claude Code Messages wire contract.

Status: stable. buildClaudeCodeRequest and parseBuiltClaudeCodeRequest build and read back the pinned wire contract. The package performs no I/O: credentials, transport, persistence, refresh coordination, and retries remain the consumer's responsibility.

Package

npm install @tormentalabs/claude-code-wire-compat

The package targets Node.js 20 or newer and is designed to remain portable to Bun and standards-based worker runtimes. Consumers own credentials, transport, persistence, refresh coordination, retries, and deployment policy.

Protocol profile

Two pinned profiles are exported:

  • CLAUDE_CODE_2_1_233_PROFILE — Claude Code 2.1.233 with SDK 0.112.1. This is the profile used when profile is omitted.
  • CLAUDE_CODE_2_1_195_PROFILE — the previous pin, Claude Code 2.1.195 with SDK 0.94.0.

Either can be selected explicitly by passing the singleton as the profile argument, from the package root or from its own subpath export:

import { CLAUDE_CODE_2_1_195_PROFILE } from "@tormentalabs/claude-code-wire-compat/profiles/claude-code-2.1.195";
import { CLAUDE_CODE_2_1_233_PROFILE } from "@tormentalabs/claude-code-wire-compat/profiles/claude-code-2.1.233";

The fail-closed rule is unchanged: only these exported singletons are accepted. Any other object, even a structurally identical clone, is rejected with ClaudeCodeWireError code INVALID_INPUT. This prevents callers from substituting an unpinned protocol profile.

Endpoint URL and custom base URLs

built.url is the pinned endpoint of the profile, not a suggestion. It is literal-typed, so the type is part of the contract:

  • buildClaudeCodeRequest"https://api.anthropic.com/v1/messages?beta=true"
  • buildClaudeCodeCountTokensRequest"https://api.anthropic.com/v1/messages/count_tokens?beta=true"

A host that talks to a proxy, a gateway, or a regional endpoint overrides the origin and nothing else: replace protocol, hostname and port; keep the package's pathname and search verbatim. The ?beta=true query and the /v1/messages path are wire contract — dropping either changes what the server does, and the golden fixtures no longer describe the request that was sent.

const built = await buildClaudeCodeRequest(input);

// Origin override. `pathname` and `search` come from the package, untouched.
const target = new URL(built.url);
const base = new URL(hostBaseUrl); // whatever the host resolved, e.g. from its own config
target.protocol = base.protocol;
target.hostname = base.hostname;
target.port = base.port;

await fetch(target, {
  method: built.method,
  headers: built.headers,
  body: built.body,
});

The input will not gain a baseUrl field. Three reasons, recorded so the request does not come back:

  1. BuiltClaudeCodeRequest["url"] is a string literal type. Widening it to string to accommodate an arbitrary base is a breaking change at the type level for every consumer that pins the endpoint.
  2. Speculative surface is not added to this package. A host that has a base URL already has a URL library; a package field would be a second way to do the same thing, with a validation and normalisation burden this package would then own.
  3. The only real consumer case observed is an origin override, which the four lines above express exactly — including the case where the base URL carries a path prefix, which a naive baseUrl + pathname concatenation gets wrong.

Protocol documentation

The wire contract this package pins was reverse engineered before it was implemented. That research is preserved under docs/protocol/ so a future maintainer can re-derive the contract when Claude Code ships a new version. It is ported verbatim from opencode-anthropic-fix at commit 466d500 under GPL-3.0-or-later; every file carries a provenance header and is listed in docs/ATTRIBUTION.md.

These documents describe the upstream plugin and Claude Code itself, not this package's API. The normative mapping from those findings to this package's contract is docs/source-trace.md.

Protocol knowledge corpus:

Per-version wire analyses — why they exist and when a new one is required:

Development

npm ci
npm run lint
npm run typecheck
npm test
npm run build

Security

Do not include access tokens, account identifiers, session identifiers, or private prompts in bug reports. See SECURITY.md for private disclosure instructions.

License and provenance

SPDX-License-Identifier: GPL-3.0-or-later

This repository is a modified work derived from opencode-anthropic-fix at upstream commit 466d500. See NOTICE for attribution and modification details. Corresponding source is available in this public repository.