Codex CLI 接入指南

Codex CLI 是一款命令行 AI 编程助手,支持在终端中进行代码生成和问答。

安装

使用 pip

pip install openai-codex-cli

使用 npm

npm install -g codex-cli

配置 weelinking

环境变量配置

在 shell 配置文件中添加:
# ~/.bashrc 或 ~/.zshrc
export OPENAI_API_BASE=https://api.weelinking.com/v1
export OPENAI_API_KEY=YOUR_API_KEY
使配置生效:
source ~/.bashrc  # 或 source ~/.zshrc

配置文件

创建 ~/.codex/config.json
{
  "apiBase": "https://api.weelinking.com/v1",
  "apiKey": "YOUR_API_KEY",
  "model": "gpt-4o"
}

使用方法

交互模式

codex

直接执行

codex "写一个 Python 快速排序算法"

管道输入

cat code.py | codex "解释这段代码"

功能特色

  • 代码生成:根据描述生成代码
  • 代码解释:解释代码逻辑
  • 命令行集成:与 shell 无缝协作
  • 多语言支持:支持各种编程语言

推荐模型

场景模型
代码生成gpt-5.1-codex
快速问答gpt-4o-mini
复杂任务claude-sonnet-4-5

常见问题

命令找不到

确保安装路径在 PATH 中。

API 连接失败

检查环境变量配置是否正确。