Claude Code 使用说明
这份文档基于 Anthropic 官方 Claude Code 文档整理。
它是什么
Claude Code是 Anthropic 的 agentic coding tool。- 它可以读代码、改文件、跑命令、接 MCP、用 skills / hooks / memory。
- 不只在终端里能用,也支持 VS Code、JetBrains、Desktop、Web、Slack、CI。
安装
npm install -g @anthropic-ai/claude-code
官方安装方式
官方推荐:原生安装脚本
macOS / Linux / WSL:
curl -fsSL <https://claude.ai/install.sh> | bash
Windows PowerShell:
irm <https://claude.ai/install.ps1> | iex
Windows CMD:
curl -fsSL <https://claude.ai/install.cmd> -o install.cmd && install.cmd && del install.cmd
原生安装的特点:
- 官方推荐
- 会自动后台更新
Homebrew
brew install --cask claude-code
brew upgrade claude-code
WinGet
winget install Anthropic.ClaudeCode
winget upgrade Anthropic.ClaudeCode
快速开始
启动
cd your-project
claude
首次登录时支持:
- Claude Pro / Max / Teams / Enterprise
- Claude Console
- Amazon Bedrock / Google Vertex AI / Microsoft Foundry
一次性执行
claude "fix the build error"
claude -p "explain this function"
恢复最近会话
claude -c
claude -r
Git
claude commit
官方文档里的典型能力
- 理解整个代码库
- 跨多个文件实现功能
- 修 bug
- 写测试
- 跑 lint / test
- 直接和 git 协作
- 通过 MCP 连接外部工具
- 用
CLAUDE.md、skills、hooks 做定制 - 运行多 agent 协作
常见自然语言任务
官方 quickstart 里给的典型例子包括:
what does this project do?what technologies does this project use?where is the main entry point?add a hello world function to the main filecommit my changes with a descriptive messagethere's a bug where users can submit empty forms - fix itwrite unit tests for the calculator functionsreview my changes and suggest improvements
常用命令
官方 quickstart 页明确列出的常用项:
claudeclaude "task"claude -p "query"claude -cclaude -rclaude commit/clear/helpexit
配置体系
Claude Code 的配置有 scope 概念。
作用域
ManagedUserProjectLocal
位置
| Scope | 主要位置 |
|---|---|
| User | ~/.claude/settings.json |
| Project | .claude/settings.json |
| Local | .claude/settings.local.json |
| MCP user/local | ~/.claude.json |
| MCP project | .mcp.json |
| 全局 memory | ~/.claude/CLAUDE.md |
| 项目 memory | CLAUDE.md 或 .claude/CLAUDE.md |
优先级
官方 settings 文档给出的优先级:
- Managed
- CLI arguments
- Local
- Project
- User
CLAUDE.md、Memory、Skills、Hooks
CLAUDE.md
CLAUDE.md 是 Claude Code 会在会话开始时读取的 Markdown 指令文件。
适合放:
- 代码规范
- 架构决策
- 常用命令
- review checklist
Skills
官方文档说明,团队可以把可复用工作流打包成 skills。
Hooks
hooks 可以在工具动作前后执行 shell 命令,例如:
- 编辑后自动格式化
- 提交前先跑 lint
- 拦截对敏感配置的写入
权限与工具
Claude Code 有比较完整的权限系统。
官方 settings 页列出的核心工具包括: