cli-agents
Build agentic apps on top of your users' existing AI subscriptions.
Instead of requiring API keys or managing token costs, cli-agents spawns
the AI CLI tools users already have installed — Claude Code, Codex, or
Gemini CLI — and provides a unified Rust interface for streaming events,
tool calls, cancellation, and structured results. Your app brings the UX;
the user brings their own subscription.
Features
- Single API —
run()works with any supported CLI backend. - Auto-discovery — finds installed CLIs in PATH, nvm, homebrew, etc.
- Streaming events — unified
StreamEventenum for text, thinking, tool calls, errors, and completion across all providers. - Timeouts & guardrails — idle timeout, total timeout, and consecutive tool-failure limits with automatic cancellation.
- MCP support — configure Model Context Protocol servers for all adapters.
- Async / Tokio — fully async with cancellation via
CancellationToken.
Quick start
use ;
use Arc;
async
Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["rt-multi-thread", "macros"] }
You must have at least one supported CLI installed:
| CLI | Install |
|---|---|
| Claude Code | npm install -g @anthropic-ai/claude-code |
| Codex | npm install -g @openai/codex |
| Gemini CLI | npm install -g @google/gemini-cli |
Auto-discovery
Omit cli to auto-discover the first available agent (Claude > Codex > Gemini):
let opts = RunOptions ;
let handle = run;
You can also query what's installed:
use ;
let all = discover_all.await;
for in &all
Configuration
System prompts
let opts = RunOptions ;
MCP servers
use ;
use HashMap;
let mut servers = new;
servers.insert;
let opts = RunOptions ;
Timeouts and safety
let opts = RunOptions ;
Permission bypass
By default, the library does not bypass CLI permission prompts. Set
skip_permissions: true to pass flags like --dangerously-skip-permissions
(Claude) or --dangerously-bypass-approvals-and-sandbox (Codex).
Use with caution — the agent will execute tools without human confirmation.
Provider-specific options
use ;
let opts = RunOptions ;
Cancellation
let handle = run;
let cancel = handle.cancel.clone;
spawn;
let result = handle.result.await.unwrap.unwrap;
// result.success == false when cancelled
Why cli-agents?
AI APIs require API keys and charge per token. Most developers already pay for
Claude Pro, ChatGPT Plus, or Gemini — and those subscriptions come with CLI
tools. cli-agents lets you build desktop apps, dev tools, and automation
that run on the user's existing subscription with zero API cost to you.
This is especially powerful for Tauri desktop apps: your Rust backend spawns the agent, streams events to the frontend, and the user's own subscription handles the AI — no API keys to configure, no billing to manage.
Use cases
Desktop apps (Tauri)
The primary use case. Build rich agentic UIs that leverage whatever AI CLI
the user has installed. RunOptions is serde-compatible, so front ends pass
config as JSON and receive StreamEvents back via Tauri events.
See doc/tauri_bridge_example.rs for a
complete Tauri integration with streaming and cancellation.
Dev tools and CI
Build custom coding agents, review bots, or CI automation that piggyback on existing CLI installations — no API keys needed.
Multi-agent orchestration
Run multiple agents concurrently or route tasks to different providers based on availability or capability.
StreamEvent variants
| Variant | Description |
|---|---|
TextDelta |
Incremental text output |
ThinkingDelta |
Reasoning / thinking output |
ToolStart |
A tool call has started |
ToolEnd |
A tool call has completed |
TurnEnd |
A full agent turn has completed |
Error |
An error or warning |
Done |
Run completed with final RunResult |
Raw |
Provider-specific event (escape hatch) |
CLI binary
The crate includes an optional CLI binary behind the cli feature:
# Auto-discover and run
# Specify provider
# Stream as JSON lines
# Verbose mode (show tools, thinking, stats)
# List available CLIs
Platform support
Currently Unix-only (macOS, Linux). Binary discovery uses which and
Unix file permission checks. Windows support is not yet implemented.
Contributing
Contributions are welcome! See CONTRIBUTING.md for details.
License
MIT