sharpclaw
CLAUDE.md26 starsChanged 8 months agoMITView on GitHub
Sharpclaw is an advanced AI assistant framework built on .NET 10, featuring a robust cross-conversation long-term memory system and system-level operation capabilities. It serves as an autonomous AI agent that can explore, plan, and execute complex tasks in real codebases. The project consists of two main components: 1. Sharpclaw — The AI agent framework with multi-channel frontend support 2. Sharc — A high-performance, pure managed C# library for reading/writing SQLite files (submodule)
The file
We split this CLAUDE.md into the rules it gives an agent
12 rules. About 0 are common, 7 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 113
After each turn → MemorySaver analyzes and updates vector store
- Distinctive: line 114
When context window overflows → Summarizer generates detailed summary → appends to recent memory
- Distinctive: line 115
When recent memory > 30k chars → Consolidator extracts core info → overwrites primary memory
- Very specific: line 142
All tools (built-in commands + external skills) are passed to MainAgent as a single collection
- Distinctive: line 236
All sub-agents use tool calling (not text parsing) for structured output
- Very specific: line 242
Context-Aware Execution: Use CommandDir/FindFiles when unfamiliar with project.
- Very specific: line 243
Read Before Write: Always CommandCat before CommandEditText to get exact line numbers
- Very specific: line 244
Evaluate Impact: Use SearchInFiles before modifying public APIs
- Distinctive: line 245
Skill Introspection: Check available tools/skills before claiming capabilities.
- Distinctive: line 248
Strict Verification: Check Git Diff after edits, fix immediately if wrong
- Very specific: line 255
Test Status: No test project in main sharpclaw (sharc has 3,467 tests)
- Distinctive: line 289
When working with this codebase:
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Sharpclaw is an advanced AI assistant framework built on .NET 10, featuring a robust cross-conversation long-term memory system and system-level operation capabilities. It serves as an autonomous AI agent that can explore, plan, and execute complex tasks in real codebases.
The project consists of two main components:
- Sharpclaw — The AI agent framework with multi-channel frontend support
- Sharc — A high-performance, pure managed C# library for reading/writing SQLite files (submodule)
Build & Run Commands
# Build everything (including sharc submodule)
dotnet build
# Run Sharpclaw (Web 宿主, 默认模式)
dotnet run --project sharpclaw # 启动 Web 宿主 (含 WebSocket + 可选 QQBot)
dotnet run --project sharpclaw web # 同上
dotnet run --project sharpclaw web --address 0.0.0.0 --port 8080
# CLI 客户端 (连接到 Web 宿主)
dotnet run --project sharpclaw cli # 连接到默认 localhost:5000
dotnet run --project sharpclaw cli --address 192.168.1.2 --port 8080
# TUI 模式 (本地独立运行)
dotnet run --project sharpclaw tui # TUI mode (Terminal.Gui)
dotnet run --project sharpclaw config # Re-run config dialog
dotnet run --project sharpclaw help # Show usage info
# Web 模式需要 config 已存在; CLI 需先启动 Web 宿主
# TUI 首次运行时自动弹出配置对话框Sharc Submodule Commands
# Build sharc only
dotnet build sharpclaw/sharc/Sharc.sln
# Run sharc tests
dotnet test sharpclaw/sharc/tests/Sharc.Tests
dotnet test sharpclaw/sharc/tests/Sharc.IntegrationTests
dotnet test sharpclaw/sharc # All tests
# Run sharc benchmarks (NEVER run full suite, use small chunks)
dotnet run -c Release --project sharpclaw/sharc/bench/Sharc.Comparisons -- --filter '*CoreBenchmarks*SequentialScan*'
dotnet run -c Release --project sharpclaw/sharc/bench/Sharc.Comparisons -- --tier miniArchitecture
Sharpclaw Architecture
┌─────────────────────────────────────────────────────────────┐
│ Web 宿主 (ASP.NET Core, 默认启动模式) │
│ ├── / → Web UI (index.html) │
│ ├── /ws → WebSocket 端点 (多客户端) │
│ │ ├── Web UI 浏览器客户端 │
│ │ └── CLI 终端客户端 (CliClient) │
│ └── QQBotHostedService (IHostedService, 可选) │
├─────────────────────────────────────────────────────────────┤
│ 独立模式 │
│ ├── Tui/ — Terminal.Gui v2 (本地运行, ChatWindow) │
│ └── Cli/ — CliClient (WebSocket 客户端, 连接到 Web 宿主) │
├─────────────────────────────────────────────────────────────┤
│ Agent Layer (Agents/) │
│ ├── MainAgent — Conversation loop, tool orchestration │
│ ├── MemorySaver — Autonomous memory management │
│ └── ConversationArchiver — Two-phase memory consolidation │
├─────────────────────────────────────────────────────────────┤
│ Memory Pipeline (Chat/, Memory/) │
│ ├── MemoryPipelineChatReducer — Context window management │
│ ├── VectorMemoryStore — Sharc + SQLite vector search │
│ └── InMemoryMemoryStore — Keyword-based fallback │
├─────────────────────────────────────────────────────────────┤
│ Command System (Commands/) │
│ ├── FileCommands — File operations (cat, edit, find, etc.) │
│ ├── ProcessCommands — Bash/PowerShell execution │
│ ├── HttpCommands — HTTP requests │
│ ├── TaskCommands — Background task management │
│ └── SystemCommands — System info, exit │
├─────────────────────────────────────────────────────────────┤
│ Core Infrastructure (Core/) │
│ ├── AgentBootstrap — Shared initialization │
│ ├── SharpclawConfig — Configuration with encryption │
│ ├── ClientFactory — LLM client creation │
│ ├── DataProtector/KeyStore — AES-256-GCM encryption │
│ └── TaskManager — Background process management │
└─────────────────────────────────────────────────────────────┘Multi-Tier Memory System
Sharpclaw implements a sophisticated three-layer memory pipeline:
| Layer | File | Purpose | Written By |
| Working Memory | working_memory.json | Current conversation snapshot (JSON) | MainAgent (each turn) |
| Recent Memory | recent_memory.md | Detailed summaries (append-only) | ConversationArchiver (Summarizer) |
| Primary Memory | primary_memory.md | Consolidated core facts | ConversationArchiver (Consolidator) |
| Vector Store | memories.db | Semantic embeddings + metadata | VectorMemoryStore |
| History | history/*.md | Archived full conversations | ConversationArchiver |
Memory Pipeline Flow:
- After each turn → MemorySaver analyzes and updates vector store
- When context window overflows → Summarizer generates detailed summary → appends to recent memory
- When recent memory > 30k chars → Consolidator extracts core info → overwrites primary memory
Memory Injection Mechanism:
- Injected messages are identified via
AdditionalPropertiesdictionary keys:AutoMemoryKey(__auto_memories__) — Vector search resultsAutoRecentMemoryKey(__auto_recent_memory__) — Recent memory contentAutoPrimaryMemoryKey(__auto_primary_memory__) — Primary memory contentAutoWorkingMemoryKey(__auto_working_memory__) — Working memory snapshot
- Memory messages are replaced/updated each turn rather than accumulated
- Turn-based message tracking via
turnStartIndexseparates current turn from full history
IChatIO Abstraction
The AI engine is decoupled from frontend through Abstractions/IChatIO.cs:
Channels/Tui/ChatWindow.cs— Terminal.Gui v2 interface (本地模式)Channels/Web/WebSocketChatIO.cs— WebSocket frontend (Web 宿主内)Channels/QQBot/QQBotChatIO.cs— QQ Bot interface (Web 宿主内托管服务)Channels/Cli/CliClient.cs— CLI WebSocket 客户端 (连接到 Web 宿主)
Web 宿主内的前端 (Web UI / QQBot) 通过 IChatIO 共享 MainAgent 逻辑。
CLI 通过 WebSocket 协议与 Web 宿主通信,不直接使用 IChatIO。
Skills System
External skills are loaded from ~/.sharpclaw/skills/ via AgentSkillsDotNet:
AgentBootstrapscans the skills directory at startup and converts discovered skills intoAITool[]- Skills are merged with built-in command tools into a unified
CommandSkillsarray - All tools (built-in commands + external skills) are passed to
MainAgentas a single collection - The skills directory is auto-created if it doesn't exist
Configuration
Configuration stored in ~/.sharpclaw/config.json (version 8):
{
"version": 8,
"default": { "provider": "anthropic", "endpoint": "", "apiKey": "...", "model": "claude-3-5-sonnet-20241022" },
"agents": {
"main": { "enabled": true, "provider": null, "model": null },
"recaller": { "enabled": true },
"saver": { "enabled": true },
"summarizer": { "enabled": true }
},
"memory": { "embeddingProvider": "openai", "embeddingModel": "text-embedding-3-small" },
"channels": { "tui": {}, "web": { "address": "127.0.0.1", "port": 5000 }, "qqBot": {} }
}- API keys encrypted at rest with AES-256-GCM
- Encryption key stored in OS credential manager (Windows/macOS/Linux)
- Per-agent overrides can specify different provider/model from default
- ExtraRequestBody supports custom fields (e.g.,
thinking,reasoning_split)
Key Dependencies
Sharpclaw
Microsoft.Agents.AI.OpenAI/Microsoft.Extensions.AI.OpenAI— AI agent frameworkAnthropic/GeminiDotnet.Extensions.AI— Multi-provider LLM supportAgentSkillsDotNet— External skills loading and tool generationToonSharp— Lua scripting supportCronos— Cron expression schedulingTerminal.Guiv2 (develop) — TUI frameworkLuolan.QQBot— QQ Bot SDKMicrosoft.Data.Sqlite— SQLite for vector storeSharc.Vector— Vector operations (project reference)
Sharc (Submodule)
- Pure managed C# — zero external dependencies
Sharc— Core engineSharc.Crypto— AES-256-GCM encryptionSharc.Graph— Cypher graph queriesSharc.Vector— SIMD vector searchSharc.Query— SQL pipelineSharc.Arc— Cross-arc distributed sync
Project Structure
sharpclaw/
├── CLAUDE.md ← You are here
├── README.md / README_CN.md ← User-facing documentation
├── sharpclaw.slnx ← Solution file
├── sharpclaw/ ← Main project
│ ├── Program.cs ← Entry point (web/cli/tui/config)
│ ├── sharpclaw.csproj ← Project file (net10.0)
│ ├── Abstractions/ ← IChatIO, IAppLogger interfaces
│ ├── Agents/ ← MainAgent, MemorySaver, ConversationArchiver
│ ├── Channels/ ← Web(宿主), Cli(WS客户端), Tui(本地), QQBot(托管服务)
│ ├── Chat/ ← MemoryPipelineChatReducer
│ ├── Clients/ ─ DashScopeRerankClient, ExtraFieldsPolicy
│ ├── Commands/ ← All tool implementations
│ ├── Core/ ← Config, Bootstrap, TaskManager
│ ├── Memory/ ← IMemoryStore, VectorMemoryStore
│ ├── UI/ ← ConfigDialog, AppLogger
│ └── wwwroot/ ← Web UI (index.html)
├── preview/ ← Screenshots (main.png, web.png, config.png)
└── sharc/ ← Submodule: high-performance SQLite library
├── README.md
├── Sharc.sln
├── src/ ← 9 project folders
├── tests/ ← 11 test projects (3,467 tests)
├── bench/ ← BenchmarkDotNet suites
├── docs/ ← Architecture & feature docs
├── PRC/ ← Design decisions & specs
└── samples/ ← Usage examplesConventions
Code Style
- Language: Chinese prompts and UI strings, English code identifiers
- Target framework:
.NET 10(net10.0) - All sub-agents use tool calling (not text parsing) for structured output
- Sub-agents access memory files via standard file command tools with prompt-level write restrictions
- Injected messages use
AdditionalPropertiesdictionary keys for identification - Session persistence via
working_memory.json,memories.db, tiered memory files
Agent Behavior (From MainAgent System Prompt)
- Context-Aware Execution: Use
CommandDir/FindFileswhen unfamiliar with project; skip if memory sufficient - Read Before Write: Always
CommandCatbeforeCommandEditTextto get exact line numbers - Evaluate Impact: Use
SearchInFilesbefore modifying public APIs - Skill Introspection: Check available tools/skills before claiming capabilities; never fabricate unauthorized operations
- Goal Decomposition: Break complex tasks into subtasks, execute continuously
- Auto-Recovery: On failure, analyze stderr, retry 2-3 times before reporting
- Strict Verification: Check Git Diff after edits, fix immediately if wrong
Current Status
- Target Framework: .NET 10 (
net10.0) - Test Status: No test project in main sharpclaw (sharc has 3,467 tests)
- Memory System: Vector store with semantic deduplication (cosine distance 0.15 threshold)
- Channels: Web (base host) + QQBot (embedded hosted service) + CLI (WS client) + TUI (local)
- Config Version: 8 (with auto-migration)
Key Files for Understanding
| To understand... | Read... |
| What Sharpclaw does | README.md, README_CN.md |
| Main agent logic | sharpclaw/Agents/MainAgent.cs |
| Memory pipeline | sharpclaw/Chat/MemoryPipelineChatReducer.cs |
| Available tools | sharpclaw/Commands/*.cs |
| Configuration schema | sharpclaw/Core/SharpclawConfig.cs |
| Bootstrap flow | sharpclaw/Core/AgentBootstrap.cs |
| Sharc library | sharc/README.md, sharc/CLAUDE.md |
| Sharc architecture | sharc/PRC/ArchitectureOverview.md |
What NOT To Do
- Do not add dependencies without explicit approval (zero external dependencies is a core value for sharc)
- Do not break the public API surface without updating all docs and tests
- Do not allocate in hot paths — use spans, stackalloc, ArrayPool (sharc convention)
- Do not bypass the Trust layer in sharc — all agent operations must go through
AgentRegistryandLedgerManager - Do not run full benchmark suites — always use small chunks (2-6 benchmarks)
For AI Assistants
When working with this codebase:
- Check memory first — Use
SearchMemory/GetRecentMemoriesbefore exploring - Respect workspace boundaries — All file operations stay within the session workspace
- Follow the agent protocol — Context-aware execution, read before write, evaluate impact
- Understand the dual nature — Sharpclaw is the agent framework, Sharc is the SQLite engine
- Use appropriate tools — File commands for exploration, Task commands for background processes
Quick Reference
# Build and run Web host (default)
dotnet build && dotnet run --project sharpclaw
# Run CLI client (connects to Web host)
dotnet run --project sharpclaw cli
# Run sharc tests
dotnet test sharpclaw/sharc
# Run specific benchmark chunk
dotnet run -c Release --project sharpclaw/sharc/bench/Sharc.Comparisons -- --filter '*CoreBenchmarks*'Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

