Skip to content

Run your first Codex task

A first Codex task runs an open-ended prompt across all four surfaces: the ChatGPT desktop app, the CLI, the IDE extension, and Cloud environments. Each surface follows the same cycle of exploration, analysis, implementation, and testing, powered by models such as GPT-5.6 Sol and GPT-6 Astra, while differing in how progress renders, how approvals gate tool execution, and how code diffs are reviewed.

This guide is for developers executing their first multi-file task with OpenAI Codex. You will discover error handling gaps, implement fixes, run tests, and evaluate surface-specific features. For team-wide lifecycle integration, see Build.

  • Complete an end-to-end task spanning prompt input, sandboxed execution, and diff review.
  • Run the identical prompt across the Desktop App, CLI, IDE extension, and Cloud environments.
  • Understand how approval policies, git worktrees, and sandbox boundaries shape execution.
  • Deploy reusable prompt templates for error hunting, refactoring, and feature additions.

This walkthrough uses a real-world task required in every production project: locate an error handling gap in your API routes, implement a fix, and verify it with a dedicated automated test. This exercise tests repository reading, AST analysis, code generation, sandboxed command execution, and git status tracking.

Use the following prompt:

Find an error handling gap in this project's API routes: a place where an
exception could crash the server or return a misleading response. Fix it with
proper error handling and add a test that proves the fix works. Run the tests
to confirm they pass.

The prompt is deliberately outcome-oriented. Codex must explore your codebase, identify a concrete issue, implement the fix, and validate execution. If your project lacks API routes, adjust the prompt to target your business logic layer.

To execute the task in the desktop application:

  1. Open the ChatGPT desktop app in Codex mode and select your project directory.

  2. Click New Thread. Select Worktree to isolate changes in a dedicated git worktree, or Local to modify your working directory directly.

  3. Paste the prompt into the composer and press Enter.

  4. Monitor execution. The app streams real-time status updates showing file reads, AST analysis, file edits, and test command execution. With workspace-write and on-request approvals, modifications within the workspace execute automatically without manual confirmations.

  5. When execution completes, open the Review pane to inspect the file diff.

  6. Use the integrated terminal (Cmd+J) to verify test output and inspect generated files.

Desktop app capabilities:

  • Parallel threads: Launch concurrent threads across independent worktrees without branch collisions.
  • Worktree isolation: Changes remain in a isolated git worktree, leaving your primary branch clean.
  • Voice input: Hold Ctrl+M to dictate prompts directly.
  • Completion notifications: System alerts notify you when background operations finish.

Across all surfaces, Codex executes tasks in five structured stages:

  1. Exploration: Codex inspects repository structure, reads configuration files, and maps code dependencies.

  2. Analysis: It searches for missing error boundaries, evaluating exception handlers against framework standards.

  3. Implementation: Codex edits files, adding input validation, try-catch blocks, or custom error wrappers.

  4. Testing: It creates or updates test specifications and executes the test runner in the sandbox.

  5. Summary: Codex outputs a summary detailing the identified gap, modified files, and test results.

The precision of execution depends on your repository’s AGENTS.md file. Documenting your package manager, test runner command (pnpm vitest run), and architectural boundaries prevents the model from relying on assumptions.

Use the following templates for common development workflows:

The following table summarizes recommended surfaces by task type:

Task typeRecommended surfaceRationale
Quick bug fix in one fileCLI or IDE ExtensionMinimal context switching and fast turnaround.
Multi-file refactorDesktop App (Worktree mode)Clean branch isolation and parallel session support.
Long-running migrationCloud environmentsBackground execution on independent compute.
Pull request automationCloud + GitHub connectorDirect PR generation and automated summaries.
Interactive debuggingCLI (interactive TUI)Rapid turn rollback via Esc and checkpoint forks.
Visual UI developmentIDE ExtensionInstant inline diffs and visual inspection.
  • Codex modifies incorrect files: Specify explicit file boundaries in your repository AGENTS.md (for example, “API routes live in src/routes/, not src/api/”).
  • Tests fail after code modifications: Verify that AGENTS.md contains the exact test runner invocation (for example, npm run test:unit).
  • Codex enters a repetitive loop: Press Esc in the CLI or stop the thread in the Desktop App. Re-issue the prompt with tighter constraints.
  • Cloud task execution is slow: Optimize repository setup scripts to ensure dependencies are cached between task runs.
  • Approval dialogs interrupt unattended tasks: Use codex --sandbox workspace-write --ask-for-approval on-request to allow operations inside the repository to proceed automatically while guarding system boundaries.

To verify that the task completed successfully:

  1. Inspect modified and created files:

    Terminal window
    git status -s

    Confirm that only intended files were modified.

  2. Run the newly created test:

    Terminal window
    npm test

    Confirm that all test suites pass.

  3. Verify repository formatting and types:

    Terminal window
    npm run typecheck && npm run lint

    Confirm zero errors or formatting deviations.