当你像对待 teammate 一样给 Codex 明确 context,并清楚定义 “done” 时,Codex 效果最好。本页给出 Codex IDE extension、Codex CLI 和 Codex cloud 的 end-to-end workflow examples。
如果你刚开始使用 Codex,请先阅读 Prompting ,然后回到这里查看 concrete recipes。
如何阅读这些 examples
每个 workflow 都包括:
何时使用它,以及哪个 Codex surface 最适合(IDE、CLI 或 cloud)。
带 example user prompts 的步骤。
Context notes:Codex 自动看到什么,以及你应该 attach 什么。
Verification:如何检查 output。
Note:IDE extension 会自动把 open files 作为 context 包含进去。在 CLI 中,你通常需要明确提到 paths(或用 /mention 和 @ path autocomplete attach files)。
解释 codebase
当你正在 onboarding、接手 service,或试图理解 protocol、data model 或 request flow 时使用这个 workflow。
IDE extension workflow(本地探索最快)
打开最相关的 files。
选择你关心的 code(optional,但 recommended)。
Prompt 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 Verification:
要求生成你能快速 validate 的 diagram 或 checklist:
Summarize the request flow as a numbered list of steps. Then list the files involved. CLI workflow(适合需要 transcript + shell commands 时)
Start an interactive session:
codex Attach the files(optional),然后 prompt:
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. Context notes:
你可以在 composer 中使用 @ 从 workspace 插入 file paths,或用 /mention attach specific file。
修复 bug
当你有可以在本地 reproduce 的 failing behavior 时使用这个 workflow。
CLI workflow(围绕 reproduction 和 verification 的 tight loop)
在 repo root 启动 Codex:
codex 给 Codex reproduction recipe,以及你怀疑的 file(s):
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. Context notes:
由你提供:repro steps 和 constraints(这些比 high-level description 更重要)。
由 Codex 提供:command output、discovered call sites,以及它触发的 stack traces。
Verification:
Codex 应在 fix 后重新运行 repro steps。
如果你有 standard check pipeline,要求它运行:
After the fix, run lint + the smallest relevant test suite. Report the commands and results. IDE extension workflow
打开你认为 bug 所在的 file,以及它最近的 caller。
Prompt Codex:
Find the bug causing "Saved" to show without persisting changes. After proposing the fix, tell me how to verify it in the UI. 编写 test
当你想非常明确地限定 tested scope 时使用这个 workflow。
IDE extension workflow(基于 selection)
打开包含该 function 的 file。
选择定义该 function 的 lines。从 command palette 选择 “Add to Codex Thread”,把这些 lines 加入 context。
Prompt Codex:
Write a unit test for this function. Follow conventions used in other tests. Context notes:
由 “Add to Codex Thread” command 提供:selected lines(这是 “line number” scope),以及 open files。
CLI workflow(在 prompt 中描述 path + line range)
Start Codex:
codex 用 function name prompt:
Add a test for the invert_list function in @transform.ts. Cover the happy path plus edge cases. 从 screenshot 做 prototype
当你有 design mock、screenshot 或 UI reference,并希望快速得到 working prototype 时使用这个 workflow。
CLI workflow(image + prompt)
将 screenshot 保存到本地,例如 ./specs/ui.png。
Run Codex:
codex 把 image file 拖进 terminal,将它 attach 到 prompt。
继续补充 constraints 和 structure:
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 Context notes:
Image 会提供 visual requirements,但你仍需要指定 implementation constraints(framework、routing、component style)。
为获得最佳效果,请用 text 写出任何 non-obvious behavior(hover states、validation rules、keyboard interactions)。
Verification:
要求 Codex 在允许时运行 dev server,并明确告诉你在哪里查看:
Start the dev server and tell me the local URL/route to view the prototype. IDE extension workflow(image + existing files)
在 Codex chat 中 attach image(drag-and-drop 或 paste)。
Prompt 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. 用 live updates 迭代 UI
当你希望在 Codex edits code 时保持紧凑的 “design → tweak → refresh → tweak” loop,使用这个 workflow。
CLI workflow(运行 Vite,然后用 small prompts 迭代)
Start Codex:
codex 在单独的 terminal window 中启动 dev server:
npm run dev Prompt Codex 做 changes:
Propose 2-3 styling improvements for the landing page. 选择一个方向,并用 small、specific prompts 继续迭代:
Go with option 2. Change only the header: - make the typography more editorial - increase whitespace - ensure it still looks good on mobile 用 focused requests 重复这个过程:
Next iteration: reduce visual noise. Keep the layout, but simplify colors and remove any redundant borders. Verification:
当 code 更新时,在 browser 中 “live” review changes。
Commit 你喜欢的 changes,revert 你不喜欢的 changes。
如果你 revert 或 modify 了某个 change,要告诉 Codex,避免它在下一个 prompt 中 overwrite 该 change。
将 refactor 委派到 cloud
当你希望先 carefully design(local context、quick inspection),再把较长 implementation outsource 给可以并行运行的 cloud task 时,使用这个 workflow。
Local planning(IDE)
确保当前 work 已 committed,或至少 stashed,这样你可以 cleanly compare changes。
要求 Codex 产出 refactor plan。如果你有 $plan skill 可用,请明确 invoke 它:
$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 Review the plan,并 negotiate changes:
Revise the plan to: - specify exactly which files move in each milestone - include a rollback strategy Context notes:
当 Codex 可以在本地 scan current code(entrypoints、module boundaries、dependency graph hints)时,planning 效果最好。
Cloud delegation(IDE -> Cloud)
如果还没有设置,请先 set up Codex cloud environment 。
点击 prompt composer 下方的 cloud icon,并选择你的 cloud environment。
输入下一个 prompt 时,Codex 会在 cloud 中创建 new thread,并 carry over existing thread context(包括 plan 和任何 local source changes)。
Implement Milestone 1 from the plan. Review cloud diff,必要时继续 iterate。
直接从 cloud 创建 PR,或把 changes pull 到本地 test 并 finish up。
继续 iterate plan 的 additional milestones。
做 local code review
当你希望在 committing 或 creating PR 前获得 second set of eyes 时,使用这个 workflow。
CLI workflow(review your working tree)
Start Codex:
codex 运行 review command:
/review Optional:提供 custom focus instructions:
/review Focus on edge cases and security issues Verification:
根据 review feedback apply fixes,然后重新运行 /review,确认 issues 已 resolved。
Review GitHub pull request
当你希望不把 branch pull 到本地也获得 review feedback 时,使用这个 workflow。
使用前,你需要在 repository 上 enable Codex Code review 。参见 Code review 。
GitHub workflow(comment-driven)
在 GitHub 上打开 pull request。
留下 comment,用 explicit focus areas tag Codex:
@codex review Optional:提供更 explicit 的 instructions。
@codex review for security vulnerabilities and security concerns 更新 documentation
当你需要 accurate 且 clear 的 doc change 时,使用这个 workflow。
IDE 或 CLI workflow(local edits + local validation)
识别要 change 的 doc file(s),并打开它们(IDE),或 @ mention 它们(IDE 或 CLI)。
用 scope 和 validation requirements prompt Codex:
Update the "advanced features" documentation to provide authentication troubleshooting guidance. Verify that all links are valid. Codex draft changes 后,review documentation,并按需 iterate。
Verification:
阅读 rendered page。