agentleFS
imxcstarimxcstar/sharpclaw/CLAUDE.md

sharpclaw

CLAUDE.md25 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
  1. Distinctive:

    After each turn → MemorySaver analyzes and updates vector store

    line 113
  2. Distinctive:

    When context window overflows → Summarizer generates detailed summary → appends to recent memory

    line 114
  3. Distinctive:

    When recent memory > 30k chars → Consolidator extracts core info → overwrites primary memory

    line 115
  4. Very specific:

    All tools (built-in commands + external skills) are passed to MainAgent as a single collection

    line 142
  5. Distinctive:

    All sub-agents use tool calling (not text parsing) for structured output

    line 236
  6. Very specific:

    Context-Aware Execution: Use CommandDir/FindFiles when unfamiliar with project.

    line 242
  7. Very specific:

    Read Before Write: Always CommandCat before CommandEditText to get exact line numbers

    line 243
  8. Very specific:

    Evaluate Impact: Use SearchInFiles before modifying public APIs

    line 244
  9. Distinctive:

    Skill Introspection: Check available tools/skills before claiming capabilities.

    line 245
  10. Distinctive:

    Strict Verification: Check Git Diff after edits, fix immediately if wrong

    line 248
  11. Very specific:

    Test Status: No test project in main sharpclaw (sharc has 3,467 tests)

    line 255
  12. Distinctive:

    When working with this codebase:

    line 289

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

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:

  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)

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 mini

Architecture

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:

LayerFilePurposeWritten By
Working Memoryworking_memory.jsonCurrent conversation snapshot (JSON)MainAgent (each turn)
Recent Memoryrecent_memory.mdDetailed summaries (append-only)ConversationArchiver (Summarizer)
Primary Memoryprimary_memory.mdConsolidated core factsConversationArchiver (Consolidator)
Vector Storememories.dbSemantic embeddings + metadataVectorMemoryStore
Historyhistory/*.mdArchived full conversationsConversationArchiver

Memory Pipeline Flow:

  1. After each turn → MemorySaver analyzes and updates vector store
  2. When context window overflows → Summarizer generates detailed summary → appends to recent memory
  3. When recent memory > 30k chars → Consolidator extracts core info → overwrites primary memory

Memory Injection Mechanism:

  • Injected messages are identified via AdditionalProperties dictionary keys:
    • AutoMemoryKey (__auto_memories__) — Vector search results
    • AutoRecentMemoryKey (__auto_recent_memory__) — Recent memory content
    • AutoPrimaryMemoryKey (__auto_primary_memory__) — Primary memory content
    • AutoWorkingMemoryKey (__auto_working_memory__) — Working memory snapshot
  • Memory messages are replaced/updated each turn rather than accumulated
  • Turn-based message tracking via turnStartIndex separates 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:

  • AgentBootstrap scans the skills directory at startup and converts discovered skills into AITool[]
  • Skills are merged with built-in command tools into a unified CommandSkills array
  • All tools (built-in commands + external skills) are passed to MainAgent as 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 framework
  • Anthropic / GeminiDotnet.Extensions.AI — Multi-provider LLM support
  • AgentSkillsDotNet — External skills loading and tool generation
  • ToonSharp — Lua scripting support
  • Cronos — Cron expression scheduling
  • Terminal.Gui v2 (develop) — TUI framework
  • Luolan.QQBot — QQ Bot SDK
  • Microsoft.Data.Sqlite — SQLite for vector store
  • Sharc.Vector — Vector operations (project reference)

Sharc (Submodule)

  • Pure managed C# — zero external dependencies
  • Sharc — Core engine
  • Sharc.Crypto — AES-256-GCM encryption
  • Sharc.Graph — Cypher graph queries
  • Sharc.Vector — SIMD vector search
  • Sharc.Query — SQL pipeline
  • Sharc.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 examples

Conventions

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 AdditionalProperties dictionary keys for identification
  • Session persistence via working_memory.json, memories.db, tiered memory files

Agent Behavior (From MainAgent System Prompt)

  1. Context-Aware Execution: Use CommandDir/FindFiles when unfamiliar with project; skip if memory sufficient
  2. Read Before Write: Always CommandCat before CommandEditText to get exact line numbers
  3. Evaluate Impact: Use SearchInFiles before modifying public APIs
  4. Skill Introspection: Check available tools/skills before claiming capabilities; never fabricate unauthorized operations
  5. Goal Decomposition: Break complex tasks into subtasks, execute continuously
  6. Auto-Recovery: On failure, analyze stderr, retry 2-3 times before reporting
  7. 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 doesREADME.md, README_CN.md
Main agent logicsharpclaw/Agents/MainAgent.cs
Memory pipelinesharpclaw/Chat/MemoryPipelineChatReducer.cs
Available toolssharpclaw/Commands/*.cs
Configuration schemasharpclaw/Core/SharpclawConfig.cs
Bootstrap flowsharpclaw/Core/AgentBootstrap.cs
Sharc librarysharc/README.md, sharc/CLAUDE.md
Sharc architecturesharc/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 AgentRegistry and LedgerManager
  • Do not run full benchmark suites — always use small chunks (2-6 benchmarks)

For AI Assistants

When working with this codebase:

  1. Check memory first — Use SearchMemory/GetRecentMemories before exploring
  2. Respect workspace boundaries — All file operations stay within the session workspace
  3. Follow the agent protocol — Context-aware execution, read before write, evaluate impact
  4. Understand the dual nature — Sharpclaw is the agent framework, Sharc is the SQLite engine
  5. 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*'

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.