主导航

工作流

Codex 的开发使用模式

当你将 Codex 视为一名拥有明确背景知识和清晰“完成”定义的队友时,它的效果最佳。本页面提供了针对 Codex IDE 扩展、Codex CLI 和 Codex 云端开发的全流程工作流示例。

如果你是 Codex 的新用户,请先阅读提示词技巧 (Prompting),然后再回到这里查看具体方案。

如何阅读这些示例

每个工作流包括:

  • 适用场景:以及最适合的 Codex 平台(IDE、CLI 或云端)。
  • 步骤:包含用户提示词示例。
  • 上下文说明:Codex 自动获取的内容与你需要手动附加的内容。
  • 验证:如何检查输出结果。

注意: IDE 扩展会自动将你打开的文件包含在上下文中。在 CLI 中,通常需要明确提及路径(或使用 /mention@ 路径自动补全功能来附加文件)。


解析代码库

适用于:入职上手、接手已有服务,或试图梳理协议、数据模型及请求流程时。

IDE 扩展工作流(本地探索最快)

  1. 打开最相关的文件。

  2. 选择你关注的代码(可选,但推荐)。

  3. 提示 Codex。

    Explain how the request flows through the selected code.
    
    Include:
    - a short summary of the responsibilities of each module involved
    - what data is validated and where
    - one or two "gotchas" to watch for when changing this

验证。

  • 要求提供可快速验证的图表或清单。
Summarize the request flow as a numbered list of steps. Then list the files involved.

CLI 工作流(适用于需要记录副本 + shell 命令的情况)

  1. 开始交互式会话。

    codex
  2. 附加文件(可选)并提示。

    I need to understand the protocol used by this service. Read @foo.ts @schema.ts and explain the schema and request/response flow. Focus on required vs optional fields and backward compatibility rules.

上下文说明

  • 你可以在编辑器中使用 @ 插入工作区的文件路径,或使用 /mention 附加特定文件。

修复 Bug

适用于:当你有一个可以在本地复现的故障行为时。

CLI 工作流(包含复现和验证的紧密循环)

  1. 在仓库根目录启动 Codex。

    codex
  2. 为 Codex 提供复现方案,以及你怀疑的文件。

    Bug: Clicking "Save" on the settings screen sometimes shows "Saved" but doesn't persist the change.
    
    Repro:
    1) Start the app: npm run dev
    2) Go to /settings
    3) Toggle "Enable alerts"
    4) Click Save
    5) Refresh the page: the toggle resets
    
    Constraints:
    - Do not change the API shape.
    - Keep the fix minimal and add a regression test if feasible.
    
    Start by reproducing the bug locally, then propose a patch and run checks.

上下文说明

  • 由你提供:复现步骤和约束条件(这些比高层描述更重要)。
  • 由 Codex 提供:命令输出、发现的调用位置以及触发的任何堆栈跟踪信息。

验证。

  • 修复后,Codex 应重新运行复现步骤。
  • 如果你有标准的检查流程,请要求它运行该流程。
After the fix, run lint + the smallest relevant test suite. Report the commands and results.

IDE 扩展工作流

  1. 打开你认为存在 Bug 的文件,及其最近的调用者。

  2. 提示 Codex。

    Find the bug causing "Saved" to show without persisting changes. After proposing the fix, tell me how to verify it in the UI.

编写测试

适用于:当你想要明确定义要测试的范围时。

IDE 扩展工作流(基于选择)

  1. 打开包含该函数的文件。

  2. 选中定义该函数的行。从命令面板选择“添加到 Codex 线程 (Add to Codex Thread)”,将这些行添加到上下文中。

  3. 提示 Codex。

    Write a unit test for this function. Follow conventions used in other tests.

上下文说明

  • 由“添加到 Codex 线程”命令提供:选定的行(即“行号”范围),以及打开的文件。

CLI 工作流(提示词中描述路径 + 行范围)

  1. 启动 Codex。

    codex
  2. 使用函数名进行提示。

    Add a test for the invert_list function in @transform.ts. Cover the happy path plus edge cases.

基于截图制作原型

适用于:当你拥有设计稿、截图或 UI 参考,并希望快速获得可用原型时。

CLI 工作流(图片 + 提示词)

  1. 将截图保存在本地(例如 ./specs/ui.png)。

  2. 运行 Codex。

    codex
  3. 将图片文件拖入终端以附加到提示词中。

  4. 跟进约束条件和结构要求。

    Create a new dashboard based on this image.
    
    Constraints:
    - Use react, vite, and tailwind. Write the code in typescript.
    - Match spacing, typography, and layout as closely as possible.
    
    Deliverables:
    - A new route/page that renders the UI
    - Any small components needed
    - README.md with instructions to run it locally

上下文说明

  • 图片提供了视觉要求,但你仍需指定实现约束(框架、路由、组件样式)。
  • 为了获得最佳结果,请通过文字说明非显而易见的行为(悬停状态、验证规则、键盘交互)。

验证。

  • 要求 Codex 运行开发服务器(如果允许),并告诉你要去哪里查看。
Start the dev server and tell me the local URL/route to view the prototype.

IDE 扩展工作流(图片 + 现有文件)

  1. 在 Codex 聊天中附加图片(拖放或粘贴)。

  2. 提示 Codex。

    Create a new settings page. Use the attached screenshot as the target UI.
    Follow design and visual patterns from other files in this project.

通过实时更新迭代 UI

适用于:当你想要在 Codex 编辑代码时,进行“设计 → 调整 → 刷新 → 调整”的紧密循环。

CLI 工作流(运行 Vite,然后通过短提示词迭代)

  1. 启动 Codex。

    codex
  2. 在单独的终端窗口中启动开发服务器。

    npm run dev
  3. 提示 Codex 进行更改。

    Propose 2-3 styling improvements for the landing page.
  4. 明确方向并通过简短、具体的提示词进行迭代。

    Go with option 2.
    
    Change only the header:
    - make the typography more editorial
    - increase whitespace
    - ensure it still looks good on mobile
  5. 重复聚焦请求。

    Next iteration: reduce visual noise.
    Keep the layout, but simplify colors and remove any redundant borders.

验证。

  • 随着代码更新,在浏览器中“实时”查看更改。
  • 提交你满意的更改,并撤销你不满意的部分。
  • 如果你撤销或修改了更改,请告知 Codex,以便它在执行下一个提示时不会覆盖该更改。

将重构任务委托给云端

适用于:当你想要仔细设计(本地上下文、快速检查),然后将长时间的实施工作外包给云端任务并行处理时。

本地规划(IDE)

  1. 确保你当前的工作已提交或至少已隐藏(stash),以便可以清晰地比较更改。

  2. 要求 Codex 制定重构计划。如果你有 $plan 技能,请显式调用它。

    $plan
    
    We need to refactor the auth subsystem to:
    - split responsibilities (token parsing vs session loading vs permissions)
    - reduce circular imports
    - improve testability
    
    Constraints:
    - No user-visible behavior changes
    - Keep public APIs stable
    - Include a step-by-step migration plan
  3. 审查计划并协商更改。

    Revise the plan to:
    - specify exactly which files move in each milestone
    - include a rollback strategy

上下文说明

  • 当 Codex 能在本地扫描现有代码(入口点、模块边界、依赖关系图提示)时,规划效果最好。

云端委托(IDE → 云端)

  1. 如果你还没有设置,请配置一个 Codex 云环境

  2. 点击提示编辑器下方的云图标,选择你的云环境。

  3. 当你输入下一个提示时,Codex 会在云端创建一个新线程,并携带现有的线程上下文(包括计划和任何本地源代码更改)。

    Implement Milestone 1 from the plan.
  4. 审查云端差异 (diff),必要时进行迭代。

  5. 直接从云端创建 PR,或者将更改拉取到本地进行测试和收尾。

  6. 对计划的额外里程碑进行迭代。


进行本地代码审查

适用于:在提交或创建 PR 之前想要寻求第二意见时。

CLI 工作流(审查你的工作区)

  1. 启动 Codex。

    codex
  2. 运行审查命令。

    /review
  3. 可选:提供自定义的重点说明。

    /review Focus on edge cases and security issues

验证。

  • 根据审查反馈应用修复,然后重新运行 /review 以确认问题已解决。

审查 GitHub Pull Request

适用于:在不将分支拉取到本地的情况下获取审查反馈时。

在使用此功能之前,请在你的存储库中启用 Codex 代码审查 (Code review)。参见 代码审查

GitHub 工作流(评论驱动)

  1. 在 GitHub 上打开 Pull Request。

  2. 留下评论,标记 Codex 并明确关注领域。

    @codex review
  3. 可选:提供更明确的说明。

    @codex review for security vulnerabilities and security concerns

更新文档

适用于:当你需要进行准确且清晰的文档更改时。

IDE 或 CLI 工作流(本地编辑 + 本地验证)

  1. 识别要更改的文档文件并打开它们(IDE)或使用 @ 提及它们(IDE 或 CLI)。

  2. 提示 Codex 明确范围和验证要求。

    Update the "advanced features" documentation to provide authentication troubleshooting guidance. Verify that all links are valid.
  3. 在 Codex 起草更改后,审查文档并根据需要进行迭代。

验证。

  • 阅读渲染后的页面。
© . This website operates independently and is not affiliated with or endorsed by OpenAI, Inc. All brand names, logos, and trademarks are the property of their respective owners.