Feature Request: Implement a "Plan Mode" for Complex Tasks
What feature would you like to see?
I would like to propose the addition of a "Plan Mode" to the codex-cli. This mode would be designed to handle complex, multi-step coding tasks by first generating a comprehensive implementation plan for user review before any code is modified or commands are executed.
This feature is inspired by the highly effective "Plan Mode" in tools like Cursor and Claude Code.
The proposed workflow would be as follows:
- Initiation: The user provides a complex prompt (e.g., "Build a dashboard on the /agents page where I can see and comment on my teammates' background agents") and activates Plan Mode, perhaps with a flag like
codex --mode plan.
- Analysis Phase (Read-Only): The agent uses read-only tools to analyze the existing codebase. It identifies relevant files, understands existing patterns (authentication, UI components, API routes), and determines the scope of the required changes. During this phase, it might ask the user clarifying questions to resolve ambiguities.
- Plan Generation: After its analysis, the agent generates a detailed, multi-step implementation plan. This plan should be presented to the user in a clear, reviewable format (e.g., as a temporary Markdown file). The plan would outline:
- An overview of the approach.
- Database schema changes and API endpoints to be created/modified.
- Frontend components to be built or altered.
- A to-do list of sequential tasks it will perform.
- User Review & Approval: The user can review this entire plan. They should have the ability to suggest edits or approve the plan as-is. This gives the user high-level control over the agent's strategy before any changes are committed.
- Autonomous Execution: Once the user approves the plan,
codex-cliseamlessly transitions into an execution phase. It then autonomously works through the to-do list from the approved plan, creating files, applying edits, and running commands without requiring per-action approval for each step.
This creates a powerful "plan and execute" workflow, which is a significant improvement over the current, more granular interactive approval model for large-scale tasks.
Additional information
Motivation:
Currently, for complex tasks, the combination of --sandbox read-only and --ask-for-approval is the safest way to operate. However, this requires the user to approve every single file modification and command execution one-by-one. This can be tedious and doesn't give the user a holistic view of the agent's strategy. A Plan Mode would solve this by front-loading the strategic decisions and approvals, allowing for much smoother execution afterward.
Key Differentiator:
The most critical aspect of this feature is the seamless transition from an approved plan to autonomous execution. This is the primary functional gap between codex-cli's current capabilities and the workflow offered by competitors. The goal is to approve a strategy, not just individual actions.
Bonus Feature Idea:
Following Cursor's implementation, the generated plan files could optionally be saved to the workspace (e.g., in a .codex/plans/ directory). This would serve as excellent documentation of the changes made and could be used for team collaboration.
7 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Here is a potential high-level architectural plan to implement the "Plan Mode" feature.
***
1. Guiding Principles & Philosophy
The core idea is not to create an entirely new execution engine but to introduce a state machine within the existing
codex-core::Sessionthat orchestrates the agent's behavior through distinct phases. The approved plan will act as a "contract" that justifies a temporary, task-specific elevation of autonomy.This approach leverages existing components (sandboxing, tool routing, TUI overlays) but reconfigures them dynamically based on the current phase of the Plan Mode workflow.
2. Architectural Phases
The workflow will be managed by a state machine within the
Sessionstruct, transitioning through the following phases:Analyzing: A read-only phase where the agent explores the codebase and formulates a plan.ReviewingPlan: The agent has submitted a plan, and the UI is awaiting user approval. The agent is idle.Executing: The user has approved the plan. The agent is granted more permissive settings to carry out the plan autonomously.3. Component-Level Implementation Plan
Phase 1: Analysis & Plan Generation (Read-Only)
codex-tui):--plan, will be added to thecodexCLI.Tuiwill initialize thecodex-core::Configto signal the start of a Plan Mode session.codex-core):Sessionwill enter theAnalyzingstate.TurnContextwill be hardcoded with restrictive, safe settings:sandbox_policy:SandboxPolicy::ReadOnlyapproval_policy:AskForApproval::OnRequest(to allow clarifying questions if the agent gets stuck).codex-core):read_fileandlist_dir.submit_plan_for_review(plan: string).codex-core):submit_plan_for_review, will be added to the tool registry.EventMsgto the TUI:EventMsg::PlanReadyForReview { plan: String }. This serves as a robust, unambiguous signal to transition to the next phase.Phase 2: User Review & Approval (TUI)
codex-tui):ChatWidgetwill listen for thePlanReadyForReviewevent.pager_overlay.rs.BottomPaneViewwith keybindings:[Y]es, proceed: Approves the plan.[N]o, cancel: Aborts the plan entirely.[E]dit instructions: (Post-MVP) Denies the current plan and drops the user back to the composer to provide feedback for regeneration.codex-tui->codex-core):Op:Op::ApprovePlan { plan: String, decision: ReviewDecision }.Phase 3: Autonomous Execution
codex-core):submission_loopincodex.rswill handle theOp::ApprovePlan.Approved, a crucial state transition occurs:Sessionstate transitions toExecuting.TurnContextis updated with more permissive settings (e.g.,sandbox_policy: WorkspaceWrite,approval_policy: Never). This dynamically grants the agent autonomy.codex-core):apply_patchandshellwith its elevated permissions.TaskComplete, and the session state returns to normal.---
Bonus Feature: Saving Plans
This can be implemented cleanly within the existing flow. When
codex-corereceives theOp::ApprovePlan, it will save the plan string to a file in a.codex/plans/directory within the user's workspace before transitioning to theExecutingstate. This requires no new protocol additions.Risks and Considerations
on-failureapproval policy might be a good model for this, even within the broaderneverapproval context of the execution phase.@thomast8 I see you're working on the plan mode already.
Please review my proposed plan above and see if it helps.
I think it will be also useful if for some planning bootstrap codex could really cooperate with PRO
https://github.com/openai/codex/issues/4863
When I'm in plan mode (read-only in codex) I'm always making sure everything is recorded to a markdown document with checklists to mark progress during the implementation phase. It would be awesome if this sort of thing was automatically done (maybe with a confirmation to opt-in/out). It really helps when breaking up larger tasks that will span multiple sessions / contexts.
Maybe even consider using something like sqlite to persist plans to memory between sessions.
That seems like quite a big change. Ho w I did it, is I used the built-in todo tool to track the plan within the conversation
I'm going to close this in favor of #2101