针对 Codex CLI、Claude Code 和 OpenCode 的统一 TypeScript 运行时,提供带有类型化事件、生命周期控制、权限和任务图的功能。
针对 Codex CLI、Claude Code 和 OpenCode 的统一 TypeScript 运行时,提供带有类型化事件、生命周期控制、权限和任务图的功能。
[!IMPORTANT] Maintenance mode. This repository is archived and is not under active development. Existing releases remain available without compatibility guarantees or planned feature updates. For new multi-agent integrations, prefer Agent Client Protocol or the official SDK of your selected agent.
Agent CLI Runtime is the dependable adapter layer you reach for when you do not want to build yet another coding agent.
Modern local coding agents (like Codex CLI, Claude Code, and OpenCode) already excel at planning, editing files, running tools, asking for permissions, and managing LLM loops. This runtime keeps those complex loops inside the user's installed CLI while giving product builders and developers a unified, typed Node.js/TypeScript API to programmatically orchestrate them.
Building developer tools with local coding agents usually means wrestling with non-standardized CLI flags, parsing chaotic terminal streams, managing subprocess timeouts, and dealing with permission leaks.
Agent CLI Runtime normalizes this chaotic landscape into a clean, predictable, and local-first execution layer:
| Subprocess Problem | Runtime Responsibility |
|---|---|
| CLI Fragmentation | |
Users have different CLIs installed (codex, claude, opencode) |
Auto-Detection |
| Probes and detects available coding agent CLIs in the system. | |
| Argument Limits | |
| Oversized prompts break command-line length limits (argv) | Safe Prompt Transport |
| Gracefully leverages stdin and temporary prompt files instead of argv. | |
| Stream Inconsistency | |
| Every CLI outputs a different text/JSON format | Event Stream Normalization |
Parses raw stdout/stderr into a single unified AgentEvent protocol. |
|
| Zombies & Hangs | |
| Headless runs can hang indefinitely on network stalls | Lifecycle Management |
| Enforces timeouts, inactivity limits, cancellation, and exit classification. | |
| Privilege Escalation | |
| Agents can run arbitrary shell commands outside workspaces | Explicit Sandboxing |
Enforces strict cwd, extraAllowedDirs, and permissionPolicy. |
AgentEvent stream.runtime.lock.json), and store health/repair utilities.Install the library via npm:
npm install agent-cli-runtimeOr execute CLI commands on the fly using npx:
npx --package agent-cli-runtime agent-runtime agents --json
npx --package agent-cli-runtime agent-runtime conformance --mode fixtures --jsonInitialize the runtime and detect what coding agents are installed on the local machine:
import { createAgentRuntime } from "agent-cli-runtime";
const runtime = createAgentRuntime();
// Detect installed coding agents on the machine
const agents = await runtime.detect({
includeUnavailable: true,
});
console.log("Detected agents:", agents);Run a direct prompt and consume the normalized event stream in real-time:
…Execute complex objectives that are automatically broken down into dependency-aware task graphs by the planner:
…The core runtime acts as a process orchestrator and event normalizer. Individual adapters encapsulate CLI-specific nuances, allowing the client application to interact with a single interface.
flowchart LR
App["Your Application / Daemon"] --> Runtime["Agent CLI Runtime"]
Runtime --> Registry["Adapter Registry"]
Registry --> Codex["Codex CLI Adapter"]
Registry --> Claude["Claude Code Adapter"]
Registry --> OpenCode["OpenCode Adapter"]
Codex --> Subprocess["Spawn CLI Subprocess"]
Claude --> Subprocess
OpenCode --> Subprocess
Subprocess --> Parser["Stream Parser"]
Parser --> Events["Unified AgentEvent Stream"]
Events --> AppEach adapter manages CLI-specific responsibilities:
When calling createGoal, the planner output is parsed and validated against a strict JSON schema:
{
"tasks": [
{
"id": "T001",
"title": "Fix Parser Core",
"objective": "Identify and correct the off-by-one error in stream-parser.",
"dependencies": [],
"allowedFiles": ["src/parsers/stream-parser.ts"],
"validationCommands": ["npm test"],
"agentId": "codex",
"retryPolicy": {
"maxAttempts": 2,
"retryableErrorCodes": ["AGENT_TIMEOUT"],
"backoffMs": 250
}
}
]
}id, title, and objective are mandatory strings.dependencies, allowedFiles, and validationCommands are optional string arrays.retryPolicy can override global schedules.By default, runs and goals are kept entirely in-memory. By passing a storageDir, the runtime enables durable local persistence:
const runtime = createAgentRuntime({
storageDir: "./.agent-runtime",
storage: { durability: "fsync" }, // Optional. Default is "relaxed"
});On-disk serialization uses a robust, append-friendly layout:
.agent-runtime/
runtime.lock.json # Single-writer concurrency lease
runs/
/
manifest.json # Run configuration metadata
events.jsonl # Append-only stream event log
goals/
/
manifest.json # Goal objective & tasks configuration
events.jsonl # Append-only goal execution event logruntime.lock.json file contains information about the active runtime (PID, host, heartbeat). A second runtime trying to gain write access to the same directory will be safely refused.AGENT_RUNTIME_INTERRUPTED diagnostic, ensuring your data history never lies about active state.The package is intentionally environment-first to avoid mutating user files.
Specify custom binary locations using environment variables:
export CODEX_BIN=/absolute/path/to/codex
export CLAUDE_BIN=/absolute/path/to/claude
export OPENCODE_BIN=/absolute/path/to/opencodeConfigure Claude Code's Anthropic-compatible provider through environment variables:
export ANTHROPIC_BASE_URL=
export ANTHROPIC_MODEL=
export ANTHROPIC_DEFAULT_OPUS_MODEL=
export ANTHROPIC_DEFAULT_SONNET_MODEL=
export ANTHROPIC_DEFAULT_HAIKU_MODEL=
export CLAUDE_CODE_SUBAGENT_MODEL=
export CLAUDE_CODE_EFFORT_LEVEL=
export ANTHROPIC_API_KEY=⚠️ Security Warning: Never write real token values or API keys directly into prompts, manifests, examples, or committed code files.
Subprocesses automatically inherit system network proxies:
export HTTPS_PROXY=http://127.0.0.1:7897
export HTTP_PROXY=http://127.0.0.1:7897The package ships with an agent-runtime CLI tool for administrative, testing, and debugging purposes.
…| Adapter | Binary | Transport | Stream Strategy | Status / Capabilities |
|---|---|---|---|---|
| Codex CLI | codex |
stdin | codex exec --json |
Fully supported. Timeout diagnostics categorize startup lags, and reconnect streams are parsed as statuses. |
| Claude Code | claude |
stdin JSONL | stream-json |
Basic detection supported. Advanced capabilities and authentication probe support is ongoing. |
| OpenCode | opencode |
stdin | JSON Stream | Supported. Stdin prompts verified on opencode 1.15.6. Read-only isolation profile is active. |
This runtime spawns and manages powerful coding agents on your local machine. We take safety extremely seriously:
Bearer keywords before writing data to manifests or diagnostic exports.This project is in maintenance mode. No new features, adapter compatibility updates, beta releases, or stable releases are planned. The published alpha packages remain available for existing users without ongoing support guarantees.
[email protected] - Published corrective alpha release. Published on npm; npm alpha and latest dist-tags both point at 0.1.0-alpha.6. GitHub Release v0.1.0-alpha.6 exists as a prerelease with the npm registry tarball asset, and release:post-alpha:verify tarball parity passes.[email protected] - Published on npm. npm alpha and latest dist-tags both point at 0.1.0-alpha.6. GitHub Release v0.1.0-alpha.5 exists as a prerelease with the npm registry tarball asset, and release:post-alpha:verify tarball parity passes. Its immutable npm tarball contains stale package docs, so aggregate published verification (published:verify / published:verify:evidence) fails with registry_packaged_docs_failed; alpha.5 is not final corrective release acceptance.[email protected] - Historical version published on npm. The immutable npm tarball contains stale release-prep package docs. GitHub Release v0.1.0-alpha.4 exists with the npm registry tarball asset, and GitHub Release tarball parity passes.[email protected] - Historical corrective pre-alpha release.[email protected] - Published historical version whose immutable npm tarball contains stale pre-publish package docs.[email protected] - Earlier published alpha with GitHub pre-release v0.1.0-alpha.1.暂无开放 Issues,或尚未同步最近议题。