Codex: Plan a Refactor Before Delegating It

A $plan prompt that asks Codex for a step-by-step migration plan to refactor an auth subsystem with no behaviour changes, before handing milestones to a cloud task.

  • 🤖 Codex
  • 🗂️ Coding

Last verified: write-up checked

Prompt by OpenAI · Original source (opens in a new tab)

Codex: Plan a Refactor Before Delegating It — prompt preview

The prompt

prompt
$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

What it is

From the "Delegate refactor to the cloud" workflow in OpenAI's Codex prompting docs. You design the approach locally with full context, then hand the long implementation to a cloud environment that runs in parallel. The prompt invokes the $plan skill, lists the refactor goals (split responsibilities, reduce circular imports, improve testability) and the constraints (no user-visible changes, stable public APIs, a step-by-step migration plan).

Who it's for

  • Developers planning large refactors
  • Teams using Codex cloud for long implementations

Requirements

Requirements

  • OpenAI Codex (CLI, IDE extension or cloud)

طلب $plan يطلب من Codex خطة ترحيل مرحلية لإعادة هيكلة نظام المصادقة دون تغيير السلوك، قبل تسليم المراحل لمهمة سحابية.

Examples

From the source

Prompt
prompt
$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

Expected output: Exact prompt from OpenAI prompting docs.

Follow-up from the source: negotiate the plan

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

Expected output: Also from OpenAI prompting docs.

Pros & cons

Pros

  • Pro:Separates planning from execution so you can review the plan first
  • Pro:Plan can be split into smaller cloud tasks

Cons

  • Con:Two steps instead of one; slower for trivial refactors

Tips

  • The source says to commit or stash current work first so you can compare changes cleanly
  • Planning works best when Codex can scan the code locally (entrypoints, module boundaries, dependency hints)
  • After the plan, delegate one milestone at a time, e.g. "Implement Milestone 1 from the plan."