> ## Documentation Index
> Fetch the complete documentation index at: https://www.qhaigc.net/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code 接入启航AI教程

> 在终端中使用 Claude Code 接入启航AI

# Claude Code 接入启航AI教程

[Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) 是 Anthropic 官方终端 AI 编程工具，极高付费意愿用户的首选。本教程介绍如何接入启航AI。

## 前置要求

* Node.js 18+
* Claude Code CLI
* 启航AI API Key（[获取地址](https://api.qhaigc.net)）

## 安装 Claude Code

```bash theme={null}
npm install -g @anthropic-ai/claude-code
```

## 配置步骤

### 1. 设置环境变量

#### macOS/Linux

```bash theme={null}
export ANTHROPIC_API_KEY="your-api-key"
export ANTHROPIC_BASE_URL="https://api.qhaigc.net"
```

添加到 `~/.zshrc` 或 `~/.bashrc` 使其永久生效：

```bash theme={null}
echo 'export ANTHROPIC_API_KEY="your-api-key"' >> ~/.zshrc
echo 'export ANTHROPIC_BASE_URL="https://api.qhaigc.net"' >> ~/.zshrc
source ~/.zshrc
```

#### Windows (PowerShell)

```powershell theme={null}
$env:ANTHROPIC_API_KEY = "your-api-key"
$env:ANTHROPIC_BASE_URL = "https://api.qhaigc.net"
```

添加到系统环境变量使其永久生效。

### 2. 验证配置

```bash theme={null}
claude --version
```

### 3. 启动 Claude Code

在项目目录中：

```bash theme={null}
claude
```

## 使用方式

### 自然语言编程

```
> 创建一个 Python 脚本，读取 CSV 文件并生成统计报告
```

Claude Code 会自动：

1. 分析需求
2. 创建文件
3. 编写代码
4. 运行测试

### 代码审查

```
> 审查这个文件中的潜在问题
```

### 重构代码

```
> 重构 src/utils.py，使其更符合 PEP8 规范
```

### 调试

```
> 这个测试失败了，帮我找出原因
```

### Git 操作

```
> 提交所有更改并写一个有意义的提交信息
```

## 功能特性

* ✅ 自然语言编程
* ✅ 自动文件操作
* ✅ 终端命令执行
* ✅ 代码审查
* ✅ 调试辅助
* ✅ Git 集成
* ✅ 测试生成
* ✅ 代码重构

## 支持的模型

Claude Code 默认使用 Claude 模型，启航AI支持：

| 模型                | 特点     |
| ----------------- | ------ |
| claude-3-5-sonnet | 最强编程能力 |
| claude-3-haiku    | 快速响应   |

## 高级用法

### 指定模型

```bash theme={null}
claude --model claude-3-5-sonnet
```

### 禁用工具

```bash theme={null}
claude --no-tools
```

### 仅对话模式

```bash theme={null}
claude --chat
```

## 配置文件

Claude Code 支持配置文件 `~/.claude/config.json`：

```json theme={null}
{
  "apiKey": "your-api-key",
  "baseUrl": "https://api.qhaigc.net",
  "defaultModel": "claude-3-5-sonnet"
}
```

## 快捷键

| 快捷键        | 功能     |
| ---------- | ------ |
| `Ctrl + C` | 中断当前操作 |
| `Ctrl + D` | 退出     |
| `↑/↓`      | 浏览历史   |

## 常见问题

**Q: 提示 "API key not found"？**

A: 确保环境变量已正确设置，或检查配置文件。

**Q: 连接失败？**

A: 检查：

* `ANTHROPIC_BASE_URL` 是否正确
* API Key 是否有效
* 网络能否访问 `api.qhaigc.net`

**Q: 如何查看 Token 消耗？**

A: 登录 [启航AI控制台](https://api.qhaigc.net) 查看。

## 相关链接

* [Claude Code 文档](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview)
* [启航AI官网](https://api.qhaigc.net)

***

*最后更新：2026年3月*
