OpenAI Codex in VSCode
Contents
最近在Visual Studio Code上尝试了OpenAI Codex,这篇文章说说感受。
安装Codex #
在VSCode安装Extension: Codex – OpenAI’s coding agent,并登陆ChatGPT账号。同时安装Codex CLI,方便在终端操作:
brew install codexCodex的配置文件在~/.codex/config.toml.
添加MCP #
修改配置文件~/.codex/config.toml,设置超长startup_timeout_ms以免超时错误:
[mcp_servers.context7]
url = "https://mcp.context7.com/mcp"
http_headers = { "CONTEXT7_API_KEY" = "YOUR_API_KEY" }
startup_timeout_ms = 60000也可以通过命令行添加context7 MCP,
codex mcp add context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEY添加全局规则 #
Codex使用AGENTS.md配置coding agents,对应于Claude Code的CLAUDE.md。我要慢慢迁移最近使用的Cursor自定义规则 。官方指南:
1. 添加AGENTS.md #
在仓库根目录创建一个AGENTS.md文件。
2. 涵盖重要内容 #
添加能帮助agent有效处理项目的各部分。包括:
项目概述
构建和测试命令
代码风格指南
测试说明
安全注意事项
3. 添加额外说明 #
提交信息或拉取请求指南、安全隐患、大型数据集、部署步骤:任何你会告诉新团队成员的内容都应该包含在这里。
4. 大型单体仓库?为子项目使用嵌套的AGENTS.md文件 #
在每个包里放一个AGENTS.md,Agents会自动读取目录树中最近的AGENTS.md,每个子项目都可以提供定制的说明。比如,OpenAI主仓库有88个AGENTS.md文件。
5. 官方AGENTS.md示例 #
# Sample AGENTS.md file
## Dev environment tips
- Use `pnpm dlx turbo run where <project_name>` to jump to a package instead of scanning with `ls`.
- Run `pnpm install --filter <project_name>` to add the package to your workspace so Vite, ESLint, and TypeScript can see it.
- Use `pnpm create vite@latest <project_name> -- --template react-ts` to spin up a new React + Vite package with TypeScript checks ready.
- Check the name field inside each package's package.json to confirm the right name—skip the top-level one.
## Testing instructions
- Find the CI plan in the .github/workflows folder.
- Run `pnpm turbo run test --filter <project_name>` to run every check defined for that package.
- From the package root you can just call `pnpm test`. The commit should pass all tests before you merge.
- To focus on one step, add the Vitest pattern: `pnpm vitest run -t "<test name>"`.
- Fix any test or type errors until the whole suite is green.
- After moving files or changing imports, run `pnpm lint --filter <project_name>` to be sure ESLint and TypeScript rules still pass.
- Add or update tests for the code you change, even if nobody asked.
## PR instructions
- Title format: [<project_name>] <Title>
- Always run `pnpm lint` and `pnpm test` before committing.模型体验 #
VSCode的Codex集成默认是gpt-5-codex (medium),感觉确实比Cursor的gpt-5-high聪明不少。最明显的是Codex解决问题更快,human-in-the-loop步骤更少,生成的代码也更高效——这也是大家吐槽Vibe Coding最多的问题。
不过Cursor响应速度更快(可能因为我是Cursor Ultra订阅)。而且Cursor的human-in-the-loop流程做得更好,毕竟做得早有经验:可以修改任何一个历史prompt继续编码,code review时能一个个选择接受或拒绝修改。最近Cursor推出了自己的模型Composer 1,看来是想摆脱对OpenAI和Anthropic的依赖。
其他体验 #
Cursor升级到2.0后bug特别多,有时候一天更新几个版本,有一次直接把我Ubuntu系统搞死机了。Cursor生成的git commit message比较差,还不能输入意见让它改。
Cursor是基于VSCode二次开发的,但很多VSCode新功能都跟不上。比如VSCode新版本可以直接点击复制终端输出的结果,Cursor目前需要手工选,这个问题我吐槽了很久。
配额方面,Claude模型给200美元额度,但用Claude 4.1 Opus处理5700万tokens就用完了。用gpt-5-high会时不时提醒月底可能不够用,gpt-5-pro的配额基本没有。现在Claude Code国内还访问不了,我在考虑要不要从Cursor Ultra换到ChatGPT Pro.