How ixi-enki/claw-code works
1. Repository shape
- The canonical implementation is the Rust workspace under rust/.
- The top-level src/ and tests/ tree is a companion Python/reference surface used for audit, parity, and helper tooling, not the primary runtime.
- The repo is organized around a CLI agent harness, provider clients, runtime orchestration, plugin/hooks, and a separate RAG service.
2. Primary user entrypoint: claw CLI
- The main executable lives in rust/crates/rusty-claude-cli.
- This binary is the user-facing surface for commands like prompt, doctor, status, resume/compact flows, and setup.
- It delegates most behavior to shared runtime and commands crates rather than implementing agent logic directly.
3. Core orchestration layer: runtime
- rust/crates/runtime is the central control plane.
- It owns session lifecycle, conversation state, prompt construction, bootstrapping, permissions, policy enforcement, sandboxing, hooks, branch/session recovery, and task orchestration.
- Most “agent behavior” is composed here: taking user input, shaping it into a task packet/prompt, enforcing permissions, then coordinating tool use and downstream services.
4. API and model-provider boundary
- rust/crates/api isolates outbound model/API traffic.
- It contains provider-specific clients for Anthropic and OpenAI-compatible backends, plus SSE/streaming, prompt caching, HTTP plumbing, and request/response types.
- This is the boundary between the local agent runtime and external LLM services, and it is also what the integration tests exercise against mock or compatibility services.
5. Tooling and command abstraction
- rust/crates/commands and rust/crates/tools hold reusable command/tool definitions and helper utilities.
- Tools are treated as a constrained execution surface, with runtime-side permission checks and path-scope enforcement.
- This layer is the bridge between the agent and local environment capabilities such as file operations, extraction, lane completion, and other task-oriented utilities.
6. Plugins and hooks
- rust/crates/plugins plus rust/crates/runtime/src/plugin_lifecycle.rs and hooks.rs implement plugin discovery and hook execution.
- Bundled examples under rust/crates/plugins/bundled/ show the expected plugin layout and pre/post hook model.
- Architecturally, plugins extend behavior at defined lifecycle points rather than bypassing the runtime, so they sit on the edge of the orchestration layer.
7. Security, policy, and workspace boundaries
- Permission handling is first-class in runtime via permissions, permission_enforcer, policy_engine, trust_resolver, and related modules.
- The repo also includes branch locks, stale branch/base handling, approval tokens, and path-scope enforcement to keep agent actions constrained.
- These controls form a boundary around filesystem access, command execution, and any potentially destructive local operations.
8. Session, history, and state management
- Session persistence is spread across session, session_store, conversation, history, transcript, state, and related modules.
- The agent’s working memory is represented locally and reloaded across resume/compact flows.
- There are also compression and summary mechanisms to shrink conversation context while preserving task continuity.
9. MCP, remote integration, and live tool bridges
- The runtime includes MCP client/server/stdIO support, OAuth, remote runtime integration, LSP client support, and a tool bridge for invoking external capabilities.
- This makes the agent architecture multi-protocol: local CLI on one side, and remote services or tool servers on the other.
- If you are diagramming the system, treat MCP and remote integrations as adjacent service boundaries, not core business logic.
10. RAG service as a separate subsystem
- rust/crates/claw-rag-service is its own service, with ingest, chunking, embedding, search, DB access, and Qdrant indexing.
- It has a standalone server entrypoint and Dockerfile, and serves both an API and a static UI.
- This is a distinct data pipeline: documents are ingested, chunked, embedded, indexed in Qdrant, and later searched for retrieval-augmented workflows.
11. Testing, parity, and mock infrastructure
- The repo contains dedicated mock services and compatibility harnesses, including mock-anthropic-service, compat-harness, and parity scripts/tests.
- These exist to verify protocol behavior, CLI contracts, and release readiness without depending on live external services.
- The CI workflows and contract tests are part of the architecture because they enforce the expected interaction shapes between CLI, runtime, and providers.
12. Python reference/audit workspace
- The top-level Python tree mirrors many conceptual subsystems: bootstrap, bridge, coordinator, plugins, remote, server, state, tools, and more.
- It appears to function as a reference implementation, migration aid, and audit surface for subsystem mapping and parity validation.
- For an architecture diagram, show it as a secondary support layer, not the production runtime.
13. Key end-to-end flow
- Typical flow: user invokes claw CLI → CLI passes into runtime/session bootstrap → runtime builds a prompt/task packet → permissions/policy are checked → tools/hooks/plugins may be invoked → outbound model traffic goes through the API/provider layer → streaming responses and events return to the CLI, while session/history state is persisted locally.
- Retrieval-assisted flows branch from runtime into the RAG service, which queries its indexed corpus and returns relevant context before or during model interaction.
14. Important diagram boundaries
- Local machine vs. external services: model providers, MCP endpoints, Qdrant/RAG backend, and any remote tool servers.
- Control plane vs. execution plane: CLI/runtime/policy/session management versus tools/plugins/provider calls.
- Primary codebase vs. support systems: Rust workspace is the product; Python, parity harnesses, and CI scripts are verification/migration scaffolding.
Main entry points: src/lib.rs runtime · src/lib.rs api · main.py python ref · rust-ci.yml ci checks
Components 18
Rust workspace
Primary production implementation and runtime services
- claw CLI · User-facing command surface for prompt, doctor, status, resume, compact, and setup flows
rust/crates/rusty-claude-cli/src/main.rs - runtime · Session lifecycle, prompt shaping, permissions, hooks, recovery, and task coordination
rust/crates/runtime/src/lib.rs - api · Outbound model clients, streaming, HTTP plumbing, prompt cache, and request/response types
rust/crates/api/src/lib.rs - commands · Reusable command abstractions used by the CLI and runtime
rust/crates/commands/src/lib.rs - tools · Constrained local execution helpers such as lane completion and extraction
rust/crates/tools/src/lib.rs - plugins · Plugin discovery and bundled hook layouts executed at lifecycle points
rust/crates/plugins/src/lib.rs - policy · Permission enforcement, trust resolution, sandboxing, branch locks, and path-scope controls
rust/crates/runtime/src/permission_enforcer.rs - session state · Conversation, transcript, history, state, summaries, and resume/compact persistence
rust/crates/runtime/src/session.rs - prompt pack · Builds task packets and prompts from user input and session context
rust/crates/runtime/src/prompt.rs - MCP bridge · MCP client/server/stdIO and tool-bridge integration for external capabilities
rust/crates/runtime/src/mcp_tool_bridge.rs - remote runtime · Remote runtime and OAuth-connected service integration boundary
rust/crates/runtime/src/remote.rs - rag service · Standalone ingest, chunking, embedding, search, and Qdrant indexing service
rust/crates/claw-rag-service/src/main.rs
Support layer
Reference surface, parity harnesses, and verification scaffolding
- mock/compat · Mock provider service and compatibility harness used by tests and parity checks
rust/crates/mock-anthropic-service/src/main.rs - python ref · Audit and parity-oriented Python mirror of major subsystems and tooling
src/main.py - ci checks · Release readiness, contract checks, and workflow enforcement for the repo
.github/workflows/rust-ci.yml
External services
Model, retrieval, and protocol endpoints outside the local runtime
- Anthropic · External model backend accessed through the API provider clients
- OpenAI compat · OpenAI-compatible backend accessed through the API provider clients
- Qdrant · Vector store used by the RAG pipeline for retrieval
Connections 20
- claw CLI → runtime: invoke · CLI hands commands and user intent into the orchestration layer
- runtime → prompt pack: shape · Runtime converts input and context into task packets and prompts
- runtime → policy: enforce · Permissions, trust, sandbox, and path controls gate runtime actions
- runtime → session state: persist · Session and history state are loaded, updated, and resumed here
- runtime → plugins: lifecycle · Runtime triggers plugin discovery and hook execution
- runtime → commands: dispatch · Shared command abstractions are used to implement user flows
- runtime → tools: use tools · Runtime brokers constrained local tools for task execution
- runtime → api: model calls · Runtime sends prompts and receives streaming responses through the API boundary
- api → Anthropic: request · Anthropic client traffic leaves the local system through this boundary
- api → OpenAI compat: request · OpenAI-compatible client traffic leaves the local system through this boundary
- runtime → MCP bridge: bridge · Runtime connects to MCP and other external tool protocols
- runtime → remote runtime: remote · Runtime can delegate to remote runtime and OAuth-backed integrations
- runtime → rag service: retrieve · Retrieval-assisted flows branch to the RAG subsystem
- rag service → Qdrant: index/search · Documents are indexed and queried in the vector store
- mock/compat → api: exercise · Compatibility harness validates provider/client behavior against the API layer
- ci checks → mock/compat: verify · CI and parity workflows run the mock and contract harnesses
- ci checks → runtime: contract test · Workflows validate runtime behavior and release readiness
- python ref → runtime: mirror · Python reference surface mirrors major runtime and subsystem concepts
- python ref → tools: mirror · Reference tooling surface parallels the Rust tools layer
- runtime → session state: resume/compact · Working memory is reduced and restored across conversational flows