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

@agentex/agent

v0.0.2

Published

Programmatic execution of AI coding agents (Claude Code, Codex, OpenClaw)

Readme

@agentex/agent

Programmatic execution of AI coding agents. Spawn and manage Claude Code, Codex, OpenClaw, or any CLI-based agent as a child process with streaming output, session resume, and a unified interface.

Install

npm install @agentex/agent

Quick Start

import { getProvider } from "@agentex/agent";

const claude = getProvider("claude");

const result = await claude.execute({
  prompt: "Add error handling to server.ts",
  config: {
    skipPermissions: true,
    maxTurns: 5,
    timeoutSec: 120,
  },
  onEvent: (event) => {
    if (event.type === "assistant") process.stdout.write(event.text);
    if (event.type === "tool_call") console.log(`Tool: ${event.name}`);
  },
});

console.log(result.exitCode);   // 0
console.log(result.summary);    // "Added try/catch to all route handlers..."
console.log(result.durationMs); // 12340
console.log(result.costUsd);    // 0.0342
console.log(result.usage);      // { inputTokens: 1200, outputTokens: 350, cachedInputTokens: 800 }

Built-in Providers

| Provider | CLI | Description | | ---------- | ---------------- | ----------------------------------- | | claude | claude | Claude Code (Anthropic) | | codex | codex | Codex CLI (OpenAI) | | openclaw | openclaw | OpenClaw agent | | process | any executable | Generic process executor |

Custom Providers

import { registerProvider } from "@agentex/agent";
import type { ProviderModule } from "@agentex/agent";

const myProvider: ProviderModule = {
  type: "my-agent",
  async execute(ctx) {
    const startedAt = new Date().toISOString();
    // Spawn your agent, stream events via ctx.onEvent...
    return {
      runId: ctx.runId ?? "generated-id",
      exitCode: 0,
      signal: null,
      timedOut: false,
      startedAt,
      completedAt: new Date().toISOString(),
      durationMs: 0,
      errorMessage: null,
      errorCode: null,
      costUsd: null,
      model: null,
      summary: "Done",
      sessionParams: null,
      sessionDisplayId: null,
      clearSession: false,
      billingType: null,
    };
  },
  async testEnvironment(ctx) {
    return { providerType: ctx.providerType, status: "pass", checks: [], testedAt: new Date().toISOString() };
  },
};

registerProvider(myProvider);

API

getProvider(type: string): ProviderModule

Returns a registered provider by name. Throws if not found.

listProviders(): string[]

Returns all registered provider type names.

registerProvider(provider: ProviderModule): void

Registers a custom provider, making it available via getProvider().

renderTemplate(template: string, context: Record<string, string>): string

Renders a template string with {{variable}} interpolation.

redactEnvForLogs(env: Record<string, string>): Record<string, string>

Returns a copy of env vars with sensitive values redacted for safe logging.

Execution Context

Only prompt is required. Everything else has sensible defaults.

interface ExecutionContext {
  prompt: string;             // The task to execute
  model?: string;             // Model override (e.g. "claude-sonnet-4-20250514")
  runId?: string;             // Auto-generated UUIDv7 if omitted
  cwd?: string;               // Defaults to process.cwd()
  env?: Record<string, string>;
  sessionParams?: Record<string, unknown> | null;
  config?: ProviderConfig;
  onOutput?: (stream: "stdout" | "stderr", chunk: string) => void;
  onEvent?: (event: StreamEvent) => void;
}

Execution Result

interface ExecutionResult {
  runId: string;
  exitCode: number | null;
  signal: string | null;
  timedOut: boolean;
  startedAt: string;          // ISO timestamp
  completedAt: string;        // ISO timestamp
  durationMs: number;         // Wall-clock duration
  errorMessage: string | null;
  errorCode: string | null;
  usage?: { inputTokens: number; outputTokens: number; cachedInputTokens?: number };
  costUsd: number | null;
  model: string | null;
  summary: string | null;
  sessionParams: Record<string, unknown> | null;
  sessionDisplayId: string | null;
  clearSession: boolean;
  billingType: "api" | "subscription" | null;
}

Stream Events

Events emitted during execution via onEvent. All events include a timestamp field.

  • system — Session init (event.sessionId, event.model)
  • assistant — Text output from the agent (event.text)
  • thinking — Agent's internal reasoning (event.text)
  • tool_call — Agent invoked a tool (event.name, event.input)
  • tool_result — Tool returned a result (event.content, event.isError)
  • result — Final result (event.text, event.cost)

Requirements

  • Node.js >= 18
  • The CLI for each provider must be installed and on $PATH (e.g., claude for the Claude provider)

License

MIT