Command-line AI Agent built with OpenAgentSDK (Swift) — a terminal tool that demonstrates the full power of the SDK's public API through a real, usable product.
The ultimate proof of SDK capability. If this CLI runs smoothly, the SDK's public API is complete. If it hits a wall, we've found an API gap.
- Streaming Output — Real-time agent responses with ANSI-styled terminal output
- Interactive REPL — Multi-turn conversations in the terminal
- Single-Shot Mode — Quick one-off queries via command line
- Tool Visibility — See which tools the agent calls and their results
- Session Persistence — Save, resume, and fork conversations
- MCP Integration — Connect external tool servers via Model Context Protocol
- Permission Control — Choose from 6 permission modes for safe execution
- Multi-Provider LLM — Anthropic (Claude) and OpenAI-compatible APIs (GLM, Ollama, etc.)
- Hook System — Lifecycle event handlers for customization
git clone https://github.com/terryso/open-agent-cli.git
cd open-agent-cli
swift buildCreate ~/.openagent/config.json:
{
"apiKey": "your-api-key",
"provider": "openai",
"baseURL": "https://open.bigmodel.cn/api/coding/paas/v4",
"model": "glm-5.1"
}Or set environment variables:
export OPENAGENT_API_KEY=your-api-key# Single-shot query
swift run openagent "Explain Swift concurrency in one paragraph."
# Interactive REPL
swift run openagent
# With options
swift run openagent --model claude-sonnet-4-6 --max-turns 5 "Analyze this codebase"| Option | Description | Default |
|---|---|---|
--model |
LLM model to use | glm-5.1 |
--api-key |
API key | config file or env |
--provider |
LLM provider (anthropic, openai) |
anthropic |
--base-url |
Custom API endpoint | — |
--mode |
Permission mode | default |
--max-turns |
Maximum agent turns | 10 |
--max-budget-usd |
Cost cap in USD | — |
--system-prompt |
Custom system prompt | — |
--thinking |
Thinking budget tokens | — |
--log-level |
Log level (debug, info, warn, error) |
— |
--version |
Print version | — |
--help |
Print help | — |
CLI Entry Point (ArgumentParser)
│
▼
AgentFactory ──── OpenAgentSDK.createAgent()
│
▼
OutputRenderer ◀── AsyncStream<SDKMessage>
│ │
▼ ▼
Terminal Agent Loop (SDK)
The CLI consumes only import OpenAgentSDK — zero internal module access. Every feature exercises the SDK's public API surface.
- Swift 6.1+
- macOS 13+
- OpenAgentSDK (Swift) (as local dependency)
# Build
swift build
# Run tests (124 tests)
swift test
# Run with coverage
swift test --enable-code-coverage
# Open in Xcode
open Package.swift- OpenAgentSDK (Swift) — The SDK this CLI is built on
- OpenAgentSDK (TypeScript) — TypeScript version
- OpenAgentSDK (Go) — Go version
MIT