深入解析克劳德代码:当代与未来AI智能体系统的设计空间
Dive into Claude Code: The Design Space of Today's and Future AI Agent Systems
April 14, 2026
作者: Jiacheng Liu, Xiaohan Zhao, Xinyi Shang, Zhiqiang Shen
cs.AI
摘要
克劳德代码(Claude Code)是一种代理式编程工具,能够代表用户执行Shell命令、编辑文件及调用外部服务。本研究通过分析其公开的TypeScript源代码,并与独立开源AI代理系统OpenClaw进行对比,系统阐述了其整体架构。OpenClaw作为多通道个人助理网关,从不同部署场景出发对诸多相同设计问题给出了差异化解决方案。我们提炼出驱动该架构的五大人本价值观、设计哲学与需求(人类决策权威、安全与防护、可靠执行、能力增强及情境适应性),并沿着十三条设计原则追溯至具体实现方案。该系统的核心是一个调用模型、运行工具并循环执行的简易while循环,但主要代码实现在循环外围的支撑系统中:包含七种模式与基于机器学习分类器的权限系统、五层压缩流水线的上下文管理机制、四种扩展机制(MCP、插件、技能与钩子)、具备工作树隔离的子代理委托机制,以及面向追加的会话存储。与OpenClaw的对比表明,当部署场景变化时,相同设计问题会催生不同的架构答案:从基于操作的安全分类转向边界级访问控制,从单一CLI循环演进为网关控制平面内的嵌入式运行时,从上下文窗口扩展发展为网关级能力注册。最后我们基于近期实证研究、架构实践与政策文献,为未来代理系统提出六个开放设计方向。
English
Claude Code is an agentic coding tool that can run shell commands, edit files, and call external services on behalf of the user. This study describes its comprehensive architecture by analyzing the publicly available TypeScript source code and further comparing it with OpenClaw, an independent open-source AI agent system that answers many of the same design questions from a different deployment context. Our analysis identifies five human values, philosophies, and needs that motivate the architecture (human decision authority, safety and security, reliable execution, capability amplification, and contextual adaptability) and traces them through thirteen design principles to specific implementation choices. The core of the system is a simple while-loop that calls the model, runs tools, and repeats. Most of the code, however, lives in the systems around this loop: a permission system with seven modes and an ML-based classifier, a five-layer compaction pipeline for context management, four extensibility mechanisms (MCP, plugins, skills, and hooks), a subagent delegation mechanism with worktree isolation, and append-oriented session storage. A comparison with OpenClaw, a multi-channel personal assistant gateway, shows that the same recurring design questions produce different architectural answers when the deployment context changes: from per-action safety classification to perimeter-level access control, from a single CLI loop to an embedded runtime within a gateway control plane, and from context-window extensions to gateway-wide capability registration. We finally identify six open design directions for future agent systems, grounded in recent empirical, architectural, and policy literature.