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

@posthog/code-agent

v0.2.0

Published

Unified TypeScript SDK for coding agents (Claude Code + Codex) with MCP Bridge

Readme

Code Agent SDK

A unified TypeScript SDK for orchestrating coding agent tasks using Claude Code (Anthropic) or OpenAI models with MCP (Model Context Protocol) bridge support.

Features

  • Unified Interface: Single API for both Anthropic and OpenAI coding agents
  • MCP Bridge: Register and use MCP tools across different agent implementations
  • Streaming Events: Real-time event stream for tokens, tool calls, diffs, and metrics
  • Auth Discovery: Ambient authentication from environment variables
  • Diff Normalization: Standardized code change representation across vendors
  • Task Management: Async task lifecycle with cancellation support
  • Unified Permissions: Common permission modes that work across providers
  • Tool Execution: Built-in tool execution with configurable permissions

Installation

npm install @code-agent/sdk

Quick Start

import { createAgent, ClaudeCodeAgent, CodexAgent } from '@code-agent/sdk';

// Using Claude Code
const claudeAgent = createAgent(new ClaudeCodeAgent({ 
  model: 'claude-3-5-sonnet-20241022' 
}));

// Using OpenAI Codex
const openAIAgent = createAgent(new CodexAgent({ 
  profile: 'balanced' 
}));

// Run a task
const { taskId, stream } = await claudeAgent.run({
  prompt: 'Add a health check endpoint to the Express server',
  repoPath: process.cwd(),
  onEvent: (event) => {
    console.log(event.type, event);
  }
});

// Stream events
for await (const event of stream) {
  if (event.type === 'token') {
    process.stdout.write(event.content);
  }
}

// Wait for completion
const result = await claudeAgent.waitForCompletion(taskId);

MCP Integration

await agent.run({
  prompt: 'Create a pull request for the new feature',
  mcp: {
    servers: [
      { 
        id: 'github', 
        transport: 'sse', 
        url: 'https://mcp.github.example/sse' 
      }
    ],
    allowTools: ['github.create_pr', 'github.list_branches']
  }
});

Unified Permissions

The SDK provides unified permission modes that work consistently across providers:

Permission Modes

  • strict: Restrictive mode, limits tool usage (maps to read-only for Codex, default for Claude)
  • auto: Balanced mode, auto-approves safe operations (maps to auto for both)
  • permissive: Allows all operations (maps to full-access for Codex, bypassPermissions for Claude)

Basic Usage

// Works with both Claude and OpenAI
await agent.run({
  prompt: 'Create a new feature',
  permissionMode: 'auto', // Unified mode
  tools: {
    allow: ['Read', 'Write', 'Edit'],     // Only allow these tools
    deny: ['Bash', 'WebSearch'],          // Block these tools
    autoApprove: ['Read', 'Glob']         // Auto-approve these without prompts
  }
});

Vendor-Specific Permissions

For fine-grained control, use vendor-specific configurations:

// Claude Code specific
const claudeAgent = createAgent(new ClaudeCodeAgent({
  vendor: {
    anthropic: {
      permissionMode: 'bypassPermissions',  // Claude-specific mode
      canUseTool: async (toolName, input, options) => {
        // Custom approval logic
        if (toolName === 'Write' && input.file_path?.includes('.env')) {
          return { behavior: 'deny', message: 'Cannot write to .env files' };
        }
        return { behavior: 'allow', updatedInput: input };
      },
      hooks: {
        PreToolUse: [{
          hooks: [async (input) => {
            console.log(`Tool called: ${input.tool_name}`);
            return { continue: true };
          }]
        }]
      }
    }
  }
}));

// OpenAI Codex specific
const codexAgent = createAgent(new CodexAgent({
  vendor: {
    openai: {
      approvalMode: 'full-access',  // Codex-specific mode
      profile: 'high',
      verbose: true
    }
  }
}));

Mixed Approach

Combine unified settings with vendor overrides:

await agent.run({
  prompt: 'Add tests for the new feature',
  
  // Unified settings
  permissionMode: 'auto',
  tools: { allow: ['Read', 'Write', 'Edit'] },
  
  // Vendor overrides (these take precedence)
  vendor: {
    anthropic: {
      permissionMode: 'acceptEdits',  // Override unified mode
      model: 'claude-3-opus-20240229'
    }
  }
});

Authentication

The SDK discovers credentials from environment:

  • ANTHROPIC_API_KEY for Claude Code
  • OPENAI_API_KEY for OpenAI/Codex

Override per-run:

await agent.run({
  prompt: 'Refactor the utils module',
  auth: { 
    anthropicApiKey: 'sk-ant-...' 
  }
});

Tool Execution

The Claude Code SDK includes built-in tool execution for file operations, bash commands, and more. The SDK executes these tools directly rather than just suggesting changes:

// The agent will actually create/edit files and run commands
await agent.run({
  prompt: 'Create a new Express server with error handling',
  permissionMode: 'auto',  // Will prompt for dangerous operations
  tools: {
    allow: ['Read', 'Write', 'Edit', 'Bash'],
    autoApprove: ['Read']  // Never prompt for read operations
  }
});

Available Tools

  • File Operations: Read, Write, Edit, MultiEdit
  • Search: Grep, Glob, LS
  • Execution: Bash (with timeout and background support)
  • Web: WebSearch, WebFetch
  • Notebooks: NotebookRead, NotebookEdit
  • Task Management: TodoWrite
  • MCP Tools: Any tools provided by MCP servers

Event Types

  • status: Task lifecycle phases
  • token: Streaming text output
  • tool_call/tool_result: Tool execution events
  • diff: Code changes in unified diff format
  • file_write: File modifications
  • metric: Performance metrics
  • error: Error events