# cppClaw **Repository Path**: judeli/cppclaw ## Basic Information - **Project Name**: cppClaw - **Description**: cppClaw 是一个基于现代 C++23 打造的高性能、轻量级 AI 智能体(c++版本小龙虾),受 nanobot 和 OpenClaw 启发,具备 ReAct Agent 循环、可扩展工具系统、多渠道接入、灵活 JSON 配置,支持主流 LLM 提供商及长期记忆与会话持久化能力等,是将 AI Agent 带入 C++ 世界的原生解决方案。 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2026-03-12 - **Last Updated**: 2026-08-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

🦞 cppClaw: C++ Native AI Assistant

A high-performance, lightweight AI agent framework built with modern C++23

C++23 CMake License
Version 0.1.0

[中文](README.zh.md) | **English**
--- ## 🚀 Overview **cppClaw** is a high-performance AI assistant framework built with modern C++23, dedicated to bringing the intelligence of large language models to local application scenarios: - ⚡ **Extreme Performance**: Compiled language advantages with millisecond-level startup and ~10MB memory footprint - 🔧 **Flexible Configuration**: JSON-based configuration supporting multiple LLM providers - 🛡️ **Privacy First**: Supports local Ollama deployment, keeping data within your network - 📦 **Portable Deployment**: Cross-platform single binary with no complex dependencies ### Inspiration Inspired by [nanobot](https://github.com/HKUDS/nanobot) and [OpenClaw](https://github.com/openclaw/openclaw.git), cppClaw brings the same philosophy to the C++ ecosystem with a focus on: - **Performance**: Minimal runtime overhead - **Portability**: Single binary deployment across Windows/Linux/macOS - **Extensibility**: Plugin architecture via skills and tools --- ## ✨ Features ### Core Capabilities | Feature | Description | |---------|-------------| | **🧠 ReAct Agent** | Complete → Tool Calls → Execute → Iterate loop with safety guards | | **🛠️ Tool System** | File operations, shell execution, web search, skill hub | | **💬 Multi-Channel** | CLI for local use, Gateway for Telegram/Discord/QQ | | **🔧 Configuration** | JSON config with OpenAI/Anthropic/Ollama/Zhipu support | | **📚 Skills** | GitHub, Weather, Summarize, Self-Improvement | | **🧵 Memory** | Long-term memory (`MEMORY.md`) + session history | ### Technical Highlights - **Modern C++23**: `std::expected`, ranges,coroutines, modules-ready new features, and there is no lack of the smoothness of modern programming languages. - **Type-Safe Tools**: Strong typing for tool definitions - **Workspace Sandbox**: Security-first file/command access control --- ## 📊 Comparison | Feature | cppClaw | PicoClaw (Golang)| NanoBot (Python) | OpenClaw (TypeScript) | |---------|--------------|------------------|----------------------|----------------------| | **Language** | C++23 | Golang 1.25+| Python 3.10+ | TypeScript/Node.js | | **Memory Footprint** | ~10MB | < 10MB | ~100MB | ~1GB+ | | **Startup Time** | <10ms | ~1s | ~5s | ~30s | | **Deployment** | Single binary | Single binary| Python env + deps | Node.js + npm | | **Performance** | ⚡⚡⚡⚡ | ⚡⚡⚡ | ⚡⚡ | ⚡ | *Estimated based on current implementation; actual usage varies by workload. --- ## 🏗️ Architecture ### Directory Structure ``` cpp-ai-assistant/ ├── CMakeLists.txt # CMake root configuration ├── config/ # Configuration management │ └── default.json # Default configuration, copied to ~/.cppclaw/ during init ├── third_party/ # Header-only libraries (internal dependency examples; actual downloads may vary) │ ├── json/ # nlohmann/json │ ├── spdlog/ # spdlog │ ├── cereal/ # cereal │ ├── httplib/ # cpp-httplib │ └── CMakeLists.txt # Dependency library and auto-download configuration ├── include/ # Header files directory. Tools, agent interfaces or abstract class encapsulation. │ ├── common/ # Basic modules │ │ ├── logger.hpp # Logger encapsulation │ │ ├── serializer.hpp # Serialization encapsulation │ │ ├── config.hpp # Configuration loading │ │ ├── file_util.hpp # File operation encapsulation │ │ ├── error.hpp # Error handling encapsulation │ │ ├── date_time.hpp # Date/time handling encapsulation │ │ ├── string_util.hpp # String processing encapsulation │ │ ├── uuid.hpp # UUID generation encapsulation │ │ ├── base64.hpp # Base64 encoding/decoding encapsulation │ │ ├── md5.hpp # MD5 calculation encapsulation │ │ ├── constants.hpp # Common constant definitions. e.g., environment names dev/prod/test, config file paths, default log levels, error codes, etc. │ │ └── expected.hpp # Expected encapsulation │ ├── core/ # Core engine │ │ ├── agent_loop.hpp # ReAct loop │ │ ├── context.hpp # Context building │ │ ├── memory.hpp # Memory system │ │ ├── skills_loader.hpp # Skills loading │ │ └── task.hpp # Task definition │ ├── llm/ # LLM providers │ │ ├── provider.hpp # Unified interface │ │ ├── provider_registry.hpp # Provider Registry │ │ ├── openai.hpp # OpenAI implementation │ │ ├── anthropic.hpp # Anthropic implementation │ │ └── ollama.hpp # Ollama local implementation │ ├── tools/ # Tool system │ │ ├── tool_base.hpp # Tool abstraction │ │ ├── shell_tool.hpp # Shell execution │ │ ├── file_tool.hpp # File read/write operations │ │ └── web_tool.hpp # Web search │ ├── bus/ # Message bus │ │ ├── message.hpp # Message definition │ │ ├── event_queue.hpp # Event queue │ │ └── channel.hpp # Channel abstraction │ ├── channels/ # Channel implementation │ │ ├── cli_channel.hpp # Command line │ │ └── http_channel.hpp # HTTP API │ ├── cron/ # Scheduled tasks │ │ └── scheduler.hpp # Task scheduling │ └── heartbeat/ # Active wake-up │ └── heartbeat.hpp # HEARTBEAT.md periodic tasks ├── src/ # Source code │ ├── apps/ # Applications │ │ ├── gateway/ # Gateway main program │ │ │ ├── main.cpp # Main program │ │ │ └── CMakeLists.txt # CMake configuration │ │ └── cli/ # CLI tools (init, status, etc.) │ │ ├── main.cpp # Main program │ │ └── CMakeLists.txt # CMake configuration │ └── common/ # libcppclaw_common ├── tests/ # Unit tests │ ├── p1/ # Phase 1 test execution program │ ├── p2/ # Phase 2 test execution program │ ├── .../ # Other phase test execution programs │ └── CMakeLists.txt # Common CMake configuration for tests ├── docs/ # Documentation │ ├── prompt_example/ # Configuration examples │ │ ├── scripts/ # Build scripts │ │ ├── skills/ # Built-in skills │ │ ├── AGENTS.md # Role definition │ │ ├── SOUL.md # Personality & values │ │ ├── TOOLS.md # Available tools │ │ ├── USER.md # User profile │ │ └── HEARTBEAT.md # Periodic tasks │ ├── 日志说明.md │ ├── 测试情况.md │ └── 编程规范.md ├── LICENSE ├── README.md ├── README.zh.md └── CMakeLists.txt ``` ### Execution Flow ``` User Input (CLI/Gateway) ↓ AgentLoop.run() ↓ ContextBuilder.build() → System Prompt + Messages ↓ LLM Provider.complete() ↓ Has tool_calls? ├─ Yes → Execute tools → Write results → Repeat └─ No → Return response → Save to memory ``` ## System Context Diagram (C4 Level 1 — Context) **Answer**: Who uses this system and which external systems does it interact with? ``` flowchart TB subgraph actors["People"] U(["End User"]) end subgraph sys["Software System: cppClaw AI Assistant"] direction TB S["Automated conversations, tool calls &\nworkspace memory (C++)"] end subgraph ext["External Dependencies"] OLL["Ollama\n(Local/LAN LLM)"] OAI["OpenAI Compatible API\n(Optional Cloud)"] MMX["MiniMax API\n(Optional Cloud)"] end subgraph fs["User Environment"] WS[("Workspace Directory\nSOUL.md / session / memory / …")] CFG[("Configuration File\nconfig.json")] SKILLS[("skills/ Directory\n(SKILL.md Index)")] end U -->|"Interactive / -m single turn"| S S -->|"HTTPS/HTTP\nchat / complete"| OLL S -->|"HTTPS\nchat/completions"| OAI S -->|"HTTPS\nchat/completions"| MMX S <-->|"Read/Write"| WS S <-->|"Load"| CFG S <-->|"Read skill index"| SKILLS ``` **Notes**: - The actual **LLM provider** is determined by configuration, supporting **Ollama** (local), **OpenAI** or **MiniMax** (cloud), switchable. - **Workspace** and **configuration** are on disk; session history is stored in `session/history.json` under the workspace (see Phase 5 documentation). - The **skills/** directory contains installed skill packages, each with a `SKILL.md` definition file. --- ## Container Diagram (C4 Level 2 — Containers) **Answer**: What are the runnable/deployable blocks and how do they connect? ``` flowchart LR U(["User"]) subgraph deploy["Local Processes"] CLI["cppclaw_cli\n(init / status / agent)"] GW["cppclaw_gateway\n(CLI channel + Agent)"] end subgraph lib["Shared Library Logic\n(libcppclaw_common)"] APP["agent_session\n(resolve workspace,\nagent_run_turn)"] CORE["AgentLoop\nContextBuilder\nMemoryStore"] LLM["ProviderRegistry\nOllama / OpenAI / MiniMax"] TOOL["ToolManager\nfile / shell / web_search"] SKILLS["SkillsLoader\n(skills/*/SKILL.md)"] end OLL["Ollama :11434"] OAI["OpenAI API"] MMX["MiniMax API"] DISK[("Disk: workspace + config")] SKDISK[("skills/ Directory\n(SKILL.md Index)")] U --> CLI U --> GW CLI --> APP GW --> APP APP --> CORE APP --> LLM APP --> TOOL APP --> SKILLS CORE --> LLM CORE --> TOOL CORE --> SKILLS LLM --> OLL LLM --> OAI LLM --> MMX CORE --> DISK APP --> DISK SKILLS --> SKDISK ``` **Notes**: - **CLI** and **Gateway** are two **entry point processes**; core logic resides in **`cppclaw_common`** (including `agent_session`, `AgentLoop`, LLM, tools, etc.). - **Gateway** currently uses **CLIChannel** for stdin/stdout; HTTP and other channels can be extended later (see `planning.md`). - **EventBus** is used within Gateway to demonstrate inbound/outbound queues; it runs parallel to the Agent call chain. - **SkillsLoader**: loads `skills/*/SKILL.md` indexes and injects skill summaries into the system prompt via `ContextBuilder`. - **LLM Providers**: adds **MiniMax** provider (alongside Ollama/OpenAI), managed through ProviderRegistry. --- ## 🎯 Quick Start ### Prerequisites | Requirement | Version | Notes | |-------------|---------|-------| | **CMake** | ≥ 3.22 | Build system | | **Compiler** | C++23 capable | GCC 13+, Clang 16+, MSVC 2022+ | | **OpenSSL** | Optional | For HTTPS support (recommended) | ### Build from Source ```bash # Clone repository git clone https://gitee.com/judeli/cppclaw.git cd cppclaw # Configure cmake -S . -B build -DCMAKE_BUILD_TYPE=Release # Build cmake --build build --target cppclaw_cli cppclaw_gateway # Outputs located in build/bin/ ``` --- ## 📦 Installation ### Pre-built Binaries (Coming Soon) Download from [Releases](https://github.com/your-org/cppclaw/releases) page. Extract the installation package to a specified directory (e.g., /opt/cppclaw) ```bash unzip cppclaw-linux-x64.zip -d /opt/cppclaw ``` Extracted installation root directory structure: ``` cppclaw/ ├── bin/ │ ├── cppclaw_cli │ └── cppclaw_gateway ├── skills/ │ ├── create-agent-skills/ │ ├── weather/ │ └── ... └── config/ ├── default.json └── ... ``` ### First Run ```bash # Initialize workspace (~/.cppclaw/) ./build/bin/cppclaw_cli init # Edit configuration vim ~/.cppclaw/config.json # Test with a simple query ./build/bin/cppclaw_cli agent -m "Hello! What can you do?" ``` --- ## ⚙️ Configuration ### Config Location Default: `~/.cppclaw/config.json` ### Basic Setup ```json { "agent": { "name": "钢铁龙虾", "profession": "AI 助手", "system_prompt": "", "max_iterations": 10, "working_directory": "~/.cppclaw/workspace" }, "llm": { "provider": "ollama", "model": "qwen3.5:4b", "base_url": "http://localhost:11434/v1", "api_key": "", "max_tokens": 4096, "temperature": 0.7 }, "tools": { "shell_enabled": true, "file_enabled": true, "web_search_enabled": true, "skill_hub_enabled": true, "clawhub_api_base": "https://wry-manatee-359.convex.site" } } ``` ### Supported LLM Providers | Provider | Model Format | Get API Key | |----------|--------------|-------------| | **Ollama** | `ollama/{model}` | Local (no key) | | **OpenAI** | `openai/{model}` | [platform.openai.com](https://platform.openai.com) | | **Kimi** | `kimi/{model}` | [platform.moonshot.cn](https://platform.moonshot.cn) | | **MiniMax** | `minimax/{model}` | [platform.minimaxi.com](https://platform.minimaxi.com) | | **Qwen (千问)** | `qwen/{model}` | [dashscope.console.aliyun.com](https://dashscope.console.aliyun.com) | | **Doubao (豆包)** | `doubao/{model}` | [www.volcengine.com](https://www.volcengine.com) | | **DeepSeek** | `deepseek/{model}` | [platform.deepseek.com](https://platform.deepseek.com) | | **Zhipu** | `zhipu/{model}` | [bigmodel.cn](https://bigmodel.cn) | | **Anthropic** | `anthropic/{model}` | [console.anthropic.com](https://console.anthropic.com) | ### Workspace Structure ``` ~/.cppclaw/workspace/ ├── sessions/ # Conversation history ├── memory/ │ ├── MEMORY.md # Long-term facts │ └── YYYY-MM-DD.md # Daily notes ├── skills/ # Custom skills ├── AGENTS.md # Agent guidelines ├── SOUL.md # Personality & values ├── USER.md # User preferences └── TOOLS.md # Tool documentation ``` --- ## 💬 Usage ### CLI Mode ```bash # One-shot query ./cppclaw_cli agent -m "List files in current directory" # Interactive mode ./cppclaw_cli agent # Specify custom workspace ./cppclaw_cli agent -w /path/to/workspace -m "Help me with..." ``` ### Gateway Mode (Chat Platforms) ```bash # Start gateway for Telegram/Discord ./cppclaw_gateway # Configure channels in ~/.cppclaw/config.json ``` #### Example: Telegram Setup 1. Create bot via [@BotFather](https://t.me/BotFather) 2. Copy token to config: ```json { "channels": { "telegram": { "enabled": true, "token": "YOUR_BOT_TOKEN", "allow_from": ["YOUR_USER_ID"] } } } ``` 3. Run gateway and chat with your bot! --- ## 🛠️ Tool System ### Built-in Tools | Tool | Operations | Description | |------|------------|-------------| | **file** | read/write/append/list/delete | Workspace-scoped file operations | | **shell** | execute | Command execution with safety filters | | **web_search** | search | Web search (requires API key) | | **skill_hub** | search/install/uninstall | ClawHub skill management | ### Security Sandbox By default, cppClaw runs in a sandboxed environment: - ✅ File access restricted to workspace - ✅ Dangerous commands blocked (`rm -rf`, `format`, etc.) - ✅ Timeout enforcement for long-running operations Disable restrictions (⚠️ security risk,not support now): ```json { "agent": { "restrict_to_workspace": false } } ``` --- ## 📚 Skills Pre-installed skills: | Skill | Description | |-------|-------------| | **github** | GitHub integration via `gh` CLI | | **weather** | Current weather & forecasts | | **summarize** | URL/file summarization | | **self-improving-agent** | Continuous learning from errors | | **create-agent-skills** | Guide for creating new skills | ### Using Skills Skills are auto-loaded from `skills/` directory. To use a skill: ```` User: "Check the weather in Beijing" → Agent loads: skills/weather/SKILL.md → Executes weather tool → Returns forecast ``` ### ClawHub (Planned) Future feature to install community skills.Currently, you can install it directly through the conversation; the command line method is not yet supported. ```bash # Search ClawHub cppclaw_cli skill search "code-review" # Install skill cppclaw_cli skill install code-review-assistant ``` --- ## 🤝 Contributing PRs welcome! The codebase is designed to be readable and extensible. ### How to Contribute 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Run tests 5. Submit a Pull Request ### Areas We Need Help - 🚀 Performance optimization (SIMD, async I/O) - 🌍 More channel integrations (Discord, QQ, WeCom) - 🧪 Test coverage expansion - 📚 Skill development for ClawHub - 🐛 Bug fixes and platform compatibility --- ## 🔒 Security ### Sandboxing - Workspace restriction enabled by default - Dangerous command patterns blocked - File access validation ### Reporting Vulnerabilities Please report security issues via GitHub Private Vulnerability Reporting (if enabled) or contact maintainers directly. --- ## 📄 License **MIT License** - See [LICENSE](LICENSE) for details. ### Third-Party Dependencies | Library | License | Purpose | |---------|---------|---------| | spdlog | MIT | Logging | | nlohmann/json | MIT | JSON handling | | httplib | BSD-3 | HTTP server/client | | cereal | BSD-3 | Serialization | --- ## 🙏 Acknowledgments - [nanobot](https://github.com/HKUDS/nanobot) - Original inspiration - [OpenClaw](https://github.com/openclaw/openclaw.git) - Architectural reference - [spdlog](https://github.com/gabime/spdlog) - Fast C++ logging - [nlohmann/json](https://github.com/nlohmann/json) - JSON for Modern C++ --- ## 📬 Contact - **GitHub Issues**: [Report bugs / Feature requests](https://github.com/your-org/cppclaw/issues) - **Discussions**: [Community forum](https://github.com/your-org/cppclaw/discussions) ---

🦞 cppClaw — Bringing AI Agents to C++!

Built with ❤️ using modern C++23