by 4xian
ccapi - A management tool for quickly switching Claude Code and Codex configurations | 一个Claude Code 和 Codex 配置管理工具,一键切换多个中转站API配置;一键切换系统环境变量;一键测试API延迟;一键测试API有效性;自动择优线路切换与国际化支持。
# Add to your Claude Code skills
git clone https://github.com/4xian/claude-codex-apiGuides for using cli tools skills like claude-codex-api.
Last scanned: 5/30/2026
{
"issues": [
{
"type": "npm-audit",
"message": "@chevrotain/cst-dts-gen: Vulnerability found",
"severity": "medium"
},
{
"type": "npm-audit",
"message": "@chevrotain/gast: Vulnerability found",
"severity": "medium"
},
{
"type": "npm-audit",
"message": "@rollup/plugin-terser: Vulnerability found",
"severity": "medium"
},
{
"type": "npm-audit",
"message": "brace-expansion: brace-expansion: Zero-step sequence causes process hang and memory exhaustion",
"severity": "medium"
},
{
"type": "npm-audit",
"message": "chevrotain: Vulnerability found",
"severity": "medium"
},
{
"type": "npm-audit",
"message": "js-yaml: js-yaml has prototype pollution in merge (<<)",
"severity": "medium"
},
{
"type": "npm-audit",
"message": "lodash-es: Lodash has Prototype Pollution Vulnerability in `_.unset` and `_.omit` functions",
"severity": "high"
},
{
"type": "npm-audit",
"message": "minimatch: minimatch has a ReDoS via repeated wildcards with non-matching literal in pattern",
"severity": "high"
},
{
"type": "npm-audit",
"message": "picomatch: Picomatch: Method Injection in POSIX Character Classes causes incorrect Glob Matching",
"severity": "high"
},
{
"type": "npm-audit",
"message": "rollup: Rollup 4 has Arbitrary File Write via Path Traversal",
"severity": "high"
},
{
"type": "npm-audit",
"message": "serialize-javascript: Serialize JavaScript is Vulnerable to RCE via RegExp.flags and Date.prototype.toISOString()",
"severity": "high"
},
{
"type": "npm-audit",
"message": "yaml: yaml is vulnerable to Stack Overflow via deeply nested YAML collections",
"severity": "medium"
}
],
"status": "WARNING",
"scannedAt": "2026-05-30T15:48:55.435Z",
"npmAuditRan": true,
"pipAuditRan": true
}claude-codex-api is an open-source cli tools skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by 4xian. ccapi - A management tool for quickly switching Claude Code and Codex configurations | 一个Claude Code 和 Codex 配置管理工具,一键切换多个中转站API配置;一键切换系统环境变量;一键测试API延迟;一键测试API有效性;自动择优线路切换与国际化支持。. It has 206 GitHub stars.
claude-codex-api returned warnings in SkillsLLM's automated security scan. It has no critical vulnerabilities, but review the flagged issues in the Security Report section before adding it to your workflow.
Clone the repository with "git clone https://github.com/4xian/claude-codex-api" and add it to your Claude Code skills directory (see the Installation section above).
claude-codex-api is primarily written in JavaScript. It is open-source under 4xian on GitHub, so you can review or fork the full source.
Yes. SkillsLLM lists many other CLI Tools skills you can browse and compare side by side. Open the CLI Tools category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh claude-codex-api against similar tools.
No comments yet. Be the first to share your thoughts!
Top skills in this category by stars
Requires a passing catalog security scan. Resolve the flagged issues and resubmit to enable featuring.
一个Claude 和 Codex 配置管理工具,一键切换多个中转站API配置; 一键切换系统环境变量,一键测试API延迟,一键测试API有效性,自动择优线路切换与国际化支持。 当前文档为Claude Code配置介绍,Codex文档请点击右上角↗️查看
# 安装
npm install -g @4xian/ccapi
# 卸载
npm uninstall -g @4xian/ccapi
ccapi -v
初次使用需要设置Claude Code的settings.json 文件路径和自定义API配置文件路径:
# windows 默认settings.json路径在 C:\Users\Administrator\.claude\settings.json
# mac 默认settings.json路径在 ~/.claude/settings.json
# 若无settings.json文件可自己创建一个
# 三种方式设置路径(例如):
1. mac同时设置两个路径
ccapi set --settings ~/.claude/settings.json --api /Users/4xian/Desktop/api.json5
2.分别设置
ccapi set --settings ~/.claude/settings.json
ccapi set --api /Users/4xian/Desktop/api.json5
3.直接在配置文件中修改路径
# (若无 .ccapi-config.json 文件可自己创建一个)
在 ~/.ccapi-config.json 文件中(与.claude同级),有存储路径的变量,直接修改即可
{
"settingsPath": "~/.claude/settings.json",
"apiConfigPath": "/Users/4xian/Desktop/api.json5",
}
# 查询当前设置的配置文件路径
ccapi set
支持多种配置文件格式:JSON、JSON5、YAML、TOML
创建一个配置文件(如 api.json、api.yaml、api.json5 或 api.toml),格式如下:
JSON5 格式示例:
{
"openrouter": {
"url": "https://api.openrouter.ai",
"token": "your-auth-token",
"model": "claude-sonnet-4-20250514",
"fast": "claude-3-5-haiku-20241022",
"timeout": 600000,
"tokens": 65000
},
// 推荐使用数组形式,可进行多个配置
"multiconfig": {
"url": [
"https://api.example1.com",
"https://api.example2.com"
],
"token": [
"token1-for-auth",
"token2-for-auth"
],
"model": [
"claude-sonnet-4-5-20250929",
"claude-sonnet-4-20250514"
]
}
}
YAML 格式示例:
openrouter:
url: "https://api.openrouter.ai"
token: "your-auth-token"
model: "claude-sonnet-4-20250514"
fast: "claude-3-5-haiku-20241022"
timeout: 600000
tokens: 65000
multiconfig:
url:
- "https://api.example1.com"
- "https://api.example2.com"
token:
- "token1-for-auth"
- "token2-for-auth"
model:
- "claude-sonnet-4-5-20250929"
- "claude-sonnet-4-20250514"
字段说明: 【不同厂商提供的可能是key, 也可能是token, 若不能使用可将key和token互换一下】 【本工具只提供快速切换环境变量的功能,因此只支持Anthropic格式的配置, 只要Claude Code能用就都可以】
url: API厂商服务器地址(必需)
key: API_KEY(key 和 token 同时只需要一个)
token: AUTH_TOKEN(key 和 token 同时只需要一个)
model: 模型名称(非必需,默认claude-sonnet-4-20250514)
fast: 快速模型名称(非必需,默认claude-3-5-haiku-20241022)
timeout: 请求超时时间(非必需,默认为官方600000ms)tokens: 最大输出令牌数(非必需,默认以官方为准)http: 为网络连接指定 HTTP 代理服务器https: 为网络连接指定 HTTPS 代理服务器ccapi ls 或者 ccapi list
显示说明:
*号的配置表示当前正在使用# 切换到指定配置(使用默认模型,配置若为数组,则默认使用第一个)
ccapi use openrouter
# 对于字符串格式的 model/fast,直接切换
ccapi use anyrouter
# 切换到 multiconfig 配置,并使用第一个url,第一个token,第2个模型,第1个快速模型
ccapi use multiconfig -u 1 -t 1 -m 2 -f 1
# 只切换某些字段的索引
ccapi use multiconfig -k 1 # 只切换到某个Key
ccapi use multiconfig -t 2 # 只切换到某个Token
ccapi use multiconfig -u 1 # 只切换到某个URL
ccapi use multiconfig -m 3 # 只切换到某个Model
ccapi use multiconfig -f 2 # 只切换到某个Fast Model索引
# 同时清除 settings.json 和系统环境变量中的所有当前配置
ccapi clear
参数说明:
-u <index>: 指定要使用的URL索引(从1开始计数)-k <index>: 指定要使用的Key索引(从1开始计数)-t <index>: 指定要使用的Token索引(从1开始计数)-m <index>: 指定要使用的模型索引(从1开始计数)-f <index>: 指定要使用的快速模型索引(从1开始计数) {
"settingsPath": "~/.claude/settings.json",
"apiConfigPath": "/Users/4xian/Desktop/api.json5",
"useNoEnv": false
}
环境变量功能允许你将配置设置到系统环境变量中
# 显示当前系统中已设置的 Claude Code 相关环境变量
ccapi env
显示示例:
当前系统环境变量: openrouter
CCAPI_CURRENT_CONFIG: openrouter
ANTHROPIC_BASE_URL: https://api.openrouter.ai
ANTHROPIC_AUTH_TOKEN: your-auth-token...
ANTHROPIC_MODEL: claude-sonnet-4-20250514
ANTHROPIC_SMALL_FAST_MODEL: claude-3-5-haiku-20241022
# 基本设置
ccapi env openrouter
# 指定数组索引(适用于数组配置)
ccapi env multiconfig -u 1 -k 2 -t 1 -m 2 -f 1
参数说明:
-u <index>: 指定要使用的URL索引(从1开始计数)-k <index>: 指定要使用的Key索引(从1开始计数)-t <index>: 指定要使用的Token索引(从1开始计数)-m <index>: 指定要使用的模型索引(从1开始计数)-f <index>: 指定要使用的快速模型索引(从1开始计数)# 清除当前配置相关的所有系统环境变量
ccapi env clear
# 同时清除 settings.json 和系统环境变量中的所有当前配置
ccapi clear
快速测试配置中所有中转站 URL 的网络延迟(仅测试网络连通性,不验证 API 可用性)。
# 测试所有配置
ccapi ping
# 测试指定配置
ccapi ping openrouter
测试中转站API配置在Claude Code中是否可用,可以真实的反映出配置是否有效
# 测试所有配置
ccapi test
# 测试指定配置
ccapi test openrouter
# 使用 Claude Code CLI 方式测试(更准确,但速度较慢)
ccapi test -c
ccapi test -c openrouter
测试方式说明:
-c 选项):使用真实的Claude Code CLI环境,准确度最高,可能会出现调用各种mcp服务情况,速度较慢(1分钟左右)配置说明:
ping测试超时时间:默认为5秒,可在 ~/.ccapi-config.json 文件中新增变量控制超时,如:pingTimeout: 5000
test测试超时时间:默认为30秒(接口模拟方式)或 100秒(CLI方式),可在 ~/.ccapi-config.json 文件中新增变量控制超时,如:testTimeout: 30000
测试返回的结果:默认显示,由于厂商不同,返回结果仅供参考,可在 ~/.ccapi-config.json 文件中新增变量是否显示结果,如:testResponse: true
test cli模式测试并发:默认为3,cli模式测试由于消耗性能较高,采用分批测试,若测试结果全部都超时,建议数值小点,超时时间拉长
{
"settingsPath": "~/.claude/settings.json",
"apiConfigPath": "/Users/4xian/Desktop/api.json5",
"pingTimeout": 5000,
"testTimeout": 30000,
"testResponse": true,
"testConcurrency": 3
}
对于数组格式的URL,会测试所有URL地址,数组配置的URL内部不会按延迟排序,保持原有的URL顺序
配置按最佳延迟排序,延迟最低的配置排在前面
显示每个配置的最优路线(最快的URL地址)
测试结果示例:
测试结果(按延迟从低到高):
【xxx】(最优路线: xxx/claude)
1.[https://xxx/claude] ● 628ms
【multiconfig】(最优路线: api.example1.com)
1.[https://api.example1.com] ● 856ms
2.[https://api.example2.com] ● 892ms
首先进行延迟测试,然后选择最优的进行切换配置,测试基准可按上诉两种方式选择其一为准
# 会先进行所有配置测试,然后选择最优的配置进行自动切换,默认以test命令测试的结果为基准切换
ccapi auto
# 以ping结果为准进行切换
ccapi auto -p
# 以test结果为准进行切换(默认)
ccapi auto -t
# 只测试单个配置,从中选择最优切换(适用于单个配置中多URL的情况)
ccapi auto multiconfig -t
# 常用于组合命令,这样每次启动claude前都会选择最优路线
ccapi auto && claude
# 也可以自定义别名,每次使用别名启动
alias cc=ccapi auto && claude
cc
功能说明:
由于自动配置的对齐规则,可以在一个配置中进行多厂商配置,比如:
{
"aaa": {
"url": [
"https: 第一个厂商.com",
"https: 第二个厂商.com",
"https: 第三个厂商.com",
],
"token": [
"第一个厂商的token",
"第二个厂商的token",
"第三个厂商的token",
],
"model": ["xxx"]
},
"bbb": {
"url": [
"https: 第一个厂商.com",
"https: 第二个厂商.com",
"https: 第三个厂商.com",
],
"key": [
"第一个厂商的key",
"第二个厂商的key",
"第三个厂商的key",
],
"model": ["xxx"]
},
}
程序自带版本检查,若npm发布新版则在使用过程中会进行更新提示,若不想要提示可在 ~/.ccapi-config.json 文件中新增变量 update: false关闭
# 自动更新 ccapi 到最新版本
ccapi update
程序支持中英文双语界面,可以根据需要切换显示语言,默认中文:
# 查看当前语言设置
ccapi lang
# 切换为中文
ccapi lang zh
# 切换为英文
ccapi lang en
# 也可直接在配置文件修改 ~/.ccapi-config.json
{
"language": "zh"
}
该文件是ccapi使用的配置文件,可在此进行选项配置,具体文件在 ~/.ccapi-config.json。
{
# settings.json文件路径
"settingsPath": "~/.claude/settings.json",
# api配置文件路径
"apiConfigPath": "/Users/4xian/Desktop/api.json5",
# codex配置文件路径(可选)
"codexConfigPath": "~/.codex/config.toml",
# ping命令超时时间
"pingTimeout": 30000,
# test命令超时时间
"testTimeout": 100000,
# ping、test命令返回结果显示
"testResponse": true,
# 是否需要更新提示
"update": true,
# 使用use命令时是否同步修改系统环境变量
"useNoEnv": true,
# 界面语言设置 (zh: 中文, en: 英文)
"language": "zh"
}