Codex Characterization-Test-First Refactor with Verification Handoff
Runs a behavior-preserving refactor in Codex exec. It pins current behavior with characterization tests, refactors in small verified steps inside an allowed scope, and ends with an evidence-based handoff for the merge decision.
You get: Verdict, baseline vs final and characterization tests added
The prompt
mkdir -p .agents/skills/codex-characterization-test-first-refactor-with-verification-han && curl -sL "https://prompts-gpt.com/prompts/codex-characterization-test-first-refactor-with-verification-handoff/raw" -o .agents/skills/codex-characterization-test-first-refactor-with-verification-han/SKILL.mdExample output
Tips and common edits
Run from the repo root, for example: codex exec --sandbox workspace-write "<prompt with variables filled>". Adjust flags to your installed Codex version. Keep the scope small, since large modules work better when split into several runs. Review the characterization tests yourself, because they pin current behavior including quirks.
Questions about this prompt
More like this
More in CodexCodex CI Failure Triage: Reproduce, Classify, Fix or Hand Off
Guides Codex through reproducing a failing CI job locally, classifying the cause as code, test, environment, or flaky, applying a minimal fix when safe, and producing an evidence-based handoff for anything it cannot resolve.
Codex Exec CI Fixer: Diagnose, Minimal Fix, Rerun, Stop After 3 Attempts
Gives codex exec a non-interactive procedure to diagnose a failing CI output, apply a minimal fix, rerun the checks and stop after three attempts with a clear report.
Codex Read-Only Repo Investigation for a Bug Report
Runs a read-only Codex investigation that maps the relevant code paths, test commands, and likely root causes for a bug report. It ends with a ranked hypothesis table and a go/no-go recommendation before any edits.
Outcome-First Codex Task Writer for a Feature or Bug Request
Turns a raw feature or bug request into a paste-ready Codex task with a goal, constraints, files in scope, definition of done and exact verification commands.
Codex Pre-Merge Diff Review with Severity-Ranked Findings
Has Codex review a branch diff against a base ref in read-only mode. It checks correctness, tests, security, and maintainability, and returns evidence-backed findings with severity and a merge recommendation.
Codex Pull Request Review With Comments Ranked by Severity
Has Codex review a pull request and return comments sorted into blocking, should-fix and nit, each with the file and line, the risk, and a suggested change.
Codex Writes an AGENTS.md for This Repository From the Real Setup
Has Codex inspect your repository and write a short, accurate AGENTS.md with the real build, test and lint commands, conventions and boundaries, checked by actually running them.
Agent Run Pre-Mortem and Self-Correction Loop Designer
Designs verification checks, error handling, and a self-correction loop for an agent task before it runs, based on likely failure modes.
Characterization Tests Before a Refactor
Writes tests that lock in a module's current behavior, including edge cases and quirks, so you can refactor safely.
Claude Code Behavior-Preserving Refactor with Characterization Tests and Staged Commits
Guides Claude Code to refactor a module safely by first pinning current behavior with characterization tests, then applying small reversible steps with verification after each. Delivers a diff, risk register, and rollback plan.
Cursor Characterization-Test-First Refactor of a Legacy Module
Has Cursor lock in current behavior with characterization tests before restructuring a legacy module in small steps, so you can decide whether the refactor preserved behavior and is safe to merge.
Cursor Refactor of a Component With Zero Behaviour Change
Has the Cursor agent restructure a messy component into smaller pieces while proving the behaviour stays identical, using existing tests or new characterization tests first.