Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 79 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![Node.js Version](https://img.shields.io/node/v/qiniu-coding-helper.svg)](https://nodejs.org)

**The CLI helper for configuring Claude Code with Qiniu AI API endpoints**
**The CLI helper for configuring AI coding assistants with Qiniu AI API endpoints**

[简体中文](README.zh-CN.md) · [Features](#-features) · [Quick Start](#-quick-start) · [Commands](#-commands) · [Configuration](#-configuration) · [FAQ](#-faq)

Expand All @@ -21,6 +21,8 @@
- **🔐 API Key Management** — Input, validate, save, and revoke API keys
- **📦 Model Configuration** — Fetch available models from the API, with manual model ID input support
- **⚡ Claude Code Integration** — Automatically writes environment variables to `~/.claude/settings.json`
- **🧩 Codex Integration** — Writes Qiniu provider settings to `~/.codex/config.toml` and stores credentials in Codex auth
- **🦀 OpenClaw Integration** — Uses OpenClaw's config CLI to register a Qiniu OpenAI-compatible provider and default model
- **🔍 Health Check** — Built-in `doctor` command to verify config, API Key, network, tools, Git, and Node.js
- **🌍 Internationalization** — Supports Chinese (zh_CN) and English (en_US)

Expand All @@ -29,7 +31,7 @@
Before you begin, ensure you have:

- **Node.js** 18 or later ([Download](https://nodejs.org/))
- **Claude Code CLI** installed ([Get it here](https://claude.ai/download))
- **Claude Code CLI** installed ([Get it here](https://claude.ai/download)), **Codex CLI** installed (`npm install -g @openai/codex`), and/or **OpenClaw CLI** installed
- **Qiniu API Key** ([Get one here](https://portal.qiniu.com/))

## 🚀 Quick Start
Expand All @@ -47,19 +49,27 @@ npx qiniu-coding-helper
- Select your language (Chinese / English)
- Choose your endpoint (Domestic / International)
- Enter and validate your API Key
- Select the coding assistant you want to configure
- Pick a model

### 3️⃣ Restart Claude Code
### 3️⃣ Restart Your Coding Assistant

If Claude Code is running, restart it to apply changes.
If Claude Code, Codex, or OpenClaw is running, restart it to apply changes when needed.

### 4️⃣ Start Coding! 🎉

```bash
# Claude Code
claude

# Codex
codex

# OpenClaw
openclaw
```

That's it! You're now using Qiniu AI endpoints in Claude Code.
That's it! You're now using Qiniu AI endpoints in your coding assistant.

---

Expand Down Expand Up @@ -91,6 +101,12 @@ npx qiniu-coding-helper auth revoke

# Reload configuration to Claude Code
npx qiniu-coding-helper auth reload claude

# Reload configuration to Codex
npx qiniu-coding-helper auth reload codex

# Reload configuration to OpenClaw
npx qiniu-coding-helper auth reload openclaw
```

---
Expand Down Expand Up @@ -120,7 +136,7 @@ Run system health check to diagnose configuration issues.
npx qiniu-coding-helper doctor
```

**Checks:** Config files · API Key validity · Network connectivity · Claude Code installation · Git · Node.js
**Checks:** Config files · API Key validity · Network connectivity · configured tool installations · Git · Node.js

---

Expand All @@ -134,6 +150,12 @@ npx qiniu-coding-helper enter

# Claude Code configuration menu
npx qiniu-coding-helper enter claude-code

# Codex configuration menu
npx qiniu-coding-helper enter codex

# OpenClaw configuration menu
npx qiniu-coding-helper enter openclaw
```

---
Expand All @@ -149,6 +171,7 @@ npx qiniu-coding-helper enter claude-code
| **Claude Code Onboarding** | `~/.claude.json` | Onboarding completion flag |
| **Codex Config** | `~/.codex/config.toml` | Qiniu model provider and profile settings |
| **Codex Auth** | `~/.codex/auth.json` | Codex API key auth cache |
| **OpenClaw Config** | `~/.openclaw/openclaw.json` | Qiniu custom provider, API key env, and default model |

### 🌍 Region Endpoints

Expand Down Expand Up @@ -180,6 +203,45 @@ When Codex configuration is applied, Coding Helper writes the Qiniu model provid

Treat `~/.codex/auth.json` like a password because it contains API credentials.

### 🔧 OpenClaw Configuration

When OpenClaw configuration is applied, Coding Helper calls `openclaw config set` to register a Qiniu OpenAI-compatible provider under `models.providers.qnaigc`, stores the API Key as `env.QINIU_API_KEY`, and sets the default model to `qnaigc/<selected-model>`.

The managed OpenClaw provider uses the Qiniu OpenAI-compatible endpoint:

```json
{
"env": {
"QINIU_API_KEY": "<your-api-key>"
},
"models": {
"mode": "merge",
"providers": {
"qnaigc": {
"baseUrl": "https://api.qnaigc.com/v1",
"apiKey": "${QINIU_API_KEY}",
"api": "openai-completions",
"models": [
{
"id": "<selected-model>",
"name": "<selected-model>"
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "qnaigc/<selected-model>"
}
}
}
}
```

OpenClaw gateway, channels, daemon, workspace, and pairing setup remain managed by OpenClaw itself.

---

## ❓ FAQ
Expand All @@ -191,6 +253,13 @@ Treat `~/.codex/auth.json` like a password because it contains API credentials.
3. **Restart Claude Code completely**
4. Ensure `ANTHROPIC_BASE_URL` is not set in your shell environment (`unset ANTHROPIC_BASE_URL`)

### OpenClaw doesn't use the configured endpoint

1. Run `npx qiniu-coding-helper doctor` to check OpenClaw installation and configuration
2. Run `npx qiniu-coding-helper auth reload openclaw` to reapply settings
3. Confirm `~/.openclaw/openclaw.json` contains `models.providers.qnaigc`
4. Run `openclaw doctor` if the OpenClaw gateway reports a config validation error

### API errors or authentication failures

1. Verify your API Key: check `~/.coding-helper/config.yaml`
Expand All @@ -202,6 +271,9 @@ Treat `~/.codex/auth.json` like a password because it contains API credentials.
```bash
chmod 600 ~/.claude/settings.json
chmod 600 ~/.coding-helper/config.yaml
chmod 600 ~/.codex/config.toml
chmod 600 ~/.codex/auth.json
chmod 600 ~/.openclaw/openclaw.json
```

---
Expand All @@ -211,6 +283,7 @@ chmod 600 ~/.coding-helper/config.yaml
```bash
pnpm install # Install dependencies
pnpm build # Build (tsc + copy locales to dist/)
pnpm test # Build and run node:test tests
pnpm dev # Watch mode
pnpm start # Run CLI (node dist/cli.js)
pnpm clean # Clean dist/
Expand Down
93 changes: 87 additions & 6 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![Node.js Version](https://img.shields.io/node/v/qiniu-coding-helper.svg)](https://nodejs.org)

**一站式配置 Claude Code 使用七牛 AI API 端点的 CLI 工具**
**一站式配置 AI 编程助手使用七牛 AI API 端点的 CLI 工具**

[English](README.md) · [功能特性](#-功能特性) · [快速开始](#-快速开始) · [命令一览](#-命令一览) · [配置说明](#-配置说明) · [常见问题](#-常见问题)

Expand All @@ -21,6 +21,8 @@
- **🔐 API Key 管理** — 输入、验证、保存、删除,一条龙管理
- **📦 模型配置** — 从 API 获取可用模型列表,也支持手动输入模型 ID
- **⚡ Claude Code 集成** — 自动将环境变量写入 `~/.claude/settings.json`
- **🧩 Codex 集成** — 将七牛 provider 写入 `~/.codex/config.toml`,并把凭证保存到 Codex auth
- **🦀 OpenClaw 集成** — 通过 OpenClaw 配置 CLI 注册七牛 OpenAI 兼容 provider 和默认模型
- **🔍 健康检查** — 内置 `doctor` 命令,检测配置文件、API Key、网络、工具安装状态
- **🌍 国际化** — 支持中文 (zh_CN) 和英文 (en_US)

Expand All @@ -29,7 +31,7 @@
开始之前,请确保已安装:

- **Node.js** 18 或更高版本 ([下载](https://nodejs.org/))
- **Claude Code CLI** ([安装地址](https://claude.ai/download))
- **Claude Code CLI** ([安装地址](https://claude.ai/download))、**Codex CLI** (`npm install -g @openai/codex`) 和/或 **OpenClaw CLI**
- **七牛 API Key** ([获取地址](https://portal.qiniu.com/))

## 🚀 快速开始
Expand All @@ -47,19 +49,27 @@ npx qiniu-coding-helper
- 选择语言(中文 / 英文)
- 选择线路(国内 / 海外)
- 输入并验证 API Key
- 选择要配置的编程助手
- 选择模型

### 3️⃣ 重启 Claude Code
### 3️⃣ 重启编程助手

如果 Claude Code 正在运行,请重启以应用配置
如果 Claude Code、Codex 或 OpenClaw 正在运行,请按需重启以应用配置

### 4️⃣ 开始编程! 🎉

```bash
# Claude Code
claude

# Codex
codex

# OpenClaw
openclaw
```

配置完成!现在 Claude Code 已通过七牛 AI 端点运行。
配置完成!现在你的编程助手已通过七牛 AI 端点运行。

---

Expand Down Expand Up @@ -91,6 +101,12 @@ npx qiniu-coding-helper auth revoke

# 重新加载配置到 Claude Code
npx qiniu-coding-helper auth reload claude

# 重新加载配置到 Codex
npx qiniu-coding-helper auth reload codex

# 重新加载配置到 OpenClaw
npx qiniu-coding-helper auth reload openclaw
```

---
Expand Down Expand Up @@ -120,7 +136,7 @@ npx qiniu-coding-helper lang set en_US
npx qiniu-coding-helper doctor
```

**检查项:** 配置文件 · API Key 有效性 · 网络连通性 · Claude Code 安装 · Git · Node.js
**检查项:** 配置文件 · API Key 有效性 · 网络连通性 · 已配置工具安装状态 · Git · Node.js

---

Expand All @@ -134,6 +150,12 @@ npx qiniu-coding-helper enter

# 进入 Claude Code 配置菜单
npx qiniu-coding-helper enter claude-code

# 进入 Codex 配置菜单
npx qiniu-coding-helper enter codex

# 进入 OpenClaw 配置菜单
npx qiniu-coding-helper enter openclaw
```

---
Expand All @@ -147,6 +169,9 @@ npx qiniu-coding-helper enter claude-code
| **Coding Helper 配置** | `~/.coding-helper/config.yaml` | 语言、线路、API Key、模型设置 |
| **Claude Code 设置** | `~/.claude/settings.json` | API 端点环境变量 |
| **Claude Code Onboarding** | `~/.claude.json` | 初始化完成标记 |
| **Codex 配置** | `~/.codex/config.toml` | 七牛模型 provider 和 profile 设置 |
| **Codex Auth** | `~/.codex/auth.json` | Codex API Key 认证缓存 |
| **OpenClaw 配置** | `~/.openclaw/openclaw.json` | 七牛 custom provider、API Key env 和默认模型 |

### 🌍 线路端点

Expand All @@ -172,6 +197,51 @@ npx qiniu-coding-helper enter claude-code

> **说明:** 工具还会设置 `API_TIMEOUT_MS`(50 分钟,适配长时间推理请求)、禁用非必要流量(第三方端点不需要 Anthropic 遥测)、禁用 commit/PR 归属标注(通过代理端点运行时标注不准确)。

### 🔧 Codex 配置

配置应用到 Codex 时,Coding Helper 会将七牛模型 provider 写入 `~/.codex/config.toml`,并把 API Key 保存到 Codex 自己的 `~/.codex/auth.json` 认证缓存,不依赖 `QINIU_API_KEY` shell 环境变量。

请像保管密码一样保管 `~/.codex/auth.json`,因为它包含 API 凭证。

### 🔧 OpenClaw 配置

配置应用到 OpenClaw 时,Coding Helper 会调用 `openclaw config set`,在 `models.providers.qnaigc` 下注册七牛 OpenAI 兼容 provider,把 API Key 保存为 `env.QINIU_API_KEY`,并将默认模型设置为 `qnaigc/<selected-model>`。

托管的 OpenClaw provider 使用七牛 OpenAI 兼容端点:

```json
{
"env": {
"QINIU_API_KEY": "<your-api-key>"
},
"models": {
"mode": "merge",
"providers": {
"qnaigc": {
"baseUrl": "https://api.qnaigc.com/v1",
"apiKey": "${QINIU_API_KEY}",
"api": "openai-completions",
"models": [
{
"id": "<selected-model>",
"name": "<selected-model>"
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "qnaigc/<selected-model>"
}
}
}
}
```

OpenClaw 的 gateway、channels、daemon、workspace 和 pairing 设置仍由 OpenClaw 自身管理。

---

## ❓ 常见问题
Expand All @@ -183,6 +253,13 @@ npx qiniu-coding-helper enter claude-code
3. **完全重启 Claude Code**
4. 确认 shell 环境中没有设置 `ANTHROPIC_BASE_URL`(运行 `unset ANTHROPIC_BASE_URL`)

### OpenClaw 没有使用配置的端点

1. 运行 `npx qiniu-coding-helper doctor` 检查 OpenClaw 安装和配置
2. 运行 `npx qiniu-coding-helper auth reload openclaw` 重新应用设置
3. 确认 `~/.openclaw/openclaw.json` 包含 `models.providers.qnaigc`
4. 如果 OpenClaw gateway 报配置校验错误,运行 `openclaw doctor` 查看原因

### API 报错或认证失败

1. 检查 API Key:查看 `~/.coding-helper/config.yaml`
Expand All @@ -194,6 +271,9 @@ npx qiniu-coding-helper enter claude-code
```bash
chmod 600 ~/.claude/settings.json
chmod 600 ~/.coding-helper/config.yaml
chmod 600 ~/.codex/config.toml
chmod 600 ~/.codex/auth.json
chmod 600 ~/.openclaw/openclaw.json
```

---
Expand All @@ -203,6 +283,7 @@ chmod 600 ~/.coding-helper/config.yaml
```bash
pnpm install # 安装依赖
pnpm build # 编译 (tsc + 复制 locales 到 dist/)
pnpm test # 编译并运行 node:test 测试
pnpm dev # 监听模式
pnpm start # 运行 CLI (node dist/cli.js)
pnpm clean # 清理 dist/
Expand Down
1 change: 1 addition & 0 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ora from 'ora';
function resolveToolName(tool: string): string {
if (tool === 'claude' || tool === 'claude-code') return 'claude-code';
if (tool === 'codex' || tool === 'openai-codex') return 'codex';
if (tool === 'openclaw' || tool === 'claw') return 'openclaw';
return tool;
}
Comment on lines 11 to 16

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The resolveToolName function is duplicated in both src/commands/auth.ts and src/lib/command.ts. This duplication makes the code harder to maintain. Consider moving this utility function to a shared location, such as src/lib/tool-manager.ts or a dedicated utility file.


Expand Down
1 change: 1 addition & 0 deletions src/lib/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { VERSION } from './version.js';
function resolveToolName(tool: string): string {
if (tool === 'claude' || tool === 'claude-code') return 'claude-code';
if (tool === 'codex' || tool === 'openai-codex') return 'codex';
if (tool === 'openclaw' || tool === 'claw') return 'openclaw';
return tool;
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/tool-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ITool } from './tools/base-tool.js';
import { ClaudeCodeTool } from './tools/claude-code-tool.js';
import { CodexTool } from './tools/codex-tool.js';
import { OpenClawTool } from './tools/openclaw-tool.js';

// 工具注册中心
class ToolManager {
Expand All @@ -10,6 +11,7 @@ class ToolManager {
// 注册默认工具
this.register(new ClaudeCodeTool());
this.register(new CodexTool());
this.register(new OpenClawTool());
}

// 注册工具
Expand Down
Loading