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

@methodts/pacta-provider-claude-cli

v0.3.0

Published

Claude CLI AgentProvider for Pacta — claude --print/--resume

Readme


title: "@methodts/pacta-provider-claude-cli" scope: package layer: L3 contents:

  • src/claude-cli-provider.ts
  • src/cli-executor.ts
  • src/simple-code-agent.ts

@methodts/pacta-provider-claude-cli

AgentProvider implementation for Claude Code CLI -- wraps claude --print and claude --resume.

Overview

This package provides a Pacta AgentProvider that invokes the Claude CLI as a child process. It supports two execution modes:

  • Oneshot -- claude --print for single prompt-response invocations
  • Resumable -- claude --resume <sessionId> to continue a prior session

The provider implements both AgentProvider and Resumable interfaces. It does not support streaming (the CLI operates in batch mode).

Also includes simpleCodeAgent -- a ready-to-use agent that combines claudeCliProvider with a minimal code-focused pact.

Install

npm install @methodts/pacta-provider-claude-cli

Requires the claude CLI to be installed and available on PATH.

Layer Position

L4  @methodts/bridge                      Uses providers to deploy agents
L3  @methodts/pacta-provider-claude-cli   This package
    @methodts/pacta                       Core SDK (peer dependency)

Usage

Basic Provider

import { claudeCliProvider } from '@methodts/pacta-provider-claude-cli';
import { createAgent } from '@methodts/pacta';

const provider = claudeCliProvider();

const agent = createAgent({
  pact: {
    mode: { type: 'oneshot' },
    scope: { allowedTools: ['Read', 'Grep', 'Glob'] },
  },
  provider,
});

const result = await agent.invoke({
  prompt: 'List all exported functions in src/index.ts',
  workdir: '/my-project',
});

console.log(result.output);

Provider Options

const provider = claudeCliProvider({
  binary: 'claude',        // CLI binary name (default: 'claude')
  model: 'claude-sonnet-4-6',  // Default model override
  timeoutMs: 300_000,      // Execution timeout in ms (default: 5 min)
});

Resumable Sessions

The provider implements Resumable, so it can resume prior sessions:

const provider = claudeCliProvider();

const agent = createAgent({
  pact: { mode: { type: 'resumable' } },
  provider,
});

// First invocation
const result1 = await agent.invoke({ prompt: 'Read the README' });
const sessionId = result1.sessionId;

// Resume with the same session
const result2 = await provider.resume(sessionId, agent.pact, {
  prompt: 'Now summarize what you read',
});

simpleCodeAgent

A one-liner for common coding tasks:

import { simpleCodeAgent } from '@methodts/pacta-provider-claude-cli';

const agent = simpleCodeAgent();

const result = await agent.invoke({
  prompt: 'Add error handling to the database connection',
  workdir: '/my-project',
});

Default pact: oneshot mode, tools limited to Read/Grep/Glob/Edit/Write.

CLI Executor (Advanced)

For custom provider implementations or direct CLI invocation:

import { executeCli, buildCliArgs } from '@methodts/pacta-provider-claude-cli';

const args = buildCliArgs({
  prompt: 'Explain this code',
  print: true,
  model: 'claude-sonnet-4-6',
  allowedTools: ['Read', 'Grep'],
  cwd: '/project',
});

const result = await executeCli(
  { prompt: 'Explain this code', print: true, cwd: '/project' },
  { binary: 'claude', timeoutMs: 60_000 },
);

console.log(result.exitCode);  // 0
console.log(result.stdout);    // CLI output

Capabilities

provider.capabilities();
// {
//   modes: ['oneshot', 'resumable'],
//   streaming: false,
//   resumable: true,
//   budgetEnforcement: 'none',
//   outputValidation: 'client',
//   toolModel: 'builtin',
// }
  • Modes: oneshot and resumable (the CLI manages sessions via --resume)
  • Streaming: not supported (batch process)
  • Budget enforcement: none (client-side via budgetEnforcer middleware)
  • Output validation: client-side (CLI returns plain text)
  • Tool model: builtin (the CLI has its own tool implementation)

API Surface

Provider Factory

claudeCliProvider(options?) -- creates ClaudeCliProvider (AgentProvider & Resumable)

ClaudeCliProviderOptions: binary, model, timeoutMs, executorOptions

Pre-Assembled Agent

simpleCodeAgent(options?) -- creates Agent<string> with oneshot pact + Read/Grep/Glob/Edit/Write

CLI Executor

executeCli(args, options?) -- spawns the CLI process, returns CliResult (exitCode, stdout, stderr)

buildCliArgs(args) -- converts CliArgs to a string array for spawning

CliArgs: prompt, print, resumeSessionId, cwd, allowedTools, model, systemPrompt, maxTurns

ExecutorOptions: spawnFn (override for testing), binary, timeoutMs

Error Types

CliTimeoutError -- CLI process exceeded timeout

CliSpawnError -- failed to spawn the CLI binary

CliExecutionError -- CLI exited with non-zero exit code

Architecture

src/
  claude-cli-provider.ts   claudeCliProvider() factory — AgentProvider & Resumable
  cli-executor.ts          executeCli(), buildCliArgs() — process spawning + capture
  simple-code-agent.ts     simpleCodeAgent() — pre-assembled oneshot code agent

Development

npm run build            # TypeScript build
npm test                 # Run all tests