Codex code explainer and refactor — read, diagnose, rewrite clean
Paste any function and Codex returns a plain-English explanation, a list of specific problems, and a refactored version with notes on every change — so you understand what changed and why.
Paste into the Codex CLI with your code: 'You are a senior [LANGUAGE] engineer doing a code review and refactor. Read the code below carefully before responding. [PASTE YOUR CODE] Do this in order: 1. EXPLAIN IT (plain English, 3-5 sentences): What does this code do? What is its role in a larger system? Describe it as if explaining to a new engineer joining the team — no jargon, no line-by-line walkthrough, just the overall shape and purpose. 2. DIAGNOSE THE PROBLEMS: List every issue you find, categorized: - BUGS: logic errors, edge cases that would cause incorrect behavior or crashes - PERFORMANCE: unnecessary loops, repeated lookups, inefficient data structures - READABILITY: confusing names, deep nesting, overly complex conditionals - SAFETY: unhandled errors, missing input validation, potential injection points - STYLE: inconsistency with common [LANGUAGE] conventions For each issue: the line or section, the specific problem, and why it matters. 3. REFACTORED VERSION: Rewrite the code fixing everything from step 2. The refactored version must: - Preserve all existing behavior (no new features, no removed functionality) - Be runnable without modification - Include a diff-style comment on each changed section: // CHANGED: [why] 4. WHAT I LEARNED: Give me 2-3 general principles this code illustrates — patterns I should apply or avoid going forward.' Tip: for large files, say 'focus on the [function name] function and its callers only' — Codex produces sharper analysis on a bounded scope than a diffuse whole-file review.
- Source
- promptfork seed
- License
- CC-BY-4.0
- Published
- 6/22/2026