10 ChatGPT Prompts for Coding and Debugging (Copy and Paste)
Prompts that help you explain code, find bugs, write tests, refactor and learn new frameworks faster.
In this article
Good coding prompts include the language, the goal, the code and the exact error. Never paste secrets such as passwords, API keys or private customer data.
Understanding code
1. Explain this code
Explain what this [language] code does, step by step, in simple terms. Point out anything unusual or risky. [code]
2. Explain an error
I get this error in [language/framework]: [error message]. Here is the relevant code: [code]. Explain the cause in plain English and give the most likely fix.
Debugging
3. Find the bug
This function should [expected behaviour] but it [actual behaviour]. Input: [example]. Expected output: [example]. Find the bug and explain why it happens. [code]
4. Rubber-duck debugging
Ask me questions one at a time to help me find the cause of this bug. Do not give the answer until I ask.
Writing and improving code
5. Write a function
Write a [language] function that [does X]. Include input validation, handle edge cases like [list] and add short comments. Show 3 example calls.
6. Write tests
Write unit tests for this function using [testing framework]. Cover normal cases, edge cases and invalid input. [code]
7. Refactor
Refactor this code for readability and maintainability without changing behaviour. List what you changed and why. [code]
8. Security review
Review this code for security issues (such as injection, unsafe input handling, exposed secrets). List each issue with a severity and a fix. [code]
Learning
9. Learn a new tool
I know [language A]. Teach me the basics of [framework/language B] with a 1-hour plan: key concepts, a small hands-on example and common mistakes.
10. Convert between languages
Convert this code from [language A] to [language B]. Use idiomatic style for B and note any behaviour differences. [code]
Rules for using AI code safely
- Run and test everything. AI code can look right and still be wrong.
- Understand before you paste. If you cannot explain it, simplify it.
- Check licenses and security for anything going to production.
- Keep prompts small. Share only the relevant part of the code. You can check size with the AI Token Counter.
Tools mentioned
All AI tools →A general-purpose AI assistant for writing, learning, coding and images.
A thoughtful AI assistant that is strong at writing, long documents and coding.
AI code suggestions and chat inside your editor.
An AI-first code editor that understands your whole project.
Free tools you can use now
AI Token Counter
Estimate how many tokens your text uses before you send it to an AI model.
Case Converter
Change text to UPPERCASE, lowercase, Title Case, Sentence case and more.
Frequently asked questions
Which is better for coding, ChatGPT or Claude?
Both are widely used by developers. Try your real tasks in each and compare. Editor tools such as [GitHub Copilot](/ai-tools/github-copilot) and [Cursor](/ai-tools/cursor) bring AI into your editor.
Can AI fix all bugs?
No. It helps with common issues, but complex bugs need testing, logs and your own reasoning.
Is it safe to paste company code into AI tools?
Follow your company's policy. Many organisations restrict sharing private code with public AI services.
Get new AI tools and prompts in your inbox
One short email when something useful is added. No spam.
Keep reading
All articles →10 ChatGPT Prompts for YouTube Creators (Ideas, Scripts, Titles)
Ten prompts to find video ideas, write hooks, plan scripts and improve titles, descriptions and thumbnails.
12 AI Writing Prompts for Bloggers and Content Writers
Twelve prompts for topic research, outlines, drafts, editing and SEO that keep your writing original and readable.
Midjourney Prompts for Beginners: Structure, Examples and Tips
Learn how Midjourney prompts are built and copy 10 example prompts for portraits, products, landscapes and illustration…
AI tools change quickly. Features, limits and prices mentioned here can differ from what you see today, so check the official website before you decide.