30 Coding Prompts for Debugging, Code Review and Learning to Code
ChatGPT and Claude coding prompts for debugging, code review, refactoring, tests, SQL, regex, documentation, system design and learning to program.
By the aiprompts.page team · Updated · 5 min read
Summarize with ChatGPT · Perplexity
Quick answer
- 30 copy-paste prompts for ChatGPT, Claude, Gemini, grouped into 7 sections.
- Short on time? Start with #1 Debug with full context.
- Replace the [BRACKETS] with your own details, then paste the prompt into the AI tool.
- Questions? Jump to the FAQ.
On this page

AI coding assistants are now part of most developers' day. The difference between a useful answer and a confident hallucination is usually the prompt: the context you give, the constraints you set and what you ask it to explain.
Never paste secrets, API keys, passwords or proprietary code your company doesn't allow in AI tools. And always run and test AI-generated code before shipping it.
Anatomy of a coding prompt that gets correct answers
AI coding help goes wrong when it has to guess: your versions, your error, your constraints. Good coding prompts include:
- Context: language, framework and versions.
- The exact problem: the error, the failing input and the expected vs. actual result.
- The code: only the relevant part, with secrets removed.
- What you've tried: so it doesn't suggest the same thing.
- The order: "explain the root cause first, then the smallest fix".
A worked example. Run "Debug with full context" (#1) with your error and code. If the fix seems to hide the problem, reply: "Is this fixing the root cause or the symptom?" Once it works, run "Unit tests" (#16) for that function so the bug can't come back. Then "Commit message" (#25). Always run and test AI-written code before you ship it.
Debugging
#1Debug with full context
Best for Debugging any error.
I'm getting this error in my [LANGUAGE / FRAMEWORK + VERSION] project: [ERROR MESSAGE + STACK TRACE] Here's the relevant code: [CODE] What I expected: [EXPECTED]. What happens: [ACTUAL]. What I already tried: [TRIED]. Explain the root cause first, then the smallest fix. If you need more information, ask before guessing.
Include your language and framework versions to avoid outdated answers.
#2Explain an error message
Best for Understanding unfamiliar error messages.
Explain this error message in plain English, list the 3 most common causes and how to check each one: [ERROR].
Check the most likely cause first.
#3Rubber duck debugging
Best for Finding bugs by talking through your logic.
Act as a rubber duck. I'll explain what my code is supposed to do, step by step. Ask me clarifying questions that might expose where my logic breaks. Don't give me the answer directly.
Explain it as if to a beginner; bugs show up when you slow down.
#4Find the bug
Best for Logic bugs with a specific failing input.
This function should [EXPECTED BEHAVIOUR] but returns [WRONG RESULT] for input [INPUT]. Trace through it line by line with that input and find where it goes wrong: [CODE].
Give the exact input and the exact wrong output.
Example result
Asked with: A Python function should return the average of a list but returns 2.0 instead of 2.5 for [2, 3].
#5Performance problem
Best for Slow code.
This code is slow when [CONDITION, e.g. the list has 100k items]: [CODE]. Identify the bottleneck, explain its time complexity, and suggest a faster approach with the trade-offs.
Give the input size where it gets slow.
Code review and refactoring
#6Code review
Best for Reviewing code before merging.
Review this [LANGUAGE] code like a senior engineer. Look for bugs, edge cases, security issues, performance problems and readability. Rank findings by severity and show a fix for the top 3: [CODE].
Ask it to rank issues by severity.
#7Security review
Best for Checking code for security issues.
Review this code for security issues: injection, authentication and authorization gaps, unsafe input handling, secrets in code and insecure defaults. Explain each risk and the fix: [CODE].
Never paste real secrets or keys; replace them with placeholders.
#8Refactor for readability
Best for Cleaning up messy code.
Refactor this code to be easier to read and maintain without changing its behaviour. Keep the same public interface, explain each change, and point out anything that needs a test first: [CODE].
Write tests before refactoring.
#9Simplify
Best for Over-complicated code.
This code works but feels over-complicated: [CODE]. Show a simpler version and explain what was unnecessary.
Ask what was unnecessary and why.
#10Naming help
Best for Clearer variable and function names.
Suggest clearer names for the variables, functions and classes in this code, with a one-line reason for each change: [CODE].
Apply names consistently across the codebase.
Writing code
#11Write a function with constraints
Best for Writing a new function.
Write a [LANGUAGE] function that [WHAT IT DOES]. Inputs: [INPUTS]. Output: [OUTPUT]. Handle these edge cases: [EDGE CASES]. Constraints: [no external libraries / must be O(n) / follow this style]. Include a short usage example.
List edge cases up front.
Example result
Asked with: A JavaScript function that removes duplicate emails case-insensitively, keeping the first one seen.
#12Plan before coding
Best for Planning features before writing code.
I want to build [FEATURE] in my [STACK] app. Before writing code, give me a step-by-step implementation plan: files to change, data model changes, API changes, edge cases and how to test it. Ask questions if anything is unclear.
Let it ask clarifying questions first.
#13Convert between languages
Best for Porting code between languages.
Convert this [SOURCE LANGUAGE] code to idiomatic [TARGET LANGUAGE], using the target language's conventions and standard library rather than a line-by-line translation: [CODE].
Ask for idiomatic code, not a line-by-line translation.
#14Regex
Best for Writing and understanding regular expressions.
Write a regular expression that matches [PATTERN DESCRIPTION] in [LANGUAGE / FLAVOUR]. Explain each part, and show 5 strings that should match and 5 that shouldn't.
Test the regex against the example strings it gives.
#15Script to automate a task
Best for Automating repetitive tasks.
Write a [Python / Bash / Node] script that [TASK, e.g. renames all files in a folder by date]. Make it safe: add a dry-run mode, handle errors and print what it does.
Always run the dry-run mode first.
Tests
#16Unit tests
Best for Writing unit tests.
Write unit tests for this function using [TEST FRAMEWORK]. Cover the happy path, edge cases, invalid input and boundary values. Use clear test names that describe the behaviour: [CODE].
Ask for test names that describe the behaviour.
#17Find untested cases
Best for Finding gaps in your tests.
Here's my function and its tests: [CODE + TESTS]. Which important cases are not tested? Write the missing tests.
Paste both the code and the existing tests.
#18Test data
Best for Generating realistic test data.
Generate realistic test data for this schema: [SCHEMA], with [NUMBER] records including edge cases (empty strings, nulls, very long values, special characters), as [JSON / CSV / SQL inserts].
Include edge cases like empty strings, nulls and special characters.
Databases and APIs
#19SQL query
Best for Writing SQL queries.
I have these tables: [SCHEMA]. Write a SQL query for [DATABASE] that [WHAT YOU NEED]. Explain how it works and suggest indexes that would help.
Paste your real schema so column names are right.
Example result
Asked with: Tables orders(id, customer_id, total, created_at) and customers(id, name, city); top 5 customers by spend in 2026, PostgreSQL.
#20Optimise a slow query
Best for Speeding up slow queries.
This query is slow: [QUERY]. Here is the EXPLAIN output: [EXPLAIN]. Explain why it's slow and suggest a rewrite or indexes.
Include the EXPLAIN output for an accurate diagnosis.
#21Design an API
Best for Designing a REST API.
Design a REST API for [FEATURE]: endpoints, methods, request and response examples, status codes, validation rules and authentication. Keep it consistent and simple.
Keep naming and status codes consistent.
#22Database schema
Best for Designing a database schema.
Design a database schema for [APP DESCRIPTION]: tables, columns with types, primary and foreign keys, indexes and the reasoning. Point out anything that will be hard to change later.
Ask which decisions will be hard to change later.
Docs and communication
#23Explain this code
Best for Understanding code someone else wrote.
Explain what this code does, as if to a new teammate: the overall purpose, then a walk-through of each part, then anything surprising or risky: [CODE].
Ask for risky or surprising parts first.
#24Write documentation
Best for Writing READMEs and docs.
Write a README section for [PROJECT / MODULE]: what it does, how to install, how to use it with examples, configuration options and common problems.
Include a working example that people can copy.
#25Commit message
Best for Writing commit messages.
Write a clear commit message for this diff: a short summary line under 60 characters and a body explaining why the change was made: [DIFF].
Explain why the change was made, not just what.
#26Pull request description
Best for Writing pull request descriptions.
Write a pull request description for these changes: [SUMMARY / DIFF]. Include what changed, why, how to test it and any risks or follow-ups.
Include how to test it.
Example result
Asked with: Changes: added rate limiting to the login endpoint (5 attempts per 15 minutes per IP).
Learning to code
#27Learning roadmap
Best for Planning how to learn programming.
I want to become a [FRONTEND / BACKEND / DATA / MOBILE] developer. I know [CURRENT SKILLS] and can study [HOURS] a week. Create a 6-month roadmap with topics, practice projects and how to know I'm ready for the next step.
Build projects at every stage, not just tutorials.
#28Explain a concept with code
Best for Learning programming concepts.
Explain [CONCEPT, e.g. closures / recursion / async/await] with the simplest possible code example, then a real-world example, then a common mistake beginners make.
Type the examples yourself instead of copying them.
#29Project ideas
Best for Building a portfolio.
Suggest 10 beginner-to-intermediate project ideas in [LANGUAGE / STACK] that would look good in a portfolio. For each: features, what I'll learn and a stretch goal.
Pick a project that solves a problem you have.
#30Hints, not solutions
Best for Learning without copying answers.
I'm solving this coding problem: [PROBLEM]. Don't give me the solution. Give me one hint at a time, and only give the next hint when I ask.
Ask for the next hint only after you've tried.
Tips
- Give versions. "React 19, Next.js 16, TypeScript" avoids outdated answers.
- Ask for explanation first, code second. You'll catch wrong assumptions early.
- Test everything. AI code often looks right and fails on edge cases.
Frequently asked questions
Is ChatGPT good for coding?
It's very helpful for debugging, explaining code, writing tests and boilerplate. Always run and test the code before using it.
How do I get better coding answers from AI?
Give versions, the full error, the relevant code, what you expected and what you already tried, and ask for an explanation first.
Can I paste my company's code into ChatGPT?
Only if your company allows it. Never paste secrets, API keys or passwords into any AI tool.
Browse more coding and development prompts.


