Home › Claude Code › 中文指南
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automationvs Cursorvs Codex & OpenCodeSubagentsHooksMCPEcosystemVS CodeOpenRouterRate limits中文指南
更新于 November 06, 2026

Claude Code 怎么用:从安装到日常使用

Claude Code 是 Anthropic 官方的命令行编程智能体:它会读取你的代码仓库、制定计划、修改文件、运行测试并提交改动。本文用中文把安装、命令、费用和常见问题讲清楚。

要点

  • 安装:npm install -g @anthropic-ai/claude-code(需要 Node.js 18+),或使用一键安装脚本。
  • 通过两个环境变量即可接入本网关:ANTHROPIC_BASE_URL 和 ANTHROPIC_API_KEY。
  • 按 token 计费,长会话每一轮都会重发全部上下文——所以要经常用 /compact。
  • 本站积分按 7.69231 倍面值充值($13 可得 $100 额度),也有 $0.80 起的不限量套餐。

分主题详细指南

  • 安装教程 — npm、一键脚本、Windows 安装与常见安装问题。
  • 怎么用 — 第一次会话、常用命令、换行与快捷键、计划模式。
  • 价格与免费使用 — 计费方式、订阅限制、注册流程、省钱方案。
  • 配置与代理 — 国内使用、API 地址、环境变量、配置排查。

Claude Code 是什么

它不是一个带代码按钮的聊天窗口,而是一个智能体循环:你描述目标,它检查仓库、给出计划、修改文件、运行命令、读取报错并迭代,做危险操作前会先征求许可。它以 npm 包(当前版本 2.1.319)、原生安装器、VS Code / JetBrains 插件、桌面应用和网页版的形式发布。

安装

# 方式一:npm(需要 Node.js 18+)
npm install -g @anthropic-ai/claude-code
claude --version

# 方式二:一键脚本(macOS / Linux / WSL,无需 Node)
curl -fsSL https://claude.ai/install.sh | bash
# Windows PowerShell
irm https://claude.ai/install.ps1 | iex

Windows 下推荐在 WSL 中使用;如果安装后提示找不到 claude 命令,重新打开终端让 PATH 生效即可。

接入网关:两行配置

export ANTHROPIC_BASE_URL=https://aiprimetech.io
export ANTHROPIC_API_KEY=你的网关密钥
claude

把这两行写进 ~/.zshrc 或 ~/.bashrc。进入会话后用 /status 确认当前连接的地址与密钥,用 /model 切换模型。网关提供的全部 Claude 模型都可以直接使用。

常用命令

  • /init:为项目生成 CLAUDE.md(构建、测试命令与约定),之后每次会话都会先读它。
  • /compact:压缩对话历史,释放上下文——最有效的省钱手段。
  • /clear:清空上下文重新开始。
  • /model:切换模型;/cost:查看本次消耗;/status:查看连接状态。
  • /permissions:设置无需确认的操作范围;/mcp:管理 MCP 服务器;/agents:管理子智能体。
  • claude -p "提示":非交互模式,适合脚本和 CI。

价格与用量

Claude Code 本身免费,费用来自它背后的模型:要么是 Claude Pro/Max 订阅的用量额度,要么是 API 按 token 计费。它每一轮都会重发完整对话和读过的文件,所以长会话费用会快速增长。

套餐时长价格
Unlimited 1 Hour1 hour$0.80
Unlimited 24 Hours24 hours$8
Unlimited 1 Week1 week$37
Unlimited 15 Days15 days$67

查看全部不限量套餐 →

通过本网关:积分按 7.69231 倍面值充值,即 $13 可获得 $100 的按官方价计费的额度(相当于 87% 折扣);重度使用可选不限量套餐,期间不按 token 计费。

Claude Code 开源吗

不开源。CLI 以编译压缩后的 JavaScript 通过 npm 发布,Anthropic 未公开源码。开源的是周边:Agent SDK、GitHub Action、官方 skills 仓库。2026 年曾发生 npm 版本附带 source map 的泄露事件,但这并未改变许可证。想要开源方案,OpenCode、Aider、Cline、Goose 都支持相同的 API,用网关密钥即可使用。

常见报错

  • 500 / 529:模型端故障或过载,稍后重试或用 /model 换一个模型;网关会自动在上游账号间切换。
  • 400:多为上下文超长,用 /compact 或 /clear,或切换到 (1M) 长上下文变体。
  • 429:触发速率限制,子智能体并行时最容易遇到;降低并行度或申请提高并发。
  • 401:密钥与地址不匹配——指向网关时必须使用网关密钥。

常见问题

Claude Code 免费吗?

工具本身免费,使用需要订阅或 API 额度。本站新账户有起始额度,最便宜的持续方案是按小时计费的不限量套餐。

国内能用 Claude Code 吗?

Claude Code 支持自定义 API 地址(ANTHROPIC_BASE_URL),接入本网关后即可正常使用,支付支持银行卡和加密货币。

Claude Code 默认用什么模型?

默认为 Sonnet 档位的当前模型,可用 `/model`、`--model` 或环境变量 ANTHROPIC_DEFAULT_SONNET_MODEL 修改。

在网关上运行 Claude Code

同样的模型,两行环境变量,积分按 7.69231 倍面值充值,或选择不限量套餐。

获取 API 密钥 查看套餐

AI Prime Tech is an independent API gateway and is not affiliated with, endorsed by, or sponsored by Anthropic. “Claude” and “Claude Code” are trademarks of Anthropic. Claude Code features described here follow Anthropic’s public documentation at the time of writing and change frequently; prices and model lists on this page are read from this gateway’s live settings.

更多 Claude Code 指南

Claude Code: the complete guideHow to install Claude CodeClaude Code CLI documentation: commands and flagsClaude Code pricing and limits, explainedThe Claude Code SDK, now the Claude Agent SDKClaude Code skills and pluginsClaude Code in GitHub: the App, the Action and @claudeDoes Claude Code have a web interface? Web, desktop and IDE explainedWhich model Claude Code uses, and how to change itClaude Code errors and how to fix themIs Claude Code open source?Claude Code tutorial: your first real sessionClaude for students: Claude Code, the API and what education actually gets youHow to use Claude Code for QA automationClaude Code vs Cursor: which one, when — and how to run bothClaude Code vs Codex vs OpenCode: the terminal agents comparedClaude Code subagents: how they work, how to define them, and agent teamsClaude Code hooks: deterministic control over what the agent doesClaude Code MCP: connecting servers, scopes, remote MCP and real examplesThe Claude Code ecosystem: routers, frameworks, plugins and the lists that track themClaude Code in VS Code: the extension, the terminal route, and the errorsHow to use OpenRouter in Claude Code (and when not to)Claude rate limit error: what "API error: rate limit reached" means and how to fix it