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

claude-code-parser

v0.1.1

Published

Parse Claude Code's --output-format stream-json into fully typed TypeScript events

Downloads

126

Readme

claude-code-parser

npm version bundle size

Parse Claude Code's --output-format stream-json NDJSON output into fully typed TypeScript events. Zero dependencies. 9 kB.

Documentation | Protocol Reference

Includes the first standalone documentation of Claude Code's undocumented stream-json protocol.

Install

npm install claude-code-parser

Quick Start

import { spawn } from 'child_process'
import { createInterface } from 'readline'
import { parseLine, Translator, createMessage } from 'claude-code-parser'

const claude = spawn('claude', [
  '-p', '--input-format', 'stream-json',
  '--output-format', 'stream-json', '--verbose',
], { stdio: ['pipe', 'pipe', 'inherit'] })

const translator = new Translator()

const rl = createInterface({ input: claude.stdout! })
rl.on('line', (line) => {
  const event = parseLine(line)
  if (!event) return

  for (const relay of translator.translate(event)) {
    switch (relay.type) {
      case 'text_delta':    process.stdout.write(relay.content); break
      case 'tool_use':      console.log(`\n[tool] ${relay.toolName}`); break
      case 'turn_complete': console.log(`\n[done] $${relay.costUsd?.toFixed(4)}`); break
    }
  }
})

claude.stdin!.write(createMessage.user('What is 2 + 2?'))

API

| Export | Description | |---|---| | parseLine(line) | NDJSON line → ClaudeEvent \| null | | Translator | Stateful dedup translator → RelayEvent[] | | createMessage.user(text) | Construct stdin user message | | createMessage.approve(id) | Approve pending tool execution | | createMessage.deny(id) | Deny pending tool execution | | createMessage.toolResult(id, content) | Send tool result | | extractContent(raw) | Normalize polymorphic tool_result content |

RelayEvent Types

text_delta | thinking_delta | tool_use | tool_result | session_meta | turn_complete | error

Full API docs

Why This Exists

The official SDK (@anthropic-ai/claude-code) couples parsing with subprocess management. This library only parses — for developers building custom relays, dashboards, CI tools, or browser viewers who need raw event access.

Key problems it solves:

  • --verbose deduplication — cumulative snapshots require stateful content tracking
  • Multi-agent interleaving — sub-agents produce interleaved events on the same stdout
  • Polymorphic contenttool_result.content can be string, array, or null
  • Double-encoded results — the result field is JSON inside JSON

Documentation

License

MIT

This is an unofficial community package. Not affiliated with or endorsed by Anthropic.