一键配置 WeCode Codex CLI 环境的自动化工具。
- 🚀 自动安装依赖: 自动检测并安装 Node.js、npm(如需要)
- 📦 CLI 自动安装: 自动安装 OpenAI Codex CLI
- 🔧 智能配置: 自动配置 Codex CLI 连接到 WeCode API
- 🌍 环境变量管理: 自动配置环境变量到系统(支持 bash/zsh/fish/Windows)
- ⚡ 立即生效: 配置完成后当前终端窗口立即可用,无需重启
- 🖥️ 跨平台支持: 支持 macOS、Linux、WSL、Windows
从 Releases 页面下载对应平台的可执行文件:
- macOS:
wecode_setup_macos_universal(通用二进制,支持 Intel 和 Apple Silicon) - Linux ARM64:
wecode_setup_linux_arm64 - Linux AMD64:
wecode_setup_linux_amd64 - Windows AMD64:
wecode_setup_windows_amd64.exe
# 克隆仓库
git clone https://github.com/Guccbai/wecode_setup.git
cd wecode_setup
# 编译
go build -o wecode_setup
# 运行
./wecode_setup# macOS/Linux
chmod +x wecode_setup_*
./wecode_setup_macos_universal
# Windows
wecode_setup_windows_amd64.exe工具启动后,按提示输入您的 WeCode API Key(以 cr_ 开头,共 67 个字符):
======================================================================
WeCode Codex CLI 配置工具
======================================================================
📝 请输入 WeCode API Key(以 cr_ 开头),或输入 'clear' 清除配置
> cr_your_api_key_here...
工具会自动完成以下操作:
- ✅ 检测并安装 Node.js/npm(如需要)
- ✅ 配置 npm 国内镜像源(提升下载速度)
- ✅ 安装 OpenAI Codex CLI
- ✅ 配置 Codex CLI 连接到 WeCode API
- ✅ 配置环境变量
CRS_OAI_KEY(当前终端立即生效 + 持久化)
配置完成后,在当前终端即可使用:
# 验证 Codex CLI 安装
codex --version
# 验证环境变量
echo $CRS_OAI_KEY # macOS/Linux
echo %CRS_OAI_KEY% # Windows./wecode_setup
# 输入 API Key 并回车
> cr_your_api_key_here...配置文件位置:
~/.codex/config.toml: Codex CLI 配置文件~/.codex/auth.json: 认证配置文件- 环境变量自动写入:
- macOS/Linux:
~/.zshrc或~/.bashrc或~/.profile - Windows: 用户级系统环境变量
- macOS/Linux:
./wecode_setup
# 输入 clear 并回车
> clear这将删除 ~/.codex/ 目录下的所有配置文件。
工具采用双重保障策略:
- 当前进程立即生效: 使用
os.Setenv()直接设置当前终端环境变量 - 持久化配置: 写入 shell 配置文件,确保新终端自动加载
优势:
- ✅ 配置完成后当前终端立即可用,无需重启或
source - ✅ 新打开的终端窗口自动加载环境变量
- ✅ 其他已打开的终端可通过
source ~/.zshrc手动加载
工具会自动检测并安装依赖,支持以下包管理器:
- macOS: Homebrew (
brew) - Linux: apt/apt-get、dnf、yum、pacman
- Windows: winget 或 Chocolatey (
choco) - WSL: 与 Linux 相同
如果工具无法自动安装依赖,请手动安装以下软件:
- Node.js: >= 14.x(推荐 LTS 版本)
- npm: >= 6.x(通常随 Node.js 安装)
手动安装后重新运行 wecode_setup 即可。
工具自动检测并配置以下 Shell 环境:
| Shell | 配置文件 | 检测方式 |
|---|---|---|
| zsh | ~/.zshrc, ~/.zprofile |
$SHELL 环境变量 |
| bash | ~/.bashrc, ~/.bash_profile, ~/.profile |
$SHELL 环境变量 |
| fish | ~/.config/fish/config.fish |
$SHELL 环境变量 |
| 其他 | ~/.profile |
默认回退 |
- 前缀: 必须以
cr_开头 - 长度: 正好 67 个字符
- 示例:
cr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
请访问 WeCode 平台 获取您的 API Key。
⚠️ 不要将 API Key 提交到版本控制系统⚠️ 不要在公共场合分享您的 API Key⚠️ 定期轮换 API Key 以提升安全性
wecode_setup/
├── main.go # 程序入口
├── internal/
│ └── setup/
│ └── setup.go # 核心逻辑(672 行)
├── go.mod # Go 模块定义
├── README.md # 本文档
└── CLAUDE.md # 项目开发指南
# 当前平台
go build -o wecode_setup
# 跨平台编译
# macOS Universal
GOOS=darwin go build -o wecode_setup_macos_universal
# Linux ARM64
GOOS=linux GOARCH=arm64 go build -o wecode_setup_linux_arm64
# Linux AMD64
GOOS=linux GOARCH=amd64 go build -o wecode_setup_linux_amd64
# Windows AMD64
GOOS=windows GOARCH=amd64 go build -o wecode_setup_windows_amd64.exe# 运行所有测试
go test ./...
# 详细输出
go test -v ./...
# 特定包
go test ./internal/setup项目遵循 Go 标准代码风格:
# 格式化代码
go fmt ./...
# 静态检查
go vet ./...A: 可能是 npm 全局安装路径不在 $PATH 中。解决方案:
# macOS/Linux: 添加 npm 全局路径到 PATH
export PATH="$PATH:$(npm config get prefix)/bin"
# 或手动安装 Codex CLI
npm install -g @OpenAI/codex --registry https://registry.npmmirror.com/A: Windows 使用 setx 设置的环境变量需要重新打开终端窗口才能生效(新终端会话)。当前终端通过 os.Setenv() 已设置,可立即使用。
A: 直接重新运行工具并输入新的 API Key 即可,会自动覆盖旧配置。
A: 如果自动配置失败,可手动添加:
# macOS/Linux (bash)
echo 'export CRS_OAI_KEY=your_api_key' >> ~/.bash_profile
source ~/.bash_profile
# macOS/Linux (zsh)
echo 'export CRS_OAI_KEY=your_api_key' >> ~/.zshrc
source ~/.zshrc
# Windows (PowerShell 管理员模式)
[Environment]::SetEnvironmentVariable("CRS_OAI_KEY", "your_api_key", "User")A: 支持。npm 会自动读取系统代理设置。如需手动配置:
# 设置 npm 代理
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080
# 或使用环境变量
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080欢迎提交 Issue 和 Pull Request!
- 🐛 Bug 报告:请包含操作系统、Go 版本、错误日志
- 💡 功能建议:请描述使用场景和预期行为
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
本项目采用 MIT 许可证 - 详见 LICENSE 文件。
- OpenAI Codex CLI - 底层 CLI 工具
- WeCode - API 服务提供商
- 所有贡献者和用户的支持
享受便捷的 WeCode Codex CLI 配置体验! 🚀