PromptFork

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.

Open in Studio
Prompt
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

More prompts you might like

Editor’s pickCoding & DevelopmentSeed

Codex API scaffolder — REST endpoint from a plain-English spec

Describe your endpoint in plain English and Codex builds the full implementation: route handler, request validation, error responses, and a usage example — no boilerplate writing required.

New

Codex test suite generator — unit and edge-case tests from your code

Point Codex at any function and it writes the full test suite: happy path, edge cases, error conditions, and the mocks — covering what you'd write manually but in a fraction of the time.

New

Codex CLI script builder — describe the automation, get the script

Tell Codex what you want to automate in plain English and it writes the complete script — with argument parsing, error handling, progress output, and dry-run mode — ready to run without cleanup.

New

Codex bug hunter — root cause, not just a patch

Paste the buggy code and the error, and Codex diagnoses the root cause, explains why the obvious fix won't work, and gives you the correct fix with a regression test so the bug can never come back silently.

New

Next.js 15 App Router page with streaming, caching, and server data

Scaffold a production App Router page: Server Component data fetching, Suspense streaming for instant TTFB, correct cache strategy (fetch cache vs unstable_cache vs revalidatePath), loading/error boundaries, and generateMetadata — with the non-obvious patterns most tutorials skip.

New

Tailwind analytics dashboard with animated stat cards, dark mode, and skeleton loading

Production-grade dashboard layout: KPI cards with counting animations and trend sparklines, a chart area, activity table — all with dark mode, skeleton loading states, and responsive breakpoints defined to the pixel.

New