LuoLuoLuoLuo Wiki
Claude Code

安装配置

如何安装和配置 Claude Code

前提条件

  • macOS、Linux 或 Windows(WSL)
  • 一个 Anthropic API Key、Claude 订阅或企业账号
  • 如果使用 npm 安装路径,需要 Node.js 18+

安装

官方现在更推荐使用 native installer:

curl -fsSL https://claude.ai/install.sh | bash

安装完成后,重启终端或按安装提示刷新 shell,再运行:

claude

npm 安装(可选)

如果你的环境更适合 npm,也可以继续使用:

npm install -g @anthropic-ai/claude-code

不要混用多个安装来源。如果 native installer 和 npm 同时装过,先确认当前命令来自哪里:

which claude

首次启动会引导你登录 Anthropic 账号或输入 API Key。

登录方式

方式一:Claude 订阅(推荐)

如果你有 Claude Pro 或 Max 订阅,直接浏览器登录即可,无需 API Key。

claude
# 首次运行会弹出浏览器让你授权

方式二:API Key

export ANTHROPIC_API_KEY="sk-ant-xxxxx"
claude

你也可以把它写进 ~/.zshrc~/.bashrc 里。

验证安装

claude --version

看到版本号就说明安装成功了。

更新

使用 native installer 安装的版本,直接运行内置更新:

claude update

如果你明确使用 npm 安装,再用 npm 更新:

npm install -g @anthropic-ai/claude-code@latest

CLAUDE.md 配置文件

在项目根目录创建 CLAUDE.md 文件,可以告诉 Claude 关于你项目的重要信息:

# 项目说明
- 这是一个 Next.js 项目
- 使用 pnpm 作为包管理器
- 测试用 vitest 运行

# 规范
- 使用中文注释
- 组件放在 src/components/ 目录下

Claude 每次启动时都会自动读取这个文件。

On this page