Review Then Edit Pattern

Introduction

Welcome back to Mastering Advanced AI Tooling in Codex! In previous lessons, we established the foundation: configuring Codex through config.toml, enabling secure web search, creating Skills (custom specialized capabilities) with arguments, and using inline shell capture (!) to inject real-time repository state into our prompts.

Today, we are building a review-then-edit workflow template that embodies safe, automated code modification. Unlike simple prompts that execute immediately, this pattern enforces a structured workflow: clarify intent, propose a plan, apply minimal changes, verify results, and report outcomes. This approach prevents the common pitfalls of AI-driven editing (such as scope creep, untested changes, or modifications to protected files) while maintaining the efficiency and intelligence that make Codex valuable. We will construct a reusable SAFE-EDIT workflow template that transforms a high-level goal into vetted, tested code changes.

What we're building: We're creating workflow template files (like safe_edit.txt) that you invoke by pasting their contents into prompts or referencing them with @filename.txt. These are NOT Skills from Unit 3 — they're structured prompt patterns that guide Codex through a multi-phase process. Think of them as recipes for AI interactions rather than registered capabilities in the Codex system.

The Problem with Direct Edits

When we ask an AI agent to modify code directly, several risks emerge. The agent might misunderstand our intent and change unrelated code; it might apply overly broad refactorings when we wanted a targeted fix; or it might modify files we consider protected (lockfiles, configuration, vendor dependencies). Without verification, we have no confidence that changes preserve functionality.

The fundamental issue is mixing cognition with action: the agent decides what to do and does it simultaneously, leaving no checkpoint where we can assess its understanding before committing to changes. This creates an all-or-nothing dynamic: either we accept whatever the agent produces, or we reject everything and start over. In collaborative development, this lacks the deliberation we would expect from code review or pair programming.

A better approach separates these concerns. First, the agent demonstrates understanding by articulating what needs to change and why; second, it proposes a specific, minimal plan; third, it executes that plan under defined constraints; finally, it proves the changes work through automated verification. This multi-phase structure transforms unpredictable agent behavior into a reliable, auditable process.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal