← Index28 entries · By Subject
Section VI · Subject Matter

Coding prompts

Prompts for code review, debugging, explaining unfamiliar code, writing tests, documenting APIs, and shipping faster.

§ Overview

These prompts target the parts of software work that are tedious to do well but easy to describe: senior-style pull request reviews, step-by-step debugging of an error message, refactoring for readability without changing behavior, generating unit tests across happy path and edge cases, and writing Conventional Commits messages. The collection leans toward the unglamorous craft tasks too — designing a normalized database schema with DDL, building and explaining a regex, hardening a multi-stage Dockerfile line by line, and translating code between languages idiomatically.

AI shines here because so much of coding is pattern recognition over well-trodden ground, and because it's tireless about boilerplate. A model will happily enumerate test cases or walk an error backwards through its likely causes. The catch is that it's confidently wrong often enough to matter: it hallucinates APIs, misses your codebase's conventions, and can introduce subtle behavior changes during a refactor. Run the output, read it like you'd review a junior's PR, and never paste secrets or proprietary code into a tool you don't control.

§ Field Notes

What makes a good coding prompt

Good coding prompts give the model the surrounding reality: the language and version, the relevant code, the actual error and stack trace, and the constraint that matters ("don't change the public interface," "optimize for readability over speed"). Pasting the real function beats describing it, and including your existing patterns keeps output consistent with the codebase.

The strongest prompts also ask for reasoning, not just code — ranked root causes when debugging, explicit tradeoffs when optimizing, or a line-by-line explanation of a regex. That lets you judge whether the model actually understood the problem before you trust the fix.

§ Pro Tips

Get sharper results

  • 01Paste the actual code, full error message, and stack trace rather than paraphrasing — the model's accuracy drops sharply when it has to guess what your code looks like.
  • 02When refactoring or optimizing, explicitly require that behavior stay identical and ask for the tradeoffs, then run your existing test suite against the result before trusting it.
  • 03Ask the model to explain its reasoning (ranked root causes, complexity analysis, why a regex matches) so you can catch confident-but-wrong answers before they reach production.
  • 04Strip out secrets, API keys, and proprietary logic before pasting code into any external AI tool, and assume anything you send may be logged.
§ FAQ

Common questions

Can I trust AI-generated code without reviewing it?

No. Treat every snippet like a pull request from a fast but unfamiliar contributor: read it, run it, and test it. Models hallucinate functions that don't exist, miss edge cases, and occasionally change behavior during a refactor. The review step is where the real value gets locked in.

How do I get unit tests that actually cover the tricky cases?

Paste the real function and ask explicitly for happy path, boundary conditions, error handling, and failure modes — and name any edge cases you already know about. Then verify the tests run and actually fail when you break the code; AI sometimes writes tests that pass against anything.

Will AI follow my project's coding conventions?

Only if you show them. Include a representative file or your style rules in the prompt — naming, error-handling patterns, formatting. Without that context the model defaults to its own generic style, which you'll then spend time reconciling with the rest of your codebase.

§ The Prompts · 28
№ 002coding

Perform a Thorough Code Review on a Pull Request

Get a senior-engineer-style code review with categorized, file-referenced feedback.

For
claude·chatgpt
№ 006coding

Explain Complex Code in Simple Terms

Turn confusing code into a clear, junior-friendly explanation with edge-case notes.

For
claude·chatgpt
№ 012coding

Debug an Error Message Step-by-Step

Get a structured debugging plan: error explanation, ranked root causes, tests, and fixes.

For
claude·chatgpt
№ 021coding

Refactor Code for Readability and Maintainability

Refactor any code for readability and maintainability without changing its behavior.

For
claude·chatgpt
№ 022coding

Generate Unit Tests for a Function

Generate comprehensive unit tests with happy path, edge cases, and failure modes.

For
claude·chatgpt
№ 023coding

Write a Clear Git Commit Message

Generate a Conventional Commits-compliant git commit message with context and rationale.

For
claude·chatgpt
№ 024coding

Design a RESTful API Endpoint Schema

Design a complete REST API schema with request/response bodies, status codes, and error cases.

For
claude·chatgpt
№ 025coding

Build and Explain a Regular Expression

Get a working regex with a plain-English breakdown and a set of passing/failing test cases.

For
claude·chatgpt
№ 026coding

Translate Code From One Language to Another

Convert code between programming languages while using idiomatic patterns in the target language.

For
claude·chatgpt
№ 027coding

Audit Code for Performance Bottlenecks

Identify performance bottlenecks in code and get ranked, impact-focused optimization suggestions.

For
claude·chatgpt
№ 028coding

Run a Security Review on Code

Get an OWASP-aligned security review with severity ratings and remediation snippets.

For
claude·chatgpt
№ 029coding

Design a Normalized Database Schema

Design a fully normalized relational database schema with DDL, indexes, and design rationale.

For
claude·chatgpt
№ 030coding

Write Clear Technical Documentation

Generate complete Markdown technical docs with params, examples, and error handling.

For
claude·chatgpt
№ 096coding

Generate a Production-Ready Dockerfile and Explain Each Line

Generate a hardened, multi-stage Dockerfile with line-by-line comments and matching .dockerignore.

For
claude·chatgpt
№ 097coding

Explain and Write a Regex From Plain English

Translate a plain-English matching requirement into a regex with line-by-line breakdown and edge cases.

For
claude·chatgpt
№ 098coding

Design a Clean REST API for a New Resource

Get a complete REST endpoint design with shapes, errors, and idempotency notes.

For
claude·chatgpt
№ 099coding

Write Unit Tests for an Existing Function

Generate a thorough unit test suite covering happy path, branches, edges, and errors.

For
claude·chatgpt
№ 100coding

Optimize a Slow Function With Specific Tradeoffs

Get a ranked list of optimizations with complexity analysis and explicit tradeoffs.

For
claude·chatgpt
№ 176coding

Refactor a long, tangled function into smaller, testable units

Breaks an overgrown function into smaller, single-responsibility units while preserving behavior and the public signature.

For
chatgpt·claude
№ 177coding

Generate table-driven unit tests for a function with edge cases

Produces a table-driven unit test suite covering happy paths, boundaries, and error conditions for a given function.

For
chatgpt·claude
№ 178coding

Explain a cryptic regex and rewrite it to be readable

Decodes a confusing regex token by token, surfaces edge cases and backtracking risk, then rewrites it readably.

For
chatgpt·claude
№ 179coding

Write clear API reference docs straight from source code

Generates accurate API reference documentation from source code without inventing behavior, flagging ambiguities.

For
chatgpt·claude
№ 180coding

Port a code snippet to another language idiomatically

Translates a snippet into idiomatic code in a target language and flags cross-language correctness pitfalls.

For
chatgpt·claude
№ 181coding

Turn a diff into a clear, reviewer-friendly PR description

Converts a diff and context into a structured, reviewer-friendly pull request description and title.

For
chatgpt·claude
№ 182coding

Design a normalized database schema from plain requirements

Turns plain-language requirements into a normalized relational schema with DDL, relationships, and trade-offs.

For
chatgpt·claude
№ 183coding

Diagnose and rewrite a slow SQL query using its plan

Reads a query plan to explain why a SQL statement is slow, then rewrites it and recommends indexes.

For
chatgpt·claude
№ 184coding

Decode a stack trace and pinpoint the likely root cause

Reads a stack trace frame by frame to explain the failure and pinpoint the most likely root cause with next steps.

For
chatgpt·claude
№ 185coding

Brainstorm edge-case test scenarios before you write tests

Enumerates grouped edge-case and adversarial test scenarios for a feature so nothing gets shipped untested.

For
chatgpt·claude