nicecode-tool
v1.3.7
Published
NiceCode API configuration tool for Claude, CodeX, and Gemini CLI tools
Maintainers
Readme
NiceCode API 切换工具
自动配置 Claude、CodeX、Gemini 和 OpenCode CLI 工具,将其 API 端点切换到 NiceCode 服务。
快速开始
Linux / macOS
一键安装并运行(推荐):
curl -fsSL https://nicecode.ai/setup.sh | bash或者下载后执行:
curl -fsSL https://nicecode.ai/setup.sh -o setup.sh
chmod +x setup.sh
./setup.sh带参数执行(直接配置 Claude):
curl -fsSL https://nicecode.ai/setup.sh | bash -s -- -cc -k your-api-keyWindows (PowerShell)
一键安装并运行(推荐):
iwr -useb https://nicecode.ai/setup.ps1 | iex或者下载后执行:
iwr -useb https://nicecode.ai/setup.ps1 -OutFile setup.ps1
.\setup.ps1带参数执行(直接配置 Claude):
& ([ScriptBlock]::Create((iwr -useb https://nicecode.ai/setup.ps1).Content)) -cc -k your-api-key功能特性
- 支持 Claude、CodeX、Gemini、OpenCode 四大 AI CLI 工具
- 交互式菜单或命令行参数两种使用方式
- 自动创建配置文件和目录结构
- 彩色终端输出,清晰的状态提示
- 支持一次性配置所有产品
- 安全的 API Key 输入(PowerShell 版本使用 SecureString)
使用方法
交互式菜单
直接运行脚本,按照菜单提示选择:
Linux/macOS:
./setup.shWindows:
.\setup.ps1会显示如下菜单:
======================================
NiceCode API 切换工具
======================================
1) Claude
2) CodeX
3) Gemini
4) OpenCode
5) 全部配置
0) 退出
======================================
请选择要配置的产品 [1-5]:命令行参数
支持通过命令行参数直接配置,适合自动化脚本。
参数说明
| 参数 | 简写 | 说明 | 示例 |
|------|------|------|------|
| --claude | -cc | 配置 Claude | -cc |
| --codex | -cx | 配置 CodeX | -cx |
| --gemini | -gm | 配置 Gemini | -gm |
| --opencode | -oc | 配置 OpenCode | -oc |
| --choice | -c | 指定产品名称 | -c claude |
| --key | -k | 指定 API Key | -k your-api-key |
| --help | -h | 显示帮助信息 | -h |
使用示例
配置 Claude:
# Linux/macOS
./setup.sh -cc -k your-api-key
./setup.sh --claude --key your-api-key
./setup.sh -c claude -k your-api-key
# Windows
.\setup.ps1 -cc -k your-api-key
.\setup.ps1 --claude --key your-api-key
.\setup.ps1 -c claude -k your-api-key配置 CodeX:
# Linux/macOS
./setup.sh -cx -k your-api-key
# Windows
.\setup.ps1 -cx -k your-api-key配置 Gemini:
# Linux/macOS
./setup.sh -gm -k your-api-key
# Windows
.\setup.ps1 -gm -k your-api-key配置所有产品(使用相同的 API Key):
# Linux/macOS
./setup.sh -c all -k your-api-key
# Windows
.\setup.ps1 -c all -k your-api-key不指定 API Key(稍后输入):
# Linux/macOS
./setup.sh -cc
# Windows
.\setup.ps1 -cc支持的产品
Claude
- 配置目录:
- Linux/macOS:
~/.claude - Windows:
%USERPROFILE%\.claude
- Linux/macOS:
- 配置文件:
settings.json - 环境变量:
ANTHROPIC_BASE_URL: https://nicecode.aiANTHROPIC_AUTH_TOKEN: your-api-key
CodeX
- 配置目录:
- Linux/macOS:
~/.codex - Windows:
%USERPROFILE%\.codex
- Linux/macOS:
- 配置文件:
config.toml: 主配置文件auth.json: 认证文件
- 模型配置: gpt-5.1-codex
Gemini
- 配置目录:
- Linux/macOS:
~/.gemini - Windows:
%USERPROFILE%\.gemini
- Linux/macOS:
- 配置文件:
.env: 环境变量配置settings.json: 设置文件
- 环境变量:
GOOGLE_GEMINI_BASE_URL: https://nicecode.aiGEMINI_API_KEY: your-api-key
OpenCode
- 配置目录:
- Linux/macOS:
~/.config/opencode - Windows:
%USERPROFILE%\opencode
- Linux/macOS:
- 配置文件:
opencode.jsonc: 从https://nicecode.ai/opencode.jsonc下载(存在也覆盖)
- 认证文件:
- Linux/macOS:
~/.local/share/opencode/auth.json - Windows:
%USERPROFILE%\.local\share\opencode\auth.json
- Linux/macOS:
- 文档地址: https://nicecode.ai/docs/oc
配置说明
Claude 配置详情
脚本会创建 ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.nicecode.ai",
"ANTHROPIC_AUTH_TOKEN": "your-api-key"
}
}并将 ~/.claude.json 中的 hasCompletedOnboarding 设置为 true。
CodeX 配置详情
脚本会创建 ~/.codex/config.toml:
model_provider = "nicecode"
model = "gpt-5.1-codex"
model_reasoning_effort = "high"
network_access = "enabled"
disable_response_storage = true
windows_wsl_setup_acknowledged = true
model_verbosity = "high"
[model_providers.nicecode]
name = "nicecode"
base_url = "https://api.nicecode.ai/v1"
wire_api = "responses"
requires_openai_auth = true以及 ~/.codex/auth.json:
{
"OPENAI_API_KEY": "your-api-key"
}Gemini 配置详情
脚本会创建 ~/.gemini/.env:
GOOGLE_GEMINI_BASE_URL=https://api.nicecode.ai
GEMINI_API_KEY=your-api-key
GEMINI_MODEL=以及 ~/.gemini/settings.json:
{
"general": {
"previewFeatures": true
},
"ide": {
"hasSeenNudge": true
},
"model": {
"name": "gemini-3-flash-preview"
},
"security": {
"auth": {
"selectedType": "gemini-api-key"
}
}
}OpenCode 配置详情
脚本会从 https://nicecode.ai/opencode.jsonc 下载配置文件到:
- Linux/macOS:
~/.config/opencode/opencode.jsonc - Windows:
%USERPROFILE%\opencode\opencode.jsonc
如果配置文件已存在,会被覆盖。
脚本会创建或更新认证文件:
- Linux/macOS:
~/.local/share/opencode/auth.json - Windows:
%USERPROFILE%\.local\share\opencode\auth.json
{
"provider": {
"opencode": {
"apiKey": "your-api-key"
}
}
}如果认证文件已存在,会更新其中的 apiKey 字段,保留其他配置。
系统要求
Linux/macOS (setup.sh)
- Bash 3.2 或更高版本
- 基本 Unix 工具:
mkdir,cat,grep,sed - 可选:
jq(用于更好的 JSON 处理,如未安装会自动使用备用方案)
Windows (setup.ps1)
- PowerShell 5.1 或更高版本
- Windows 7/8/10/11 或 Windows Server 2008 R2 及更高版本
安全提示
审查脚本: 在执行任何网络脚本之前,建议先下载并审查其内容:
# Linux/macOS curl -fsSL https://nicecode.ai/setup.sh -o setup.sh cat setup.sh # 查看脚本内容 # Windows iwr -useb https://nicecode.ai/setup.ps1 -OutFile setup.ps1 Get-Content setup.ps1 # 查看脚本内容API Key 保护:
- 不要在命令行历史中暴露 API Key
- 建议使用交互式输入而非命令行参数传递 API Key
- Windows 版本使用 SecureString 保护输入
配置文件权限:
- 配置文件包含敏感信息,确保适当的文件权限
- Linux/macOS 建议设置为
600或700
常见问题
Q: 提示"未检测到 XXX CLI"怎么办?
A: 这表示对应的 CLI 工具尚未安装。请先安装相应的工具:
- Claude: 访问 Claude CLI 官网 安装
- CodeX: 访问 CodeX 官网 安装
- Gemini: 访问 Gemini CLI 官网 安装
脚本会创建配置目录,但建议先安装官方 CLI 工具以确保完整功能。
Q: 如何验证配置是否成功?
A: 配置完成后,运行相应的 CLI 工具:
# 验证 Claude
claude --version
# 验证 CodeX
codex --version
# 验证 Gemini
gemini --versionQ: 如何切换回官方 API?
A: 手动编辑配置文件,将 API URL 改回官方地址,或删除配置文件重新运行官方工具初始化。
Q: 支持哪些操作系统?
A:
- Linux: Ubuntu, Debian, CentOS, Fedora, Arch 等主流发行版
- macOS: macOS 10.10 及更高版本
- Windows: Windows 7/8/10/11 及 Windows Server 2008 R2 及更高版本
Q: 一键安装命令是否安全?
A: 从互联网直接执行脚本存在安全风险。建议:
- 先下载脚本查看内容
- 确认来源可信
- 使用 HTTPS 连接
- 定期更新脚本
Q: 可以使用不同的 API Key 配置不同的产品吗?
A: 可以。分别运行脚本配置每个产品:
./setup.sh -cc -k claude-api-key
./setup.sh -cx -k codex-api-key
./setup.sh -gm -k gemini-api-key技术支持
如有问题或建议,请访问:
- 官网: https://nicecode.ai
- 文档: https://nicecode.ai/docs
- 问题反馈: https://github.com/nicecode/nicecode-tools/issues
许可证
MIT License
更新日志
v1.0.0 (2026-01-09)
- 首次发布
- 支持 Claude、CodeX、Gemini 三大 CLI 工具
- 提供 Linux/macOS 和 Windows 版本
- 交互式菜单和命令行参数两种使用方式
- 一键安装支持
