$ show ultraworkers/claw-code
Claw Code is a production-grade CLI application for AI-assisted coding, built primarily in Rust with a complementary Python parity workspace. It serves as a local agent harness that integrates with multiple LLM providers (Anthropic, OpenAI, xAI, DashScope, local OpenAI-compatible), manages conversational sessions, enforces workspace-scoped permissions, supports the Model Context Protocol (MCP) for external tool integration, and provides a plugin system for lifecycle hooks. The architecture is a multi-crate Rust workspace under `rust/`, with the main binary `claw` (from `rusty-claude-cli`), a core runtime crate (`runtime`) handling session persistence, permission enforcement, conversation loops, and MCP plumbing; an API client crate (`api`) for provider dispatch and streaming; a plugins crate for lifecycle management; and supplementary crates for tools, telemetry, and a workspace RAG service. The Python workspace (`src/`) is explicitly a non-production porting/parity mirror of a TypeScript archive, used for surface mapping and audit. The Rust code is well-structured, extensively tested, and demonstrates strong engineering practicesβclean abstractions, reusable components, and defense-in-depth security (path validation, read-only command heuristics, approval tokens). Notable highlights include a permission enforcer with workspace boundary enforcement, a modular MCP client supporting multiple transports, a plugin system with manifest validation, and a session store with JSONL rotation and workspace fingerprint isolation. The repository is actively maintained (CI workflows, issue triage, recent commits) and shows low technical drift, though some modules have `#[allow(dead_code)]` annotations and the parity workspace adds maintenance overhead.
The LLM identified 5 files worth highlighting for reuse:
A workspace-aware permission enforcer that gates tool calls based on permission mode (read-only, workspace-write, danger-full-access). It normalizes paths lexically, detects read-only commands heuristically, and enforces tool-level requirements. The design is modular: a `PermissionPolicy` builder with rule parsing (allow/deny/ask), hook overrides, and `EnforcementResult` enum. This component is reusable in any agent tool that needs to restrict file system access based on policy.
Manages MCP servers over stdio via JSON-RPC with Content-Length framing. The `McpServerManager` spawns child processes, handles tool/ resource discovery, and supports degraded startup (healthy subset when some servers fail). It includes a `McpStdioProcess` struct, `encode_frame`/`decode_frame` functions, and retry logic. This is a clean, extractable component for any application integrating MCP tools over stdio.
An incremental SSE (Server-Sent Events) parser that processes streaming HTTP responses with buffering. It handles `[DONE]` markers, ping events, and line-oriented data. The parser is stateless enough to be reused across different API clients and provides a simple `next_event()` method. Demonstrates careful handling of edge cases in streaming protocols.
A complete plugin system with install/enable/disable/uninstall/update lifecycle, bundled plugin sync, manifest validation (`.claude-plugin/plugin.json`), hook integration (PreToolUse, PostToolUse, PostToolUseFailure), and tool registration. The design uses a `PluginKind` enum with `BuiltinPlugin`, `BundledPlugin`, and `ExternalPlugin` variants, each implementing a `Plugin` trait. The validation accumulates errors into a `Vec<PluginManifestValidationError>`, enabling clear error reporting. This component is standalone and could be used by any agent tool requiring a plugin architecture.
Handles session persistence in JSONL format with automatic log rotation at 256KB and cleanup of old rotated files (max 3). Sessions include metadata, messages, compactions, and prompt history. The `Session` struct provides `new`, `save_to_path`, `load_from_path`, `fork`, `heartbeat_at`, and `record_compaction` methods. Uses atomic file writes (temp + rename) for crash safety. This is a reusable pattern for any CLI application needing durable, append-only conversation storage.