aicodewith
v1.0.1
Published
Aicodewith Activator for Claude Code & Codex
Readme
aicodewith
一个命令行激活器(bin:aicodewith):验证 API Key 后,根据接口返回的 service_type 自动为 Claude Code 或 Codex CLI 写入本地配置。
本版本的特点:验证请求地址(verify URL)可配置。
激活器逻辑(做了什么)
整体流程:
- 交互式输入
API Key(密码输入,不回显)。 - 验证
API Key:向verifyUrl发起GET请求,带Authorization: Bearer <API Key>,要求返回 JSON。 - 解析返回的
service_type:claude:激活 Claude Codecodex:激活 Codex CLI
- 展示 Key 状态/配额/有效期等信息后二次确认。
- 写入本地配置并提示重启工具生效。
Claude Code(service_type = "claude")
通过定位 Claude Code 的 @anthropic-ai/claude-code/cli.js,在文件开头(跳过 shebang/注释/空行后)注入一段环境变量设置:
// AICODEWITH_INJECTED_START
process.env.ANTHROPIC_BASE_URL="<baseUrl>/claude";
process.env.ANTHROPIC_AUTH_TOKEN="<API Key>";
// AICODEWITH_INJECTED_END如果之前已经注入过,会先移除旧的 AICODEWITH_INJECTED_START ~ AICODEWITH_INJECTED_END(以及历史的 APIGATHER_INJECTED_*)区块再写入,避免重复。
写入前会在 ~/.codex/.aicodewith_backup/ 生成 cli.js__<原目录>.bak.<时间戳> 备份(如 20201212101010),不会覆盖历史备份;恢复时选最新时间戳即可。
Codex CLI(service_type = "codex")
写入/更新 Codex 配置目录 ~/.codex/:
~/.codex/config.toml:设置model_provider = "aicodewith"并写入[model_providers.aicodewith](name="aicodewith"、base_url="<baseUrl>/codex"、wire_api="responses"、temp_env_key="AICODEWITH_API_KEY"、requires_openai_auth=true、model="gpt-5-codex"等)。~/.codex/auth.json:写入OPENAI_API_KEY与AICODEWITH_API_KEY(值均为该API Key,会覆盖原文件内容)。
同样会清理旧的同名段落/标题与旧 model_provider 行,避免重复配置。
写入前会在 ~/.codex/.aicodewith_backup/ 生成 config.toml__<原目录>.bak.<时间戳>、auth.json__<原目录>.bak.<时间戳> 备份(如 20201212101010),不会覆盖历史备份;恢复时选最新时间戳即可。
安装/运行
在本目录执行:
npm install
npm run build
node dist/index.js --help或安装为全局命令(示例):
npm install -g .
aicodewith --help构建期配置:aicodewith.config.json
验证地址用于校验 API Key,会发起:
GET <verify-url>- Header:
Authorization: Bearer <API Key>
请在仓库根目录的 aicodewith.config.json 中配置,构建时会将配置打包进 dist/index.js。
若没有该文件,构建会失败。可参考 aicodewith.config.example.json。
示例:
{
"verifyUrl": "https://example.com/user/api/v1/me",
"baseUrl": "https://example.com",
"templates": {
"claude": {
"env": [
"process.env.ANTHROPIC_BASE_URL=\"{CLAUDE_BASE_URL}\";",
"process.env.ANTHROPIC_AUTH_TOKEN=\"{API_KEY}\";"
]
},
"codex": {
"provider": "aicodewith",
"header": "# Aicodewith API 中转配置",
"configLines": [
"name = \"{PROVIDER}\"",
"base_url = \"{CODEX_BASE_URL}\"",
"wire_api = \"responses\"",
"temp_env_key = \"AICODEWITH_API_KEY\"",
"requires_openai_auth = true",
"model = \"gpt-5-codex\""
],
"auth": {
"OPENAI_API_KEY": "{API_KEY}",
"AICODEWITH_API_KEY": "{API_KEY}"
}
}
}
}可用占位符:
{API_KEY}、{VERIFY_URL}、{BASE_URL}{CLAUDE_BASE_URL}(<baseUrl>/claude){CODEX_BASE_URL}(<baseUrl>/codex){PROVIDER}(templates.codex.provider)
中转 base URL(可选)
默认会从 verify-url 的 origin 推导中转地址:
- Claude:
<origin>/claude - Codex:
<origin>/codex
如需覆盖,在 aicodewith.config.json 中设置 baseUrl 后重新构建。
打包说明
package.json的bin定义了安装后可以执行的命令 "aicodewith": "dist/index.js"
其他参数
--help/-h:显示帮助--version/-v:输出版本号
发布到 npm(维护者)
- 已配置
prepublishOnly:执行npm publish前会自动npm run build,确保dist/为编译产物。 repository/homepage/bugs等字段需要你在仓库设置好远程地址后补齐(当前本仓库未配置git remote origin)。
