Learn Claude Code Rs 标志

Learn Claude Code Rs

社区
wulawulu

Build an AI agent harness in Rust, from a minimal loop to tools, subagents, memory, teams, worktrees, MCP, and typed tool routing.

发布者wulawulu
代码仓库learn-claude-code-rs
语言Rust
复刻数
27
星标数
139
可用工具
0
传输类型stdio
许可协议MIT
链接
  • 将工具接入 AI 工作流

    Learn Claude Code Rs 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 139 个 Star 和 27 个 Fork。

CI

learn-claude-code-rs

English | 中文

A progressive AI Agent Harness tutorial written in Rust.

This repository is a Rust-oriented learning path for building an agent harness. It starts with the smallest agent loop and gradually adds tools, planning, subagents, skills, context compaction, permissions, hooks, memory, multi-agent collaboration, worktree isolation, MCP/plugins, tool routing, and agent evaluation.

This project was inspired by shareAI-lab/learn-claude-code. Its chapter design, content organization, and some code ideas reference that project to a certain extent, then reimplement and adapt them for the Rust ecosystem. It is not a line-by-line copy or a simple port; it reorganizes the agent harness topic itself into a runnable Rust tutorial.

Each chapter is an independent runnable Rust crate. You can read them in order or jump directly into a topic to see how a harness capability is expressed through data structures, runtime loops, tool interfaces, and durable state.

Why This Repo

Most LLM examples stop at tool calling. This repo focuses on the runtime around the model:

  • tool dispatch
  • permissions
  • skills
  • memory
  • context compaction
  • subagents
  • background work
  • team protocols
  • worktree isolation
  • MCP plugins
  • typed tool routing
  • agent evaluation

Architecture

learn-claude-code-rs architecture

Audience

  • People who want to understand the internals of coding agents instead of only using existing products.
  • People who want to write AI agents, CLI tools, or automation tools in Rust.
  • Readers who already know LLM APIs and want to learn tool use, subagents, permissions, hooks, memory, and related engineering structures.
  • People interested in the infrastructure behind Claude Code, Codex, Devin, Cursor Agent, and similar coding agents.

Quick Start

Prepare Rust:

bash
rustup update
cargo --version

Configure the model API. The examples use an Anthropic-compatible SDK interface and read configuration from environment variables:

bash
cp .env.example .env

Edit .env:

bash
ANTHROPIC_API_KEY=your_api_key
ANTHROPIC_BASE_URL=your_anthropic_compatible_base_url
ANTHROPIC_MODEL=your_model_name

Run the first chapter:

bash
cargo run -p s01_agent_loop

Run the integrated version:

bash
cargo run -p sfull

Check the whole workspace:

bash
cargo check --workspace

Learning Path

Each chapter is an independent crate that can be run, read, and modified on its own. Reading in order is recommended because later chapters build on earlier structures.

ChapterDirectoryTopicDescription
01s01_agent_loopAgent LoopMinimal runnable agent with user input, model response, tool calling, and a basic bash tool. Docs: s01.en.md.
02s02_tool_useTool UseExtract tools into a trait and add read_file, write_file, and edit_file. Docs: s02.en.md.
03s03_todo_writeTodo PlanningAdd a todo tool so the agent can maintain a plan and execution state. Docs: s3.en.md.
04s04_subagentSubagentStart fresh-context subagents for delegated exploration or subtasks. Docs: s4.en.md.
05s05_skill_loadingSkill LoadingLoad skills from skills/ and inject skill content into context on demand. Docs: s05.en.md.
06s06_context_compactContext CompactCompact long context while preserving key state. Docs: s06.en.md.
07s07_permission_systemPermissionAdd permission modes and interactive confirmation for tool calls. Docs: s07.en.md.
08s08_hook_systemHook SystemAdd lifecycle hooks around tool execution and agent events. Docs: s08.en.md.
09s09_memory_systemMemoryAdd durable memory for preferences, facts, feedback, and references. Docs: s09.en.md.
10s10_system_promptSystem PromptManage system prompts through structured sections and templates. Docs: s10.en.md.
11s11_error_recoveryError RecoveryRecover from tool failures, model errors, transport errors, and truncation. Docs: s11.en.md.
12s12_task_systemTask SystemAdd structured task records with status, owner, and dependencies. Docs: s12.en.md.
13s13_background_tasksBackground TasksStart, query, and manage long-running background commands. Docs: s13.en.md.
14s14_cron_schedulerCron SchedulerSchedule future tasks and reinject them into the loop when due. Docs: s14.en.md.
15s15_agent_teamsAgent TeamsOrganize multiple agents into teams with roles, inboxes, and messages. Docs: s15.en.md.
16s16_team_protocolsTeam ProtocolsAdd durable request-response protocols for multi-agent collaboration. Docs: s16.en.md.
17s17_autonomous_agentsAutonomous AgentsImplement long-running workers with idle polling and task claiming. Docs: s17.en.md.
18s18_worktree_task_isolationWorktree IsolationUse git worktrees to isolate task execution environments. Docs: s18.en.md.
19s19_mcp_pluginMCP PluginConnect MCP/plugin tools to the same permission and tool-result loop. Docs: s19.en.md.
20s20_tool_refactorTool RefactorRefactor tool registration, routing, dispatch, and macro support. Docs: s20.en.md.
21s21_agent_evaluationAgent EvaluationAdd eval cases, repeatable environments, observable trajectories, deterministic assertions, and LLM-as-a-Judge to the simple s20 agent. Docs: s21.en.md.
FullsfullComplete VersionIntegrate previous chapters into one complete agent harness. Docs: sfull.en.md.

Recommended Reading Order

  1. Run s01_agent_loop and understand the minimal loop: user input, model response, tool call, and tool result.
  2. Read s02_tool_use through s04_subagent to understand tools, planning, and delegation.
  3. Read s05_skill_loading through s08_hook_system to see how a demo becomes an extensible system.
  4. Read s09_memory_system through s14_cron_scheduler to understand state, long-running work, and scheduling.
  5. Read s15_agent_teams through s20_tool_refactor to understand multi-agent collaboration, isolated execution, plugins, and tool routing.
  6. Read s21_agent_evaluation to understand how to determine whether an agent actually completed its task.
  7. Read sfull last to see how the pieces fit together.

Project Structure

text
.
├── Cargo.toml
├── CONTRIBUTING.md
├── s01_agent_loop/
├── s02_tool_use/
├── s03_todo_write/
├── s04_subagent/
├── s05_skill_loading/
├── s06_context_compact/
├── s07_permission_system/
├── s08_hook_system/
├── s09_memory_system/
├── s10_system_prompt/
├── s11_error_recovery/
├── s12_task_system/
├── s13_background_tasks/
├── s14_cron_scheduler/
├── s15_agent_teams/
├── s16_team_protocols/
├── s17_autonomous_agents/
├── s18_worktree_task_isolation/
├── s19_mcp_plugin/
├── s20_tool_refactor/
├── s20_tool_refactor_macros/
├── s21_agent_evaluation/
├── sfull/
└── skills/

Common Commands

Run a chapter:

bash
cargo run -p s03_todo_write

Run the full version:

bash
cargo run -p sfull

Check:

bash
cargo check --workspace

Test:

bash
cargo test --workspace

Format:

bash
cargo fmt --all

Acknowledgements

Some Rust engineering ideas in this project were inspired by bosun-ai/swiftide, especially around hooks and system prompts.

Contributing

Contributions are welcome from people interested in Rust, AI agents, tool use, MCP, and coding agents.

Please read CONTRIBUTING.md before opening an issue or pull request.

Useful contribution areas:

  • Fix unclear or outdated docs.
  • Add explanations, diagrams, or examples.
  • Improve code structure and error handling.
  • Add tests.
  • Connect more models, tools, or MCP servers.
  • Translate docs.

License

This project is licensed under the MIT License.

Please preserve the license information when using, modifying, or distributing this project.

将 Learn Claude Code Rs MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Learn Claude Code Rs 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 Learn Claude Code Rs 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Learn Claude Code Rs MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "learn-claude-code-rs": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Learn Claude Code Rs MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Learn Claude Code Rs MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Learn Claude Code Rs 帮我完成这项任务吗?
Learn Claude Code Rs
当然。我已阅读。
以下是我使用 Learn Claude Code Rs 得到的结果。

常见问题

Learn Claude Code Rs MCP 服务器有什么用途?

Learn Claude Code Rs 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Learn Claude Code Rs MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 Learn Claude Code Rs,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 Learn Claude Code Rs MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 Learn Claude Code Rs 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Learn Claude Code Rs MCP 连接到 TypingMind?

Learn Claude Code Rs 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Learn Claude Code Rs MCP 在 TypingMind 中提供哪些工具?

Learn Claude Code Rs 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Learn Claude Code Rs MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 Learn Claude Code Rs 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇