Home › Prompt examples › Coding AI prompts: 23 copy-ready examples

Coding AI prompts: 23 copy-ready examples

23 prompts from 7 coding guides, ready to copy into any AI chat assistant.

Replace the [brackets] with your details. Every prompt comes from one of our full guides, which also covers which tool to use, the steps and the risks. Want a prompt for something else? Use the prompt builder.

Tasks on this page

AI prompts to explain unfamiliar code

When to use: Walk through what a function or file does, line by line. Full guide: Explain unfamiliar code

Explain this function
Explain this [language] code to someone who knows basic programming but not this codebase: [paste]. Cover: what it's for, inputs and outputs, side effects (files, network, database), edge cases, and anything that looks like a bug. Refer to line numbers.
Trace one example
Walk through this code with the input [example input], step by step, showing the value of each variable as it changes. Tell me the final output and any point where it could crash.
Map an unfamiliar repo
I've opened a new project. Read the main entry point and folder structure, then give me a one-page map: what each folder does, where requests or data come in, and the 5 files I should read first.
Debug with me
This [language] code gives [actual result] but I expected [expected result] for input [input]. Here is the code and the error or output: [paste]. List the 3 most likely causes in order, how to test each one, and the smallest fix. Don't rewrite unrelated code.
Write tests that prove the explanation
Write [pytest/Jest/...] tests for this function covering: a normal case, an empty or missing input, a boundary value, and the edge cases you found. Explain what each test proves.

AI prompts to write unit tests

When to use: Generate tests for existing code and run them in an agent. Full guide: Write unit tests

Write tests from behaviour
Write [framework] unit tests for this function. Expected behaviour: [rules]. Cover normal input, edge cases ([list]) and errors. One-line comment per test explaining what it protects.

[paste code]
Find what's untested
Here are the function and its current tests. List behaviours and edge cases the tests don't cover, ranked by risk. Don't write code yet.
Review my tests
Review these tests: which ones would still pass if the function were broken? Which mock too much? Suggest fixes.

AI prompts to fix a failing build

When to use: Agent reads errors, edits code and re-runs until green. Full guide: Fix a failing build

Diagnose first
Here is the failing build log and the command to reproduce it. Explain the root cause in plain English and propose a fix before editing anything.

[log]
Fix with guard rails
Fix the failing build on this branch. Rules: don't delete, skip or weaken tests; don't modify CI files; keep dependency changes minimal and explain each. Rerun [command] after each change.
Explain the diff
Summarise every change you made, why, and anything that could affect production or other teams.

AI prompts to refactor code across files

When to use: Rename or restructure code across a repository with review. Full guide: Refactor across files

Plan the refactor
I want to [rename X to Y / split module Z / change signature of F]. List every file and reference you'd change, including config, templates and docs. Don't edit yet.
Do it safely
Apply the plan on this branch. Behaviour must not change; public API [names] stays the same. Run [test command] after the change and report results.
Check for leftovers
Search the repository for remaining references to [old name], including strings, comments, docs and config. List them and say which are safe to change.

AI prompts to review a pull request

When to use: Get AI review comments on pull requests. Full guide: Automated PR review

Review this diff
Review this pull request diff. Focus on bugs, security issues and missing tests. For each comment give the file and line, why it matters and a suggested fix. Skip style nits.

[diff]
Write review guidelines
Draft review guidelines for an AI reviewer on our [language/framework] repository: what to flag, what to ignore, severity levels. Keep it under 200 words.
Summarise a big PR
Summarise this pull request for a human reviewer: what changed, risky areas, and the 3 files to read first.

AI prompts to turn an issue into a pull request

When to use: Assign an issue to a cloud agent that branches, codes and opens a PR. Full guide: Issue to pull request

Main prompt
Assign issue #17 to the cloud agent with instructions to add tests.
Beginner-friendly
Assign issue #17 to the cloud agent with instructions to add tests.

I'm new to this: explain each step in plain words and ask me for anything you need before starting.
Check-your-work
Assign issue #17 to the cloud agent with instructions to add tests.

When you finish, list any assumptions you made, anything you're unsure about, and what I should double-check before using the result.

AI prompts to generate a regex or SQL query

When to use: Describe what you need and get a tested pattern or query. Full guide: Generate a regex or SQL query

Write it
Write a [regex flavour / SQL dialect] that [describe the goal]. These should match: [examples]. These should NOT match: [examples]. Explain each part in one line.
Explain one I already have
Explain this [regex / SQL query] line by line in plain English, then tell me which inputs it would get wrong:

[paste]
Hunt for edge cases
Here is my [pattern / query] and the result on my sample. List 10 tricky inputs or data situations (empty values, accents, time zones, duplicates) it might mishandle, and give a fixed version.

More prompt examples

All prompt examples · Writing & editing · Research · IT ops & DevOps · Customer support · Data analysis · Automation & agents · Image & video · Personal productivity · Education & learning · Marketing · Sales · HR & recruiting · Finance & accounting · Legal & compliance · Healthcare admin · Cybersecurity · Product & design · Personal life & home · Travel · Content creation · Small business

See also: Best AI tools for coding

Report an error on this page