← Back to PRs

#21168: feat(agents): Claude Agent SDK as alternative agent runtime

by olivertriunfo open 2026-02-19 18:56 View on GitHub →
docs agents size: XL
## Summary Add the [Claude Agent SDK](https://github.com/anthropics/claude-agent-sdk-typescript) as an alternative agent runtime behind a provider-agnostic abstraction layer. - **Runtime abstraction layer** — `AgentRuntime` / `RuntimeSession` / `SessionStore` interfaces with a pi-agent reference implementation, so future runtimes slot in cleanly - **Claude SDK runtime** — spawns Claude Code CLI as a subprocess via the SDK's `query()` function, with streaming, session resume, and abort support - **Opt-in activation** — set `agents.defaults.runtime: "claude-sdk"` in config or `OPENCLAW_AGENT_RUNTIME=claude-sdk` env var; default remains `pi-agent` with zero impact on existing users ### Architecture The SDK runtime uses a subprocess model (not in-process). Custom tools are provided via an MCP server, and the SDK subprocess handles its own context management, compaction, and tool execution. Events are bridged back to the existing agent event system so the gateway/TUI work unchanged. ### Key files | File | Purpose | |------|---------| | `src/agents/runtime/types.ts` | Core interfaces | | `src/agents/runtime/pi-runtime.ts` | pi-agent implementation | | `src/agents/runtime/claude-sdk-runtime.ts` | Claude SDK implementation | | `src/agents/runtime/claude-session-store.ts` | Session persistence for SDK | | `src/agents/runtime/event-bridge.ts` | Event mapping | | `src/agents/runtime/tool-bridge.ts` | Tool mapping | | `src/agents/runtime/index.ts` | Factory + `resolveRuntimeType()` | | `src/agents/pi-embedded-runner/run/claude-sdk-attempt.ts` | SDK attempt runner | | `src/agents/pi-embedded-runner/run.ts` | Runtime dispatch | | `docs/claude-sdk-runtime.md` | Setup guide | ## Testing - CI passes (types, lint, formatting) - Default runtime (`pi-agent`) behavior unchanged — no regressions - SDK runtime activates when `OPENCLAW_AGENT_RUNTIME=claude-sdk` is set - Lightly tested end-to-end with local OpenClaw instance ## AI disclosure This PR was AI-assisted (Claude Opus 4.6 via Claude Code). The contributor understands all code changes and has tested them locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Most Similar PRs