One TypeScript SDK for every local coding agent. Drives Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Factory Droid, Pi, Cline, Kilo, Qwen Code, and Augment Code (Auggie) over the Agent Client Protocol, with cost budgets, structured JSON, tool middleware, multi-agent orchestration, and a Vercel AI SDK provider (LanguageModelV3, ai@^6).
import{agents}from"@pivanov/agents-wire";constresult=awaitagents.ask("claude","Refactor src/auth.ts",{permission: "auto-allow",maxCostUsd: 0.5,});console.log(result.text,result.cost?.totalUsd);Local coding agents are powerful but awkward to drive programmatically. Each one ships a different CLI; their output formats drift; cost tracking is bring-your-own; structured outputs are a prompt-engineering project; and combining several agents takes a lot of glue. agents-wire fixes all of that with one transport and a small, focused API.
- Twelve agents, one API - Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Factory Droid, Pi, Cline, Kilo, Qwen Code, Augment Code (Auggie)
ask/stream/session- one-shot, streaming async-iterable, multi-turn with shared subprocessaskJsonwith Standard Schema - Zod 4 / Valibot / ArkType auto-derived to JSON Schema. Strict CLI channel for Claude (via@pivanov/claude-wire), post-hoc validation for the rest.- Cost tracker + budgets - per-agent breakdown, runtime pricing table, auto-abort when over budget
- Tool middleware -
allowed/blocked/onToolUsedecision pipeline plumbed through ACP permission requests - Permission policies -
auto-allow,auto-allow-once,auto-reject,stream(HITL), or custom function - Orchestration -
failover/race/cascade/poolfor multi-agent workflows - Vercel AI SDK provider (LanguageModelV3,
ai@^6) -agentModel("claude")drops intostreamText/generateText - Typed errors -
WireErrorwithcodefield plusBudgetExceededError,JsonValidationError,AbortError,CapabilityNotSupportedError - Fully typed - discriminated
TAgentEventunion, full IntelliSense, noany - Mock + transcript replay -
@pivanov/agents-wire/testingfor deterministic tests - CLI -
agents-wire ask | ask-json | stream | detect | agents
bun add @pivanov/agents-wire
# or
npm install @pivanov/agents-wireYou also need the agent's CLI installed and authenticated. Run npx @pivanov/agents-wire detect to see which agents are available on your machine.
| Agent | How it speaks ACP | Install |
|---|---|---|
claude | bridge (@agentclientprotocol/claude-agent-acp, bundled) | Claude Code + claude /login |
codex | bridge (@zed-industries/codex-acp, bundled) | OpenAI Codex CLI on PATH |
cursor | native (agent acp) | Cursor Agent CLI |
copilot | bridge (@github/copilot --acp, peer install) | npm i -g @github/copilot + gh auth login |
gemini | bridge (@google/gemini-cli --acp, peer install) | npm i -g @google/gemini-cli + gemini auth login |
opencode | native (opencode acp) | npm i -g opencode-ai |
droid | native (droid exec --output-format acp) | npm i -g droid + FACTORY_API_KEY |
pi | native (pi acp) | npm i -g @mariozechner/pi-coding-agent |
cline | native (cline --acp) | npm i -g cline + cline auth or provider keys |
kilo | native (kilo acp) | npm i -g @kilocode/cli + kilo auth login --provider <id> or KILO_API_KEY |
qwen | native (qwen --acp --experimental-skills) | npm i -g @qwen-code/qwen-code + qwen auth qwen-oauth or BAILIAN_CODING_PLAN_API_KEY |
auggie | native (auggie --acp) | npm i -g @augmentcode/auggie + auggie login (subscription required) |
import{agents}from"@pivanov/agents-wire";constresult=awaitagents.ask("claude","Summarize README.md in 3 bullets",{cwd: process.cwd(),permission: "auto-allow",maxCostUsd: 0.25,});console.log(result.text);console.log(result.usage);// { contextSize, contextUsed, costUsd }console.log(result.cost?.totalUsd);// SDK-side cumulative costimport{agents}from"@pivanov/agents-wire";conststream=agents.stream("claude","Refactor src/auth.ts to use the new session API");forawait(consteventofstream){if(event.type==="text-delta"){process.stdout.write(event.text);}if(event.type==="tool-call"){console.log("\n[tool]",event.tool,event.input);}}constfinal=awaitstream.result();console.log("\nfinished:",final.stopReason);import{agents}from"@pivanov/agents-wire";await using session=awaitagents.session("codex",{permission: "auto-allow"});awaitsession.ask("List all TODOs in the repo");constfix=awaitsession.ask("Now fix the highest-priority one");console.log(fix.text);console.log("session cost:",session.cost.snapshot.totalUsd);import{agents}from"@pivanov/agents-wire";import{z}from"zod";constIssue=z.object({title: z.string(),severity: z.enum(["low","medium","high"]),});const{ data }=awaitagents.askJson("claude","Read src/auth.ts and report issues",Issue);console.log(data.title,data.severity);Works with Zod 4, Valibot (with @valibot/to-json-schema installed), and ArkType. You can pass a raw JSON Schema string for prompt guidance only — askJson will steer the agent toward that shape but cannot validate the response. For validated output, pass a Standard Schema instance.
constresult=awaitagents.ask("claude","Fix the build",{toolHandler: {blocked: ["Bash"],// hard blockonToolUse: async(event)=>{if(event.tool==="Write"&&String(event.input).includes("secrets")){return{decision: "deny",reason: "no secrets"};}return"allow";},},});Four primitives for combining agents.
Try candidates in order; skip on transient errors, return the first success.
constresult=awaitagents.failover("Classify this ticket",["claude","codex","gemini"]);console.log(result.winner,result.text);All candidates in parallel; first to finish wins, losers get cancelled.
constresult=awaitagents.race("Classify this ticket",["claude","gemini"]);console.log(result.winner,"lost:",result.losers.map((l)=>l.agent));Escalation chain. Try cheaper/faster first; fall through if the result fails an accept predicate.
constresult=awaitagents.cascade("Triage this issue",[{agent: "claude",options: {model: "haiku"},accept: (r)=>r.text.length>20},{agent: "claude",options: {model: "sonnet"},accept: (r)=>r.text.length>50},{agent: "claude",options: {model: "opus"}},]);console.log("won at stage",result.winningStageIndex);Warm subprocess pool with capacity limit. Concurrent prompts share the pool.
await using pool=awaitagents.pool({agents: ["claude"],capacity: 4});constreplies=awaitPromise.all(prompts.map((p)=>pool.ask(p)),);console.log("total cost:",pool.cost.snapshot.totalUsd);Use any agent as a LanguageModelV3 for streamText / generateText:
import{streamText}from"ai";import{agentModel}from"@pivanov/agents-wire/ai-sdk";const{ textStream }=streamText({model: agentModel("claude",{permission: "auto-allow"}),prompt: "Refactor src/auth.ts",});forawait(constchunkoftextStream){process.stdout.write(chunk);}For multi-turn sharing one subprocess across streamText calls:
import{createAgentModelSession}from"@pivanov/agents-wire/ai-sdk";await using s=awaitcreateAgentModelSession("codex");awaitstreamText({model: s.model,prompt: "list TODOs"});awaitstreamText({model: s.model,prompt: "now fix the highest-priority one"});npx @pivanov/agents-wire ask claude --prompt "explain this repo"
npx @pivanov/agents-wire ask-json claude --prompt "extract metadata" --schema-file ./schema.json
npx @pivanov/agents-wire stream gemini --prompt "summarize this PR"
npx @pivanov/agents-wire detect # list available agents on this machine
npx @pivanov/agents-wire agents # list all built-in agents@pivanov/agents-wire/testing ships a mock agent and transcript record/replay so you can test consumers without spawning real processes.
import{createMockAgent,createRecorder,replayTranscript}from"@pivanov/agents-wire/testing";constmock=createMockAgent({agent: "claude",turns: [{text: "ok"},{text: "porcupine"},],});constturn1=awaitmock.ask("remember 'porcupine'");// → "ok"constturn2=awaitmock.ask("what was it?");// → "porcupine"| Subpath | What's there |
|---|---|
@pivanov/agents-wire | the main facade and types |
@pivanov/agents-wire/errors | typed WireError + subclasses + KNOWN_ERROR_CODES |
@pivanov/agents-wire/ai-sdk | Vercel AI SDK provider |
@pivanov/agents-wire/testing | mock agent + transcript replay |
@pivanov/agents-wire/catalog | individual agent definitions + registry |
@pivanov/agents-wire/orchestrate | failover, race, cascade, pool |
- Bun ≥ 1.0 or Node ≥ 22
- POSIX (macOS, Linux, WSL). Native Windows isn't supported.
- The agent CLIs you want to drive must be installed and authenticated on the host machine.
When agent bridges (@agentclientprotocol/claude-agent-acp, @github/copilot, @google/gemini-cli) are installed globally rather than as workspace deps, agents-wire walks npm root -g, your Node prefix, and conventional system roots (/usr/local, /opt/homebrew, ~/.npm-global, ~/.local). If your global root is in a non-standard location (custom npm config prefix, isolated Volta/asdf install), set:
export AGENTS_WIRE_GLOBAL_NODE_MODULES=/path/to/your/global/node_modulesThe override is consulted first; resolution falls through to the standard search if the override doesn't contain the requested package.
bun install
bun run typecheck
bun run lint
bun run --filter '@pivanov/agents-wire' build
# Run the smoke test against your installed Claude
bun packages/agents-wire/tests/smoke.ts
bun packages/agents-wire/tests/smoke-orchestrate.tsSupported by LogicStar AI.
MIT - © Pavel Ivanov