OpenAI Codex 命令速查

OpenAI Codex CLI 命令在线速查:涵盖代码生成、审查、测试、配置管理等常用命令,点击命令即可复制。

未找到匹配的命令,请尝试其他关键词

会话管理

操作命令
启动交互模式codex
单次执行codex exec "你的指令"
继续会话codex resume
列出会话codex sessions
清除会话codex sessions clear
查看版本codex --version
显示帮助codex --help

代码生成

操作命令
生成函数codex generate "实现快速排序函数"
生成类codex generate "创建 User 类,包含 name 和 email"
生成 APIcodex generate "创建 REST API 端点 /users"
生成数据库模型codex generate "创建 Product 数据库模型"
生成前端组件codex generate "创建 React 登录表单组件"
指定语言codex generate --lang python "实现二分查找"
指定框架codex generate --framework django "创建视图"

代码审查

操作命令
审查文件codex review path/to/file.py
审查目录codex review ./src/
审查 Git 差异codex review --diff
检查代码质量codex review --quality path/to/file.js
检查安全漏洞codex review --security path/to/file.py
检查性能问题codex review --performance path/to/file.go
生成审查报告codex review --report ./src/ > review.md

测试生成

操作命令
生成单元测试codex test path/to/function.py
生成集成测试codex test --integration path/to/api.py
生成测试用例codex test --cases "calculate_total 函数"
指定测试框架codex test --framework pytest path/to/file.py
生成 mockcodex test --mock path/to/service.py
覆盖率分析codex test --coverage ./tests/

配置管理

操作命令
查看配置codex config show
设置 API Keyexport OPENAI_API_KEY=your_key
设置模型codex config set model gpt-4-turbo
设置温度codex config set temperature 0.3
设置输出格式codex config set output_format json
重置配置codex config reset
配置文件路径~/.codex/config.yaml

故障排查

① API 速率限制

根因:请求频率过高 · 解法:等待或升级 API 套餐
操作命令
查看限额codex quota
降低频率codex config set rate_limit 10

② 生成代码不完整

根因:max_tokens 设置过低 · 解法:增加 token 限制
操作命令
增加限制codex config set max_tokens 8192

③ 代码质量不佳

根因:提示词不够清晰 · 解法:提供更详细的上下文
操作命令
添加上下文codex generate --context "使用 TypeScript + Express"

④ 网络连接超时

根因:网络不稳定或防火墙拦截 · 解法:检查网络或配置代理
操作命令
测试连接curl https://api.openai.com
设置代理export HTTPS_PROXY=http://proxy:port
您的足迹: