Glean 拾遗
日刊 /2026-08-02 / OpenAI 自家工程师怎么用 Codex:七个用例与六条工作流实践

OpenAI 自家工程师怎么用 Codex:七个用例与六条工作流实践

原文 openai.com 收录 2026-08-02 06:00 阅读 14 min
AI 解读

OpenAI 发布官方指南,介绍其安全、前端、API、基础设施等团队如何在日常开发中使用 Codex。文章覆盖七个场景:代码理解、重构迁移、性能优化、补测试、提速、保持专注、探索构思,并给出示例提示词。最具操作性的是六条最佳实践:大规模改动先从询问模式获取方案再切执行模式;维护 AGENTS.md 提供持续上下文;像写 GitHub Issue 一样组织提示(附文件路径、代码差异);把 Codex 任务队列当简易清单;用 Best of N 对比多份输出。文中引用了多位工程师的使用感言,如“用 Codex 替换全部旧版 getUserById() 并生成 PR”“夜间让 Codex 处理低覆盖模块,次日得到可运行单元测试 PR”。适合正在评估或已上手 Codex 的团队,也提供可直接复制的提示词模板。注意这是官方发布视角,缺少失败案例与量化收益数据。

原文 14 分钟
原文 openai.com ↗
§ 1

Codex is used daily by many of OpenAI's technical teams, including security, product engineering, frontend, API, infrastructure, and performance engineering. Teams rely on it to accelerate engineering work across the board—from understanding complex systems and refactoring large codebases to shipping new features and resolving incidents under tight deadlines.

Through interviews with OpenAI engineers and analysis of internal usage data, we've compiled a set of use cases and best practices that show how Codex helps teams work more efficiently, produce higher-quality work, and manage complexity at scale.

Codex 被 OpenAI 的众多技术团队日常使用,包括安全、产品工程、前端、API、基础设施和性能工程团队。团队正借助它加速各类工程任务,从理解复杂系统、重构大型代码库,到交付新功能以及在紧迫期限内解决故障。

通过访谈 OpenAI 工程师并分析内部使用数据,我们整理了一系列使用场景和最佳实践,展示了 Codex 如何帮助团队提升工作效率、提高工作质量,并规模化管理复杂性。

§ 2

Codex helps our teams quickly get familiar with unfamiliar parts of the codebase when onboarding, debugging, or troubleshooting incidents.

They often use Codex to locate the core logic of a feature, map relationships between services or modules, and trace how data flows through the system. It also surfaces architecture patterns or documentation gaps that would otherwise require considerable manual effort to piece together.

During incident response, Codex helps engineers get up to speed on unfamiliar territory by showing how components interact and tracing how failure states propagate through the system.

What a team member says

Whenever I fix a bug, I use ask mode to check whether the same kind of issue exists elsewhere in the codebase.

— Performance engineer, Search

Example prompts for code understanding with Codex:
  • Where is the authentication logic implemented in this repository?
  • Walk through the complete flow of a request in this service, from entry to response.
  • Which modules interact with [module name], and how are exceptions handled?

Codex 可帮助我们的团队在入职上手、调试或排查故障时,快速熟悉代码库中不熟悉的部分。

他们经常使用 Codex 定位功能的核心逻辑,梳理服务或模块之间的关系,并追踪数据在系统中的流转过程。它还能识别出架构模式或文档缺失部分,这些内容原本需要投入大量人力才能整理完成。

在事件响应过程中,Codex 通过呈现组件间的交互关系、追踪故障状态在系统中的传播路径,帮助工程师快速熟悉新领域。

团队真实使用感言

每当修复一个漏洞, 我都会使用询问模式,检查代码库中是否还存在同类问题

—— 检索系统性能工程师

尝试使用 Codex 进行代码理解,可参考这些示例提示词:
  • 此仓库中的身份验证逻辑是在哪里实现的?
  • 梳理请求在本服务中,从入口到响应的完整流转流程。
  • 哪些模块与[插入模块名称]存在交互,异常故障又是如何处理?
§ 3

Codex is often used for changes that span multiple files or packages. When engineers update an API, change how a pattern is implemented, or migrate to new dependencies, Codex can perform the update cleanly and consistently.

The tool is especially useful when the same update needs to be made across dozens of files, or when the change requires recognizing structures and dependencies that regex or find-and-replace can't easily capture.

Teams also use it for code cleanup: splitting oversized modules, replacing legacy patterns with modern equivalents, or reworking code to make it more testable.

What a team member says

Codex replaced all the legacy getUserById() calls with our new service pattern and opened a PR. What used to take hours now takes minutes.

— Backend engineer, ChatGPT Web

Example prompts for refactoring and migration:
  • Split this file into separate modules by business responsibility, and generate tests for each module.
  • Convert all callback-based database access to async/await.

Codex 常用于执行跨多个文件或软件包的修改操作。例如,在工程师更新 API、修改模式实现方式或迁移至新依赖项时,Codex 可以轻松统一地完成修改。

当需要在数十个文件中执行相同更新,或更新需要识别正则表达式、查找替换无法轻松捕捉的结构和依赖关系时,该工具尤为实用。

他们还使用它进行代码清理,包括拆分超大模块、用现代模式替换旧模式,或优化代码以提升可测试性。

团队真实使用感言

Codex 将所有旧版 getUserById() 替换为我们的新服务模式,并创建了 PR。原本需要数小时的工作,如今只需几分钟。

—— ChatGPT 网页版后端工程师

尝试使用 Codex 进行重构和迁移,可参考这些示例提示词:
  • 按业务职责拆分当前文件为独立模块,并为各模块生成对应测试。
  • 将所有基于回调的数据库访问转换为 async/await。
§ 4

Codex is used to identify and resolve performance bottlenecks.

In tuning or reliability work, engineers prompt Codex to analyze slow, memory-intensive code paths—inefficient loops, redundant operations, high-cost queries—and suggest optimized alternatives, often delivering significant gains in efficiency and reliability.

Codex also helps keep code healthy by flagging high-risk or deprecated patterns that are still in use. Our teams use it to reduce long-term technical debt and proactively prevent regressions.

What a team member says

I use Codex to scan for repeated, expensive database calls. It pinpoints the hot paths and generates batched queries for me to tune further.

— Infrastructure engineer, API Reliability

Example prompts for performance optimization:
  • Optimize this loop for memory efficiency and explain why your version is faster.
  • Find repeated high-cost operations in this request handler and suggest caching optimizations.
  • Suggest a more efficient way to batch database queries in this function.

Codex 用于识别并解决性能瓶颈问题。

在调优或可靠性优化工作中,工程师会提示 Codex 分析运行缓慢、内存密集型的代码路径(如低效循环、冗余操作、高开销查询),并建议优化后的替代方案,通常能够显著提升效率和可靠性。

Codex 还可通过识别仍在使用的高风险或已弃用模式,保障代码健康。我们的团队借助它减少长期技术债,并主动预防回归问题。

团队真实使用感言

我用 Codex 扫描代码中重复的高开销数据库调用。它能够精准识别热点路径,并生成批量查询语句,方便我后续进行调优。

—— API 可靠性基础设施工程师

试用 Codex 进行性能优化,可参考这些示例提示词:
  • 优化此循环以提高内存效率,并说明你的版本更快的原因。
  • 找出此请求处理程序中的重复高开销操作,并给出可使用缓存的优化建议。
  • 建议在此函数中更高效地批量查询数据库的方法。
§ 5

Codex helps engineers write tests faster, especially where coverage is thin or missing entirely.

When fixing a bug or refactoring, engineers often ask Codex for test suggestions that cover edge cases and potential failure paths. For new code, it can generate unit or integration tests from function signatures and surrounding logic.

Codex is particularly good at identifying boundary conditions—empty inputs, maximum lengths, or unusual but valid states—that are easy to miss in initial tests.

What a team member says

I asked Codex to work on under-covered modules overnight, and by morning I had a PR with ready-to-run unit tests.

— Frontend engineer, ChatGPT Desktop

Example prompts for using Codex to improve test coverage:
  • Write unit tests for this function, covering edge cases and failure paths.
  • Generate property-based tests for this sorting utility.
  • Extend the test file to cover missing scenarios like empty input and invalid states.

Codex 可帮助工程师更快编写测试,尤其适用于测试覆盖率不足或完全缺失的场景。

在修复漏洞或进行重构时,工程师通常会让 Codex 提供覆盖边界情况和潜在异常路径的测试建议。对于新代码,它可以根据函数签名和周边逻辑生成单元测试或集成测试。

Codex 尤其擅长识别边界条件,例如空输入、最大长度或不常见但合法的状态,这些情况在初始测试中极易被忽略。

团队真实使用感言

我夜间让 Codex 处理覆盖率偏低的代码模块,第二天醒来就能拿到可直接运行的单元测试 PR。

—— ChatGPT 桌面版前端工程师

试用 Codex 提升测试覆盖率,可参考这些示例提示词:
  • 为此函数编写单元测试,覆盖边界场景与失败路径。
  • 为该排序工具生成基于属性的测试。
  • 扩充测试文件,以补充空输入与无效状态等缺失场景。
§ 6

Codex helps teams increase development velocity by speeding up both the early and final phases of the development cycle.

When starting a new feature, engineers use it to scaffold boilerplate—generating folders, modules, and API stubs—so they can get runnable code quickly without wiring everything by hand.

As a project nears release, Codex handles the small but critical tasks that keep delivery on schedule: triaging bugs, filling in remaining implementation gaps, and generating release scripts, telemetry hooks, and config files.

It can also turn product feedback into initial code. Engineers often paste user requirements or specs, let Codex produce a first draft, and then refine it themselves.

ChatGPT Enterprise internal tooling

I was in meetings all day and still merged four PRs, thanks to Codex handling the work in the background.

— Product engineer, ChatGPT Enterprise

Example prompts for using Codex to move faster:
  • Set up a new API route for POST /events, with basic validation and logging.
  • Use this template [paste your telemetry code sample] to generate a telemetry hook that tracks success/failure for the new onboarding flow.
  • Create a stub implementation based on this spec: [paste spec or product feedback].

Codex 通过加快开发周期前期与收尾阶段的效率,帮助团队提升开发速度。

在启动新功能开发时,工程师用它搭建样板代码框架,包括生成文件夹、模块和 API 存根,快速产出可运行代码,无需手动逐一配置关联。

随着项目临近发布,Codex 可处理各类细碎但关键的工作,助力按期交付,例如分类排查漏洞、补齐收尾开发缺口,以及生成发布脚本、遥测钩子和配置文件。

它还可以将产品需求反馈转化为初始代码。工程师常会粘贴用户需求或规格说明,让 Codex 生成代码初稿,后续再自行完善优化。

ChatGPT Enterprise 内部工具

我一整天都在开会,依旧合并了 4 个 PR,全靠 Codex 在后台自动处理工作。

—— ChatGPT Enterprise 产品工程师

你可以使用以下示例提示词,借助 Codex 提升开发速度:
  • 为 POST /events 搭建新的 API 路由,并添加基础验证和日志记录。
  • 使用此模板 [插入你的遥测代码示例] 生成一个遥测钩子,用于跟踪新引导流程的成功/失败状态。
  • 根据此规范创建一个存根实现:[插入规范或产品反馈]。
§ 7

Codex helps engineers stay productive even with fragmented schedules and constant interruptions.

It can capture unfinished work, turn notes into runnable prototypes, or break out exploratory tasks that can be revisited and continued later. This makes it easy to pause and resume work without losing context—especially useful for on-call shifts or meeting-heavy days.

ChatGPT API infrastructure observability

When there's a quick fix to make, I just send the task to Codex instead of switching branches myself, then review the PR it opens when I have time.

— Backend engineer, ChatGPT API

Codex 能帮助工程师在日程零散、频繁被打断的情况下,维持稳定工作效率。

它可用于记录未完成的工作、将笔记转化为可运行的原型,或拆分出可在日后再查看和继续处理的探索性任务。方便工程师在不丢失上下文的前提下暂停和接续工作,尤其适合值班或会议较多的场景。

ChatGPT API 基础设施可观测性

遇到随手小修复需求时,我直接下发 Codex 任务,无需手动切换分支,空闲时审核它生成的 PR 即可。

—— ChatGPT API 后端工程师

§ 8

Codex also works well for open-ended tasks, like exploring alternative implementation approaches or validating design decisions. You can ask it for multiple solution angles, explore unfamiliar development patterns, or stress-test assumptions. That helps surface trade-offs, broaden design options, and settle on the right implementation.

It can also be used to hunt for related bugs. Given a known issue or deprecated method, Codex can find similar patterns elsewhere in the codebase, making it easier to catch regressions and clean things up.

ChatGPT Desktop / Search

Codex helped me get past the cold-start problem—I paste in a spec and docs, and it generates a code skeleton or points out what I missed.

— Product engineer, ChatGPT Desktop

Example prompts for exploration and ideation:
  • How would this system work if it were event-driven instead of request/response?
  • Find all modules that build SQL strings manually instead of using our query builder.
  • Rewrite this code in a more standard functional style, avoiding mutation and side effects.

Codex 同样适用于开放性工作,例如寻找替代实现方案、验证设计决策。你可以提示它给出多种解题思路、探索陌生开发模式,或是对各类假设进行压力验证。这有助于梳理方案取舍、拓宽设计选择,敲定合适的实现方式。

它还可用来排查关联漏洞。针对已知问题或已弃用方法,Codex 能够识别代码中其他相似写法,便于及时发现回归问题、完成代码清理。

ChatGPT 桌面版 检索系统

Codex 帮助我解决了冷启动问题——我粘贴一份规格说明和文档,它就会生成代码框架,或者指出我遗漏的地方。

—— ChatGPT 桌面版产品工程师

可以参考这些示例提示词,使用 Codex 进行探索和创意构思:
  • 如果系统采用事件驱动而不是请求/响应模式,它会如何运作?
  • 找出所有手动构建 SQL 字符串而非使用我们的查询构建器的模块。
  • 将代码改写为更标准的函数式风格,避免数据变更与副作用。
§ 9

Codex performs best when it's given a clear framework, context, and room to iterate. These are the habits OpenAI teams have settled on to get consistent value from Codex in day-to-day work.

为 Codex 提供清晰框架、上下文和迭代空间,就能发挥出最佳效果。以下是 OpenAI 团队总结的使用习惯,可在日常工作中持续稳定发挥 Codex 的价值。

§ 10

Start in ask mode for large changes: request an implementation plan, then switch to code mode and use that plan as the reference for subsequent prompts. This two-step flow makes Codex's output more grounded and reduces errors. Codex works best on well-scoped tasks—the kind you or a colleague would spend about an hour on, or that require writing a few hundred lines of code. As model performance improves, the size of tasks it can take on will grow.

对于大规模改动,先在询问模式下向 Codex 发起请求获取实施方案,切换到代码模式后,即可将该方案作为后续提示的参考依据。这种两步式流程能让 Codex 的输出更贴合实际,有助于减少结果中的错误。Codex 最适合范围清晰的任务,这类任务一般由你或同事耗时约一小时完成,或是需要编写几百行代码实现。随着模型性能持续优化,它能够承接的任务体量也会随之增大。

§ 11

Configuring startup scripts, environment variables, and network access can significantly reduce the chance of Codex making mistakes. While it's working, watch for build errors that can be fixed by adjusting Codex's environment. This may take several rounds of iteration and debugging, but the long-term efficiency gains are substantial.

配置启动脚本、环境变量以及网络访问权限,能够显著降低 Codex 的出错概率。在执行任务过程中,留意可通过调整 Codex 环境配置来修复的构建错误。这一过程可能需要多轮迭代调试,但从长期使用来看,能够带来可观的效率提升。

§ 12

Write prompts the way you'd describe a code change in a PR or issue, and Codex will respond better. That means including file paths, component names, code diffs, and documentation snippets when necessary. Phrasing like “implement this feature the same way [module X] does” improves the generated result.

按照在 PR 或 Issue 中描述代码变更的口吻编写提示,Codex 的回复效果会更好。这意味着要在必要时附上文件路径、组件名称、代码差异和文档片段。使用“参照 [module X] 模块的方式实现该功能”这类句式,能够优化生成效果。

§ 13

Use the Codex task queue as a lightweight to-do list. Spin up tasks anytime to capture stray ideas, unfinished work, or quick fixes. Don't force every task to produce a complete PR. Treat Codex as a staging area where work waits until you can give it your full attention again.

随时新建任务,用来记录零散想法、未完成工作或是临时的小修复。无需强求一次性生成完整 PR。Codex 可作为工作暂存区,方便你恢复专注后继续处理。

§ 14

Maintain an AGENTS.md file to help Codex work effectively across prompts in a codebase. The file typically captures naming conventions, business logic, special rules, and dependencies that Codex can't infer from code alone. Check the official docs for guidance on how to write AGENTS.md.

维护 AGENTS.md 文件,帮助 Codex 在代码仓库中在不同提示下保持高效运行。该文件通常包含仅凭代码无法让 Codex 自行推断的命名规范、业务逻辑、特殊规则以及依赖关系。可查阅官方文档,了解 AGENTS.md 文件的编写规范。

§ 15

Use Best-of-N to improve outputs. The Best-of-N feature generates multiple results for the same task in one go, so you can quickly compare options and pick the best one. For more complex tasks, review multiple generations and combine the strongest parts of each into a better final result.

Best-of-N 功能支持为同一任务一次性生成多份结果,便于快速比对多种方案并择优选用。对于更复杂的任务,你可以参考多轮生成内容,整合不同结果的优势部分,形成更完善的方案。

§ 16

Codex is still in research preview, but it has already changed how we build software—speeding up development, helping us write better code, and taking on work that used to be hard to schedule.

We're excited about the potential ahead. As the model keeps improving and Codex becomes more deeply embedded in our workflows, we look forward to unlocking new and more powerful ways to build software. We'll keep sharing what we learn along the way.

Codex 目前仍处于研究预览阶段,但已切实改变研发模式,帮助我们加快开发节奏、编写更优质代码,同时承接以往难以排期的工作。

我们对未来的发展潜力充满期待——随着模型持续迭代优化,Codex 进一步深度融入工作流程,我们期待依托它解锁更多更强大的软件开发方式。我们将持续分享一路积累的经验与心得。

打开原文 ↗