I built a Rust learning project for implementing a Claude Code-style agent harness from scratch
⚓ Rust 📅 2026-04-28 👤 surdeus 👁️ 1Hi everyone,
I have been working on a Rust learning project called learn-claude-code-rs:
The goal is to build an AI agent harness in Rust progressively, starting from the smallest possible agent loop and then adding the runtime pieces that make coding agents more than just basic tool calling.
It is not a product or a full Claude Code clone. It is a runnable tutorial-style repo. Each chapter is an independent Rust crate, so you can run one chapter at a time and see how one capability is added to the harness.
Why I made it
Many LLM examples stop at tool calling:
-
define tools
-
send tool schemas to the model
-
execute tool calls
-
append tool results back to the conversation
That is useful, but coding agents need a lot more runtime structure around the model:
-
tool registration and dispatch
-
permission checks
-
context compaction
-
skills and on-demand knowledge loading
-
persistent memory
-
subagents
-
background tasks
-
task records
-
multi-agent teams
-
worktree-based task isolation
-
MCP/plugin integration
-
typed tool routing
I wanted to understand these pieces by implementing them in Rust, with explicit data structures and runnable examples.
The project was inspired by shareAI-lab/learn-claude-code, but it is not a line-by-line port. It reorganizes the ideas around Rust patterns such as traits, enums, async runtimes, durable state, and a multi-crate workspace.
Current chapters
The repo currently has 20 progressive chapters plus a full integrated version:
| Chapter | Topic |
| --- | --- |
| 01 | Agent Loop |
| 02 | Tool Use |
| 03 | Todo Planning |
| 04 | Subagent |
| 05 | Skill Loading |
| 06 | Context Compact |
| 07 | Permission System |
| 08 | Hook System |
| 09 | Memory System |
| 10 | System Prompt |
| 11 | Error Recovery |
| 12 | Task System |
| 13 | Background Tasks |
| 14 | Cron Scheduler |
| 15 | Agent Teams |
| 16 | Team Protocols |
| 17 | Autonomous Agents |
| 18 | Worktree Task Isolation |
| 19 | MCP Plugin |
| 20 | Tool Refactor |
| Full | Integrated version |
Each chapter has documentation, and the README is available in both English and Chinese.
Quick start
git clone https://github.com/wulawulu/learn-claude-code-rs
cd learn-claude-code-rs
cp .env.example .env
Configure:
ANTHROPIC_API_KEY=your_api_key
ANTHROPIC_BASE_URL=your_anthropic_compatible_base_url
Run the first chapter:
cargo run -p s01_agent_loop
Run the integrated version:
cargo run -p sfull
Check the workspace:
cargo check --workspace
Feedback wanted
I would appreciate feedback from Rust developers, especially on:
-
whether the chapter split makes sense
-
whether the Rust abstractions feel natural
-
places where traits/enums/state modeling could be improved
-
missing tests or edge cases
-
whether the docs explain the agent runtime pieces clearly enough
-
better ways to model MCP/plugin/tool routing in Rust
Repository:
Thanks for taking a look.
1 post - 1 participant
🏷️ Rust_feed