AI Prompts

AI coding prompts.

Prompts for debugging, understanding, refactoring and testing code — tap to copy, then paste in your code.

Tap Copy on any prompt, paste it into your AI assistant, and replace the [bracketed] parts with your own details.

Debug & fix

Explain and fix an error

I'm getting this error: [paste the error]. Here's the relevant code: [paste the code]. Explain in plain terms what's causing it, point out the exact line that's wrong, and show the corrected code.

Why doesn't this work?

This code is supposed to [intended behaviour] but instead it [what actually happens]. Walk through what it actually does step by step, identify the bug, and give me a fix: [paste the code].

Understand code

Explain this code

Explain what this code does, step by step, in plain English. Note anything non-obvious, any edge cases it handles, and any it misses: [paste the code].

Explain a concept with an example

Explain [concept — e.g. closures / async-await / database indexing] in [language]. Give a short, practical code example and explain when I'd actually use it.

Improve & refactor

Refactor for readability

Refactor this code to be cleaner and more readable without changing its behaviour. Explain each change briefly and why it's an improvement: [paste the code].

Review like a senior engineer

Act as a senior engineer reviewing this code. Point out bugs, security issues, edge cases and style problems, ordered by severity, and show fixes for the important ones: [paste the code].

Make it faster

This function works but is slow on large inputs. Suggest how to improve its performance, state the time complexity before and after, and show the optimised version: [paste the code].

Tests & docs

Write unit tests

Write unit tests for the function below using [framework — e.g. Jest / pytest]. Cover the normal case, edge cases and invalid input, and briefly note what each test checks: [paste the code].

Add documentation

Add clear doc comments to this code explaining what each function does, its parameters and its return value. Don't change the code itself: [paste the code].

Build a regex

Write a regular expression that matches [describe what to match], with examples of strings that should and shouldn't match. Then explain each part of the pattern.

How to prompt for code

AI is genuinely useful for coding, but it's at its best when you give it the full picture. Always paste the actual code and the actual error rather than describing them, and say what you expected to happen versus what did happen — that contrast is what lets the assistant find the bug. For anything important, ask it to explain its reasoning and point out edge cases, and always read and test the result rather than pasting it in blind. The assistant is a fast, knowledgeable pair-programmer, not an oracle.

FAQ

Can I trust AI-generated code?
Treat it as a knowledgeable draft, not a final answer. Always read it, understand it, and test it — especially for anything touching security, data, or production. Asking the AI to explain its code helps you catch mistakes.
Which AI is best for coding?
These prompts work across ChatGPT, Claude, Gemini and Copilot. They each have strengths, so it's worth trying the same prompt in more than one if you're not happy with the first result.

More prompt packs