Coding Agent:Claude Code 深度剖析 + 开源生态¶
更新日期:2026-04-15
本文目标:深入理解 Claude Code 的完整内部架构(tool loop、subagents、hooks、skills、MCP、memory、permission、compaction),对比主流开源 Coding Agent(Cline/Roo Code/OpenHands/Aider/Continue/OpenCode/Codex CLI),能据此选型或自建。
十二、开源 Coding Agent 生态对比¶
12.1 主流开源 Agent 全景¶
12.2 Cline 深入¶
Cline(原 Claude Dev)是第一个火爆的 VS Code coding agent。核心特点:每一步都要批准。参考 Cline。 Cline 的核心机制: 1. Plan Mode: 分析 + 规划, 不改代码 2. Act Mode: 每一步操作都要用户点"Approve" - 每次文件编辑 - 每次 terminal 命令 - 每次浏览器操作
优点: 最高信任度, 适合初次使用 缺点: 频繁打断, 体验不如 Claude Code / Cursor
12.3 Roo Code (Cline Fork)¶
Roo 的定位: Cline + 多模式 + 高度可定制 多模式: - Architect: 只做架构设计 - Code: 实现 - Debug: 修 bug - Custom: 用户自定义 每个模式有独立 system prompt 和工具权限
12.4 OpenHands (原 OpenDevin)¶
OpenHands 是开源版 Devin,由 All-Hands AI 维护。最成熟的开源 autonomous agent。参考 OpenHands。
# OpenHands 核心抽象
class Agent:
def __init__(self, llm, sandbox, actions):
self.llm = llm # GPT/Claude/Llama 任意
self.sandbox = sandbox # Docker/Kubernetes
self.actions = actions # bash/read/write/browse/jupyter
def step(self):
observation = self.sandbox.observe()
prompt = self.build_prompt(observation, self.history)
action = self.llm.choose_action(prompt, self.actions)
result = action.execute(self.sandbox)
self.history.append((observation, action, result))
return result
# 区别于 Claude Code:
# + 完全开源, 可替换任何 LLM
# + Sandbox 隔离 (Docker)
# + 云端 SDK 可部署
# - Agentic loop 质量不如 Claude Code (因为 Claude 模型本身最优)
# - 配置复杂度高
12.5 Aider(CLI Pair Programming)¶
Aider 是最老牌的 CLI coding agent(41.6K stars)。Git-native 设计。参考 Aider。 Aider 的哲学: - 每次 AI 修改自动 git commit - 用户可以 git revert 任何 AI 改动 - 不做 agent loop (不自主, 每次人工触发)
优势: - 极简, 上手 5 分钟 - 所有改动有 git 审计 - 多模型支持 (GPT/Claude/Llama/local)
劣势: - 不是 autonomous agent - 没有 MCP, subagents, hooks 等高级功能
12.6 Continue.dev¶
IDE 原生(VS Code + JetBrains),开源免费。 Continue 的定位: - 替代 Cursor 的开源方案 - 支持本地 LLM (Ollama) - 企业部署(内网 LLM)
vs Cursor: - 不如 Cursor 打磨 - 但开源 + 隐私
12.7 OpenAI Codex CLI¶
OpenAI 官方 CLI 工具,对标 Claude Code。参考 Codex CLI GitHub。 特点: - 专为 GPT-5 / Codex 模型优化 - Agentic loop 类似 Claude Code - 但工具和 ergonomics 不如 Claude Code 成熟
相关: codex-mini (更轻量)
12.8 SWE-Agent(学术)¶
SWE-Agent 是 Princeton 的学术项目。专注 SWE-bench。核心创新:Agent-Computer Interface (ACI)——专为 Agent 设计的命令集,不是人类 shell。参考 SWE-Agent (Yang et al., NeurIPS 2024)。
十三、选型决策¶
flowchart LR
start{"使用场景"}
indiv["个人开发"]
team["团队 / 企业"]
research["学术 / 研究"]
indiv --> cc["Claude Code (CLI)"]
indiv --> cursor["Cursor / Cline"]
team --> oh["OpenHands<br/>(自托管)"]
team --> cont["Continue<br/>(IDE 插件)"]
research --> swe["SWE-Agent"]
research --> aider["Aider"]
start --> indiv
start --> team
start --> research
classDef stage fill:#fff,stroke:#cc785c,color:#1a1a1a;
class start,indiv,team,research,cc,cursor,oh,cont,swe,aider stage
| 维度 | Claude Code | Cursor | Cline / Roo | OpenHands | Aider |
|---|---|---|---|---|---|
| 形态 | CLI | IDE 分叉 | VS Code 插件 | Web + 容器 | CLI |
| 自主性 | 高 | 中 | 中 | 高 | 中 |
| 自托管 | 否 | 否 | 是 | 是 | 是 |
| 模型自由度 | Claude only | 多模型 | 多模型 | 多模型 | 多模型 |
| 适合 | 重度 agent | 日常编码 | IDE 内 review | 沙箱执行 | 成本敏感 |
13.1 推荐组合¶
个人开发者推荐栈:
- 主力: Claude Code (CLI) — 最强模型能力 + 成熟的 agent loop
- IDE 辅助: Cursor 或 Cline — 可视化、Tab 补全
-
后备: Aider — 成本敏感或离线场景 企业推荐栈:
-
OpenHands — 可自托管、SDK 扩展、沙箱隔离
-
- Continue — 员工 IDE
-
- 自建 MCP servers — 连接内部系统
-
- 审计 Hooks — 合规
十四、自建 Coding Agent 的核心要素¶
如果想自己实现一个 Claude Code 级的 agent,需要:
参考文献¶
-
[1] Claude Code Docs. Anthropic. 官方
-
[2] Claude Code Subagents. 文档
-
[3] Subagents in the Agent SDK. 文档
-
[4] Inside Claude Code Architecture. 博客
-
[5] How Claude Code Builds a System Prompt. 博客
-
[6] Understanding Claude Code Full Stack. 博客
-
[7] The Task Tool Architecture. 博客
-
[8] Tasks v2 Update. VentureBeat
-
[9] Claude Code Source Leak Analysis. 博客
-
[10] Piebald-AI/claude-code-system-prompts. GitHub
-
[11] Awesome Claude Code Subagents. GitHub
-
[12] Open-Source Coding Agents 2026. 文章
-
[13] 12 Coding Agents Defining the Future. Cline 博客
-
[14] OpenHands. 官网
-
[15] Cline. 官网
-
[16] Aider. 官网
-
[17] Continue.dev. 官网
-
[18] Yang et al. SWE-Agent. NeurIPS 2024. 论文
-
[19] Devin (Cognition). 介绍
-
[20] MCP Specification. 规范
↑ 上级 · H4. Coding Agent:Claude Code / Cursor / Devin / OpenClaw