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-sdk

v0.1.0

Published

TypeScript wrapper for Claude Code SDK

Readme

Claude Code SDK

A TypeScript wrapper for Claude Code CLI that provides a seamless, type-safe API compatible with both OpenAI and Anthropic SDKs.

Installation

First, install the Claude Code CLI:

npm install -g @anthropic-ai/claude-code

Then install the wrapper:

npm install claude-code-sdk

Setup

You'll need an Anthropic API key to use Claude Code. You can either set it as an environment variable:

export ANTHROPIC_API_KEY=your_api_key_here

Or provide it when initializing the client:

import { ClaudeCode } from 'claude-code-sdk'

const claude = new ClaudeCode({
  apiKey: 'your_api_key_here'
})

Usage

This SDK provides both OpenAI-style and Anthropic-style APIs for interacting with Claude Code.

OpenAI Style API

import { ClaudeCode } from 'claude-code-sdk'

// Create a client
const claude = new ClaudeCode()

// Use OpenAI-style completions API
async function generateCode() {
  const response = await claude.chat.completions.create({
    model: 'claude-code',
    messages: [
      { role: 'user', content: 'Write a TypeScript function to read CSV files' }
    ],
    max_tokens: 1000,
    temperature: 0.7,
  })

  console.log(response.choices[0].message.content)
}

// Streaming example
async function streamCode() {
  const stream = await claude.chat.completions.createStream({
    model: 'claude-code',
    messages: [
      { role: 'user', content: 'Create a React component for a login form' }
    ]
  })

  for await (const chunk of stream) {
    if (chunk.choices[0].delta.content) {
      process.stdout.write(chunk.choices[0].delta.content)
    }
  }
}

Anthropic Style API

import { ClaudeCode } from 'claude-code-sdk'

// Create a client
const claude = new ClaudeCode()

// Use Anthropic-style messages API
async function generateCode() {
  const response = await claude.messages.create({
    model: 'claude-code',
    messages: [
      { 
        role: 'user', 
        content: [{ 
          type: 'text', 
          text: 'Write a TypeScript function to read CSV files' 
        }] 
      }
    ],
    max_tokens: 1000,
  })

  console.log(response.content[0].text)
}

// Streaming example
async function streamCode() {
  const stream = await claude.messages.createStream({
    model: 'claude-code',
    messages: [
      { 
        role: 'user', 
        content: [{ 
          type: 'text', 
          text: 'Create a React component for a login form' 
        }] 
      }
    ]
  })

  for await (const chunk of stream) {
    if (chunk.type === 'content_block_delta' && chunk.delta?.text) {
      process.stdout.write(chunk.delta.text)
    }
  }
}

Session Management

import { ClaudeCode } from 'claude-code-sdk'

const claude = new ClaudeCode()

async function codeSession() {
  // Start a session
  const session = await claude.sessions.create({
    messages: [
      { role: 'user', content: 'Let\'s create a TypeScript project' }
    ]
  })

  // Continue the session
  const response = await session.continue({
    messages: [
      { role: 'user', content: 'Now add a database connection' }
    ]
  })

  console.log(response.choices[0].message.content)
}

Tools

import { ClaudeCode } from 'claude-code-sdk'

const claude = new ClaudeCode()

async function useTools() {
  // Register a tool
  await claude.tools.create({
    name: 'filesystem',
    description: 'Access the filesystem',
    input_schema: {
      type: 'object',
      properties: {
        path: { type: 'string' }
      },
      required: ['path']
    }
  })

  // Use the tool in a chat completion
  const response = await claude.chat.completions.create({
    model: 'claude-code',
    messages: [
      { role: 'user', content: 'Read my README.md file' }
    ],
    tools: [{ name: 'filesystem' }]
  })

  console.log(response.choices[0].message.content)
}

Debugging

To test if the Claude Code CLI is installed and configured correctly, run:

npx claude -h

If you experience issues, set more verbose output:

const claude = new ClaudeCode({
  apiKey: process.env.ANTHROPIC_API_KEY,
  cliPath: '/path/to/claude', // If claude isn't in your PATH
  timeout: 60000 // Longer timeout (ms)
})

Features

  • OpenAI-compatible chat.completions.create method
  • Anthropic-compatible messages.create method
  • Session management for multi-turn conversations
  • Tool registration and usage
  • Full TypeScript support
  • Streaming responses
  • Batch operations

Requirements

  • Node.js v16+
  • TypeScript 4.5+
  • @anthropic-ai/claude-code CLI installed

License

MIT