| Crates.io | claude-autonomous |
| lib.rs | claude-autonomous |
| version | 1.0.16 |
| created_at | 2025-12-30 17:23:11.593742+00 |
| updated_at | 2026-01-06 08:36:34.11683+00 |
| description | Claude Autonomous Engineering CLI - Complete Rust implementation |
| homepage | |
| repository | https://github.com/hewenyu/claude-autonomous-engineer |
| max_upload_size | |
| id | 2013055 |
| size | 564,906 |
让 Claude Code 真正实现自主工程 - 纯 Rust 实现,单一二进制
这是一个完整的 Claude Code 自主工程系统,将所有 hooks 和 agents 打包进单一的 Rust 二进制文件(~8MB,包含 5 种语言的 tree-sitter 支持)。通过智能的上下文注入、自动进度同步和代码审查,让 Claude 能够真正自主地完成复杂的工程任务。
你: "帮我实现用户认证系统"
Claude: [写了一些代码]
Claude: "完成了!"
你: "还有很多功能没做啊..."
Claude: "抱歉,我忘记了之前的计划" ❌
你: "帮我实现用户认证系统"
[系统自动注入上下文]
Claude: "我会先设计架构并生成任务列表..."
[生成 ROADMAP.md - 20个任务]
[生成 API 契约]
Claude: "现在开始 TASK-001: 实现用户注册..."
[写代码 → 写测试 → 自动审查 → 提交]
✓ TASK-001 完成
Claude: "继续 TASK-002: 实现登录功能..."
[自动继续下一个任务]
✓ TASK-002 完成
... [持续执行,直到所有任务完成] ✓
每次交互前自动注入:
修改 Markdown 文件时自动更新状态:
你修改: ROADMAP.md
- [x] TASK-001: 用户注册 ← 标记为完成
系统自动: memory.json 更新
{
"current_task": "TASK-002",
"progress": { "tasks_completed": 1 }
}
git commit -m "实现用户注册"
[系统自动触发审查]
→ 智能查找 codex 命令(支持 nvm、project-local)
→ 检查是否符合 API 契约
→ 检查是否有测试
→ 检查代码质量
✓ 审查通过 → 允许提交
✗ 审查失败 → 阻止提交 + 反馈问题
Codex 路径智能解析:系统会自动在以下位置查找 codex 命令:
CLAUDE_AUTONOMOUS_CODEX_BIN(最高优先级)~/.nvm/versions/node/*/bin/codex(自动选择最新版本)./node_modules/.bin/codexClaude: "这个任务完成了"
[loop_driver hook 自动检查]
→ ROADMAP 还有 pending 任务吗?
- 有 → "继续下一个任务"
- 没有 → "所有任务完成!"
使用 Tree-sitter 提取代码结构,显著减少 token 消耗:
支持语言:Rust, Python, Go, TypeScript, JavaScript
提取内容:函数签名、类定义、接口、类型等
示例输出 (TOON 格式):
path: example.py
symbols[3]:
Struct,User,"class User:"
Function,__init__,"def __init__(self, name: str):"
Function,greet,"async def greet(self) -> str:"
优势:
✅ 节省 30-60% tokens
✅ BLAKE3 缓存 - 只解析修改的文件
✅ 并行处理 - Rayon 多线程加速
✅ 降低"接口幻觉"风险
智能 Codex 路径解析
不再依赖环境变量!系统现在会自动在多个位置智能搜索 codex 命令:
~/.nvm/versions/node/*/bin/codex,选择最新版本./node_modules/.bin/codex(向上 5 层)--version 验证技术实现:
src/hooks/codex_resolver.rs 模块(~300 行)std::sync::OnceLock 实现线程安全缓存anyhow、dirs、std::process用户体验提升:
Repository Map 多语言支持
新增对 Python、Go、TypeScript/TSX、JavaScript/JSX 的完整支持!
现在 claude-autonomous map 命令可以提取以下语言的代码骨架:
技术实现:
测试验证:在 /tmp/multi-lang-test 中测试了所有语言,成功提取 20 个符号!
修复 loop_driver 误判空 ROADMAP 为"已完成"的问题
在之前的版本中,当 ROADMAP 存在但为空(total=0,即还未生成任务)时,loop_driver hook 会误判为"所有任务已完成",导致在规划阶段就触发 Stop 事件,阻止继续工作。
修复内容:
total == 0,再检查 complete影响:
这个修复确保了 project-architect-supervisor 能够正常完成任务规划阶段,不会被提前中断。
cargo install claude-autonomous
wget https://github.com/hewenyu/claude-autonomous-engineer/releases/latest/download/claude-autonomous_1.0.13_amd64.deb
sudo dpkg -i claude-autonomous_1.0.13_amd64.deb
wget https://github.com/hewenyu/claude-autonomous-engineer/releases/latest/download/claude-autonomous-1.0.13-1.x86_64.rpm
sudo rpm -i claude-autonomous-1.0.13-1.x86_64.rpm
claude-autonomous --version
# claude-autonomous 1.0.13
在你的项目根目录运行:
cd my-project
claude-autonomous init --name "My Awesome Project"
这会创建完整的目录结构:
my-project/
└── .claude/
├── settings.json # Hook 配置
├── agents/ # 5 个 agent 定义
│ ├── project-architect-supervisor.md
│ ├── code-executor.md
│ ├── codex-reviewer.md
│ ├── prd-generator.md
│ └── visual-designer.md
├── status/ # 状态管理(唯一真相来源)
│ ├── memory.json # 当前状态
│ ├── ROADMAP.md # 任务清单(需手动创建或让 Claude 生成)
│ ├── api_contract.yaml # API 契约
│ ├── error_history.json # 错误历史
│ └── decisions.log # 决策日志
└── phases/ # 阶段详细计划
现在打开 Claude Code 并开始一个复杂任务:
你: "帮我实现一个完整的用户认证系统,包括注册、登录、密码重置、
JWT token 管理、权限控制"
Claude 会:
设计架构(通过 project-architect-supervisor agent)
ROADMAP.md - 包含 15-20 个详细任务api_contract.yaml - 定义所有函数签名开始执行(通过 code-executor agent)
自动审查(通过 codex-reviewer agent)
持续执行直到完成
随时查看当前状态:
claude-autonomous status
输出:
╔══════════════════════════════════════════════════════════════════╗
║ Claude Autonomous Engineering Status ║
╚══════════════════════════════════════════════════════════════════╝
📁 Project Root: /home/user/my-project
🧠 Current State:
Project: My Awesome Project
Task: TASK-005
Status: in_progress
Retries: 0/5
📋 Progress:
✓ Completed: 4
▶ In Progress: 1
○ Pending: 10
! Blocked: 0
Total: 15 (26.7%)
📍 Current Phase: Phase 1 - Core Authentication
Repository Map 会用 Tree-sitter 提取代码结构骨架(函数/结构体/impl 等),在上下文注入时显著减少 token 消耗,并降低"接口幻觉"风险。
支持的编程语言:
# 默认输出(推荐):.claude/repo_map/structure.toon
claude-autonomous map
# 输出 Markdown(更适合人读,但更长)
claude-autonomous map --format markdown
# 指定输出路径
claude-autonomous map --output .claude/repo_map/structure.md --format markdown
特性:
说明:
inject_state 会优先读取 .claude/repo_map/structure.toon,不存在时再读取 .claude/repo_map/structure.md。.claude/repo_map/ 默认已加入 .gitignore(建议不要提交生成物)。状态机用于把“长周期开发阶段”显式化(planning/coding/testing/reviewing/completed/blocked),并提供历史查询与回滚。
# 查看当前状态
claude-autonomous state current
# 手动创建一次状态转换(会写入 .claude/status/state.json,并创建一条 git commit + tag)
claude-autonomous state transition planning --task-id TASK-001
# 列出/可视化状态历史
claude-autonomous state list
claude-autonomous state graph --task-id TASK-001
# 回滚到某个历史 tag(仅回滚 .claude/status/state.json)
claude-autonomous state rollback state-20251231-120000-planning-TASK-001
注意:
.claude/status/state.json 存在时,inject_state 才会注入状态机上下文,loop_driver 才会尝试自动状态转换。# 在 Claude Code 中
你: "我想添加一个完整的博客系统,包括文章 CRUD、评论、
标签、分类、搜索功能"
Claude: "我会先规划架构..."
[自动生成 ROADMAP.md - 30 个任务]
Claude: "开始 TASK-001: 设计数据库模型..."
[TDD 方式实现]
[自动审查]
[提交]
Claude: "TASK-001 完成,继续 TASK-002..."
[持续执行...]
你: "重构现有的认证系统,改为使用 JWT 并添加刷新 token 机制"
Claude: "分析现有代码..."
[读取当前实现]
[生成重构计划]
Claude: "TASK-001: 添加 JWT 依赖和配置..."
Claude: "TASK-002: 实现 token 生成器..."
Claude: "TASK-003: 添加刷新 token 端点..."
[逐步完成所有任务]
你: "用户报告登录时密码错误没有正确提示,帮我修复并添加完整测试"
Claude: "复现问题..."
[分析代码]
Claude: "TASK-001: 修复密码验证错误处理..."
Claude: "TASK-002: 添加错误场景测试..."
Claude: "TASK-003: 添加集成测试..."
[完成所有相关工作]
| 命令 | 说明 | 示例 |
|---|---|---|
init |
初始化项目 | claude-autonomous init |
init --name <name> |
指定项目名称 | claude-autonomous init --name "My API" |
init --force |
强制覆盖已有配置 | claude-autonomous init --force |
| 命令 | 说明 | 输出 |
|---|---|---|
status |
显示项目状态和进度 | 当前任务、完成度、阻塞项 |
agents |
列出所有嵌入的 agents | 5 个 agent 名称列表 |
root |
显示项目根目录路径 | /path/to/project |
doctor |
诊断环境和配置 | 检查文件完整性、配置正确性 |
| 命令 | 触发时机 | 作用 |
|---|---|---|
hook claude_protocol |
SessionStart | 注入 CLAUDE.md 静态规范(自主工程协议) |
hook inject_state |
UserPromptSubmit | 注入上下文到 Claude |
hook progress_sync |
PostToolUse (Write/Edit) | 同步 Markdown 进度到 memory.json |
hook codex_review_gate |
PreToolUse (Bash - git commit) | Git commit 前审查代码 |
hook error_tracker |
PostToolUse (Bash) | 记录失败命令到 error_history.json,并递增 retry_count |
hook loop_driver |
Stop | 检查是否还有任务,决定是否继续 |
注意:Claude Code 会校验 hook 命令 stdout 的 JSON schema。
对于只做“副作用”的 hook(如progress_sync/error_tracker),建议返回最小 no-op 结构,避免出现Hook JSON output validation failed:{"hookSpecificOutput":{"for PostToolUse":{"hookEventName":"PostToolUse"}}}
┌─────────────────────────────────────────────────────────────────┐
│ Claude Code Session │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Session Start → [claude_protocol] → 注入 CLAUDE.md 静态规范 │
│ ↓ │
│ 注入 Autonomous Engineering Protocol: │
│ • Prime Directives (优先级规则) │
│ • Agent Swarm Protocol (Agent 协调) │
│ • The Loop (自主循环流程) │
│ • Anti-Patterns (禁止行为) │
│ │
│ User Prompt → [inject_state] → Claude (with full context) │
│ ↓ │
│ 读取并注入: │
│ • memory.json │
│ • ROADMAP.md (pending 任务) │
│ • TASK-xxx.md (当前任务规格) │
│ • api_contract.yaml │
│ • error_history.json │
│ │
│ Claude 输出 → [progress_sync] → 自动更新 memory.json │
│ ↓ │
│ 监听文件修改: │
│ • ROADMAP.md → 同步进度 │
│ • TASK-xxx.md → 同步当前任务 │
│ │
│ Bash 命令执行 → [error_tracker] → 记录失败命令 │
│ ↓ │
│ 失败时自动: │
│ • 记录到 error_history.json │
│ • 递增 retry_count │
│ • 供 Claude 参考避免重复 │
│ │
│ git commit → [codex_review_gate] → 审查 → PASS/FAIL │
│ ↓ │
│ 自动审查: │
│ • API 契约一致性 │
│ • 测试覆盖 │
│ • 代码质量 │
│ │
│ Stop → [loop_driver] → 检查 ROADMAP → CONTINUE/DONE │
│ ↓ │
│ 检查是否还有: │
│ • [ ] pending 任务 → 阻止停止 │
│ • 全部 [x] → 允许停止 │
│ │
└─────────────────────────────────────────────────────────────────┘
| 组件 | 语言 | 大小 | 作用 |
|---|---|---|---|
| CLI 主程序 | Rust | 2MB | 命令行入口、Hook 执行 |
| State Manager | Rust | - | 解析 ROADMAP、memory.json |
| Context Manager | Rust | - | 智能上下文管理(token 预算控制) |
| Repository Mapper | Rust | - | 多语言代码骨架提取(Tree-sitter) |
| Project Finder | Rust | - | Git-like 根目录查找(支持 submodule) |
| Templates | Embedded | - | 5 个 agents + CLAUDE.md 模板 |
| 特性 | 说明 |
|---|---|
| 极速启动 | < 50ms - 几乎零感知延迟 |
| 超小体积 | 2MB 单文件 - 所有功能全包含 |
| 零依赖 | 无需任何运行时或库 |
| 低内存 | < 20MB - 轻量高效 |
| 一键部署 | 单一二进制,复制即用 |
| 高性能 | Hook 执行 < 30ms - 极致优化 |
CLI 支持复杂的项目结构,包括 git submodule:
my-project/ ← 主项目
├── .claude/ ← 配置在这里
├── backend/
│ └── api/
└── submodules/
└── shared-lib/ ← git submodule
└── deep/path/
无论你在哪里执行命令,都能找到正确的 .claude 目录:
# 在主项目
cd my-project/
claude-autonomous root
# → /home/user/my-project
# 在 submodule 深层目录
cd my-project/submodules/shared-lib/deep/path/
claude-autonomous root
# → /home/user/my-project (正确找到父项目!)
查找顺序:
初始化后生成的 settings.json 非常简洁:
{
"hooks": {
"SessionStart": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": "claude-autonomous hook claude_protocol",
"timeout": 5
}]
}],
"UserPromptSubmit": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": "claude-autonomous hook inject_state",
"timeout": 5
}]
}],
"PostToolUse": [
{
"matcher": "Write|Edit|Create",
"hooks": [{
"type": "command",
"command": "claude-autonomous hook progress_sync",
"timeout": 5
}]
},
{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "claude-autonomous hook error_tracker",
"timeout": 5
}]
}
],
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "claude-autonomous hook codex_review_gate",
"timeout": 180
}]
}],
"Stop": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": "claude-autonomous hook loop_driver",
"timeout": 5
}]
}]
}
}
对比之前复杂的 bash 脚本(100+ 字符),现在只需要简单的命令调用。
职责: 架构设计和任务规划 输出:
ROADMAP.md - 完整任务列表api_contract.yaml - API 契约PHASE_PLAN.md - 阶段计划TASK-xxx.md - 任务规格触发词: "设计架构"、"规划项目"、"生成任务列表"
职责: TDD 方式实现代码 工作流:
TASK-xxx.md 需求api_contract.yaml 签名触发词: "实现"、"写代码"、"开发功能"
职责: 代码审查(Git commit 前自动触发) 检查项:
输出: PASS(允许提交)或 FAIL(阻止 + 反馈问题)
职责: 从需求生成 PRD 文档 触发词: "写 PRD"、"需求文档"
职责: UI/UX 设计建议 触发词: "设计界面"、"UI 设计"
A: 系统会自动智能查找 codex,无需手动配置!
自动查找顺序:
CLAUDE_AUTONOMOUS_CODEX_BIN(最高优先级)codex --version~/.nvm/versions/node/*/bin/codex(自动选择最新版本)./node_modules/.bin/codex(向上查找 5 层)手动配置(可选):
# 设置环境变量指定 codex 路径
export CLAUDE_AUTONOMOUS_CODEX_BIN=/path/to/codex
# 或添加到 shell 配置文件
echo 'export CLAUDE_AUTONOMOUS_CODEX_BIN=/home/user/.nvm/versions/node/v24.11.0/bin/codex' >> ~/.bashrc
错误排查: 如果系统找不到 codex,会显示详细的搜索位置和安装建议:
Codex command not found in any of the following locations:
1. Environment variable: CLAUDE_AUTONOMOUS_CODEX_BIN (not set)
2. System PATH (command 'codex' not found)
3. nvm directories: ~/.nvm/versions/node/*/bin/codex (not found)
4. Project-local: ./node_modules/.bin/codex (not found)
💡 Installation suggestions:
- Install via npm: npm install -g @anthropic-ai/codex
- Or set CLAUDE_AUTONOMOUS_CODEX_BIN to the full path
- Detected nvm at: ~/.nvm
Try: nvm use <version> && npm install -g @anthropic-ai/codex
A: loop_driver hook 会自动检查 ROADMAP。如果想手动停止:
# 在 ROADMAP.md 中标记所有任务为完成
- [x] TASK-001: ...
- [x] TASK-002: ...
或者删除/注释掉 Stop hook:
// 临时禁用 loop_driver
{
"hooks": {
"Stop": [] // 空数组 = 不执行
}
}
A: 系统会自动检测重试次数:
// memory.json
{
"current_task": {
"id": "TASK-005",
"retry_count": 3,
"max_retries": 5 // 超过 5 次会标记为 BLOCKED
}
}
手动干预:
# ROADMAP.md
- [!] TASK-005: 实现 OAuth (BLOCKED: 需要外部 API key) # 阻塞:会阻止整体完成
- [-] TASK-007: 集成第三方支付 (SKIPPED: 暂不做) # 跳过:不阻止整体完成
- [ ] TASK-006: 实现本地认证 # 继续下一个
A: 编辑 .claude/agents/*.md 文件:
# 修改 code-executor 的提示词
vim .claude/agents/code-executor.md
Agent 定义使用 Frontmatter + Markdown:
---
name: my-custom-agent
description: "Custom agent for special tasks"
model: sonnet
color: purple
---
# My Custom Agent
[你的提示词...]
A: 可以。创建一个模板项目:
# 创建模板
mkdir ~/claude-templates/
cd ~/claude-templates/
claude-autonomous init --name "Template"
# 自定义 agents 和 settings.json
# 在新项目中复制
cp -r ~/claude-templates/.claude ~/new-project/
cp ~/claude-templates/CLAUDE.md ~/new-project/
A: 系统本身是语言无关的 - agents 可以处理任何语言!
Repository Map (代码骨架提取) 目前支持:
其他语言 - Agents 可以处理任何语言:
💡 扩展提示: 添加新语言的 Repository Map 支持只需 ~300 行代码。 查看
src/repo_map/languages/了解实现模式,欢迎贡献 PR!
A: 完全兼容标准 Git 流程:
# 正常的 Git 操作
git checkout -b feature/new-auth
git add .
git commit -m "..." # codex_review_gate 会自动触发
git push
gh pr create
# 系统只是在 commit 前添加了审查
要禁用审查(CI/CD 环境):
# 环境变量禁用
SKIP_REVIEW=1 git commit -m "..."
A: 极快!
| Hook | 执行时间 |
|---|---|
| inject_state | < 50ms |
| progress_sync | < 20ms |
| codex_review_gate | < 30ms (不审查时) |
| loop_driver | < 10ms |
总开销: 每次交互约 50-100ms,几乎感觉不到。
编辑 .claude/settings.json 添加:
{
"context_budget": {
"max_roadmap_tasks": 20,
"max_error_history": 10,
"max_active_files": 5
}
}
手动添加错误记录(避免重复失败):
// .claude/status/error_history.json
[
{
"timestamp": "2024-01-01T10:00:00Z",
"task_id": "TASK-005",
"error": "OAuth provider not configured",
"attempted_solution": "Tried to use env vars",
"resolution": "BLOCKED - needs manual config"
}
]
记录重要的架构决策:
// .claude/status/decisions.log
2024-01-01 10:00 [TASK-003] Chose JWT over sessions (stateless, better scaling)
2024-01-01 11:30 [TASK-007] Use bcrypt for passwords (industry standard)
git clone https://github.com/hewenyu/claude-autonomous-engineer.git
cd claude-autonomous-engineer
# 开发模式运行
cargo run -- init
cargo run -- status
cargo run -- hook inject_state < test_input.json
# 运行测试
cargo test --all
# 发布构建
cargo build --release
src/
├── main.rs # CLI 入口
├── lib.rs # 库导出
├── cli/ # 命令行处理
├── hooks/ # 6 个 hook 实现 + codex 路径解析
│ ├── claude_protocol.rs # SessionStart - 注入协议
│ ├── inject_state.rs # UserPromptSubmit - 上下文注入
│ ├── progress_sync.rs # PostToolUse - 进度同步
│ ├── error_tracker.rs # PostToolUse - 错误追踪
│ ├── codex_review_gate.rs # PreToolUse - 代码审查门禁
│ ├── codex_resolver.rs # Codex 路径智能解析(支持 nvm)
│ ├── codex_executor.rs # Codex 命令执行器
│ ├── review_context.rs # 审查上下文构建
│ ├── review_parser.rs # 审查结果解析
│ ├── state_tracker.rs # 状态追踪
│ └── loop_driver.rs # Stop - 循环控制
├── state/ # 状态管理
│ ├── models.rs # Memory, Task 数据结构
│ ├── parser.rs # Markdown/YAML 解析
│ └── sync.rs # 进度同步逻辑
├── context/ # 上下文管理
│ ├── manager.rs # 上下文组装
│ └── truncate.rs # Token 预算控制
├── repo_map/ # Repository Mapping
│ ├── mod.rs # 核心逻辑
│ ├── extractor.rs # 语言提取器 trait
│ ├── parser.rs # Tree-sitter 解析器
│ ├── generator.rs # Markdown 输出
│ ├── generator_toon.rs # TOON 格式输出
│ ├── cache.rs # BLAKE3 缓存
│ └── languages/ # 语言特定提取器
│ ├── rust.rs # Rust 提取器
│ ├── python.rs # Python 提取器
│ ├── go.rs # Go 提取器
│ ├── typescript.rs # TypeScript/TSX 提取器
│ └── javascript.rs # JavaScript/JSX 提取器
├── project/ # 项目管理
│ ├── initializer.rs # init 命令
│ └── root_finder.rs # 根目录查找
├── state_machine/ # Git 状态机
│ ├── git_state.rs # Git 集成
│ └── workflow.rs # 状态转换
├── templates/ # 资源嵌入
│ ├── agents.rs # Agent 模板
│ └── files.rs # 配置模板
└── utils/ # 工具函数
├── git.rs
├── fs.rs
└── json.rs
embedded/ # 嵌入资源
├── agents/ # 5 个 agent 定义
└── templates/ # 模板文件
# 构建 DEB 包
cargo install cargo-deb
cargo deb
# 构建 RPM 包
cargo install cargo-rpm
cargo rpm build
# 发布到 crates.io
cargo publish
MIT License - 详见 LICENSE
开始自主工程之旅! 🚀
cargo install claude-autonomous
cd your-project
claude-autonomous init
# 然后在 Claude Code 中说: "帮我实现完整的用户系统"