Claude Code
Claude Code 是 Anthropic 开发的一个强大的AI编程助手工具,它将Claude AI的智能直接集成到开发者的工作流程中,让AI编程变得更加自然和高效。
上面说的有些虚头巴脑,我想要推荐的是Claude Code构建AI Agent的能力,这也是我要写这系列文章的初衷。
Claude Code 是什么?
Claude Code 是一个命令行工具和IDE集成,它让开发者可以:
在终端中直接与Claude AI对话
让AI理解和修改你的代码库
通过自然语言描述来生成、修改和优化代码
获得基于上下文的智能编程建议
我的理解
我们都用过AI Code软件如:Cursor、Trae等,后来Google也发布了一个npm版本的gemini cli,qwen也有这样的一个cli,在后来Claude Code的cli也就是今天说的这个火了,大家都在推荐用Claude Code在生产项目上。
上面介绍的几点Claude Code能做什么,其实其他软件和cli都能做到,大家在IDE编辑器用的最多,你有的别人也有你能做的别人也有替代产品,用于生产的很多workflow或者Landgraf都是主力军。
那为啥还要介绍Claude Code?是因为Claude Code能以最简单的方式让我们构建一个AI Agent的能力。
大家想想我们本地用的IDE、CLI也只是在处理本机事务,IDE用于我们自己写代码,我们在工作上构建的AI Agent基本上都是用一些开发语言的能力或者平台如:MCP、Dify、LandFlow、LandGraf等,都是要写代码或者会工作流,都要写很多提示词,对开发者来讲尤其是我们刚开始入圈的开发者一直在探索很多做AI Agent的构建在工作中,都感觉好难好难,效果也难达到预期,要学的东西太多了。很多时候我们不得以先干起来再说,从而我们把很多工具、技术混着用。
Claude Code出来了以后它简化了我们构建AI Agent的能力,无需去写什么Python代码,画流程图。Claude Code提供了一种以md文档的描述方式来构建AI Agent,并且有Super Agent去调用Sub Agent的泛化能力。另外一个优点是它提供了命令行的执行方式,我们把md文档也就是Agent描述完毕后就等于Agent构建好了,命令行的方式我们可以在任何地方去运行它。所以Claude Code能代替其他的Agent工具,也是我目前推崇此AI工具的原因。
主要解决的问题
那Claude Code能解决我们什么问题?我想写很多很多示例,但是我觉得我写不下去,好像我们在IDE或Dify、Landgraf能做的它都能做(当然,你一定是有过一段时间要构建AI Agent的工作才能理解)。当你用Claude Code的时候,你会发现你不用去依赖其他的平台部署或者写一些软件代码,你仅仅通过md的描述语言来极简单的方式实现,这就是已经很能降低成本了,无论是学习还是其他资源成本都降低。
所以我们非常高兴的去学习它,并将它用在我们的生产环境工作,构建生产级的AI Agent。
安装与使用
前提条件
Node.js 18 或更新版本
Claude Code是用node基座建立的,这个对于现在AI圈来讲,已经是通用技术了,安装成本很低。
安装方式
# 安装1 Claude Code
npm install -g @anthropic-ai/claude-code
# 安装2 国内推荐通过阿里提供的npm镜像安装:
npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com
# 查看是否安装完毕
claude -v
1.0.92 (Claude Code)
# 导航到您的项目
cd your-awesome-project
# 开始使用 Claude 编程
claude
# 我执行这个命令的时候报了这个错
Unable to connect to Anthropic services
Failed to connect to api.anthropic.com: ERR_BAD_REQUEST
# 解决方式
对于MAC来讲在你的用户下有一个.claude的文件夹,和一个.claude.json的配置文件
在.claude.json中加一句即可,再执行claude就正常了
{
...,
"hasCompletedOnboarding": true
}
这个问题是中国区无法连接Anthropic的问题。
Hello World
# 安装完毕后我们得到一个cli的界面,如果之前玩过gemini cli的就不会陌生了
/help
# 按帮助看有哪些东西
Claude Code v1.0.92
Always review Claude's responses, especially when running code. Claude has read access to files in the current directory
and can run commands and edit files with your permission.
Usage Modes:
• REPL: claude (interactive session)
• Non-interactive: claude -p "question"
Run claude -h for all command line options
Common Tasks:
• Ask questions about your codebase > How does foo.py work?
• Edit files > Update bar.ts to...
• Fix errors > cargo build
• Run commands > /help
• Run bash commands > !ls
Interactive Mode Commands:
/add-dir - Add a new working directory
/agents - Manage agent configurations
/bashes - List and manage background bash shells
/bug - Submit feedback about Claude Code
/clear - Clear conversation history and free up context
/compact - Clear conversation history but keep a summary in context. Optional: /compact [instructions for
summarization]
/config - Open config panel
/context - Visualize current context usage as a colored grid
/cost - Show the total cost and duration of the current session
/doctor - Diagnose and verify your Claude Code installation and settings
/exit - Exit the REPL
/export - Export the current conversation to a file or clipboard
/help - Show help and available commands
/hooks - Manage hook configurations for tool events
/ide - Manage IDE integrations and show status
/init - Initialize a new CLAUDE.md file with codebase documentation
/install-github-app - Set up Claude GitHub Actions for a repository
/login - Switch Anthropic accounts
/logout - Sign out from your Anthropic account
/mcp - Manage MCP servers
/memory - Edit Claude memory files
/migrate-installer - Migrate from global npm installation to local installation
/model - Set the AI model for Claude Code
/output-style - Set the output style directly or from a selection menu
/output-style:new - Create a custom output style
/permissions - Manage allow & deny tool permission rules
/pr-comments - Get comments from a GitHub pull request
/release-notes - View release notes
/resume - Resume a conversation
/review - Review a pull request
/security-review - Complete a security review of the pending changes on the current branch
/status - Show Claude Code status including version, model, account, API connectivity, and tool statuses
/statusline - Set up Claude Code's status line UI
/terminal-setup - Install Shift+Enter key binding for newlines
/upgrade - Upgrade to Max for higher rate limits and more Opus
/vim - Toggle between Vim and Normal editing modes
Learn more at: https://docs.anthropic.com/s/claude-code
Press Enter to continue…
交互模式命令介绍
基础操作命令
配置管理命令
账户和认证命令
项目和代码库管理
Agent和集成管理
开发和调试工具
GitHub集成命令
会话管理命令
使用建议
新手入门:从
/help
和/status
开始,了解基本状态项目配置:使用
/init
初始化项目,/add-dir
添加工作目录性能优化:定期使用
/compact
清理上下文,用/context
监控使用情况团队协作:利用
/review
和/security-review
进行代码审查故障排除:遇到问题时使用
/doctor
诊断,/bug
反馈问题
大模型设置和初始化项目
# 配置大模型,大模型支持很多种,有些用的是另外一个路由项目配置的,我这边是用Deepseek 3.1,它支持Anthropic的协议
export ANTHROPIC_API_KEY="sk-xxx"
export ANTHROPIC_MODEL="deepseek-v3.1"
export ANTHROPIC_BASE_URL="https://deepseek.xxx.com"
# 执行项目初始化,必须配置好大模型,否则init无法执行
/init
执行完毕后会得到一个主CLAUDE.md的Agent描述文件,这里就算结束。
总结
Claude Code 代表了AI辅助编程的新一代工具,它不仅能够生成代码,更重要的是能够理解项目的整体架构和业务逻辑。对于开发团队来说,它是一个强大的生产力倍增器。后续我将用Claude Code构建AI Agent的工作,用于生产实践给出我自己的应用案例。