
Short answer
A chat model can't open your repository. It sees exactly what you paste and nothing else, so a one-line request like "fix my login bug" makes it guess the framework, the file and the bug. These prompts are built for that limit. Each one asks for the missing facts up front and tells the model how to prove its answer.
Paste the code, not a description of it. Include the full error, the exact versions ("Python 3.12, Django 5.1", not "Python") and one example input with the output you expected. Keep one task per chat: when you move from debugging to a new feature, start a fresh conversation so old code doesn't leak into the answer.
If you repeat the same context every time, save it once. ChatGPT's Projects keep chats, files and instructions together, and its custom instructions apply to every chat. Claude's Projects give each workspace its own knowledge base and chat history, and they are available on free accounts too (up to five projects). In Gemini, Gems save a name, instructions and optional files, though Google says Gems on personal accounts move to skills starting November 2026. A saved line such as "TypeScript 5, React 19, Vitest, no new dependencies without asking" saves you typing it into every prompt.
For habits beyond the prompt itself, like reviewing every diff and keeping changes small, see our AI coding best practices. And if the job needs the model to read many files or run your tests, a chat window is the wrong tool: our Cursor prompts and Claude Code tips cover agents that work inside your repository.
| Job | Prompts | What to paste |
|---|---|---|
| Understand code or an error | 1, 2 | The code or the full error, plus versions |
| Write new code | 3, 4 | Inputs, outputs and 2 to 3 examples |
| Debug | 5, 6, 7 | Stack trace, exact input and output, timings |
| Tests and test data | 8, 9, 10 | The function, test framework, schema |
| Refactor | 11, 12 | The code and how it is tested today |
| Review | 13, 14 | The diff and what it is meant to do |
| SQL | 15, 16 | CREATE TABLE statements and the query plan |
| Regex | 17, 18 | Flavor and strings that must and must not match |
| Docs | 19, 20 | The code or the diff |
| Migrations and upgrades | 21, 22 | Old and new schema, or the official migration notes |
Start here when you're new to a codebase or a library. Prompt 3 is the one to memorize: a spec with examples gets you a function you can check in seconds.
For code you inherited or found. Asking for the inputs, outputs and side effects first stops a vague line-by-line tour.
Explain this [language] code to someone who knows [language] but has never seen this codebase. 1. In two sentences: what does it do and when is it called? 2. Inputs, outputs and side effects (writes, network calls, global state). 3. Anything surprising or easy to break. Don't rewrite it. If something depends on code I haven't pasted, say what you'd need to see. [paste code]
When the error text makes no sense yet. You want the meaning and the likely cause, not a guessed fix.
I got this error running [command] with [language/framework and version]: [paste the full error] Explain in plain words what it means, then list the 3 most likely causes in order of likelihood. For each cause, tell me one thing to check that would confirm or rule it out. Don't write a fix yet.
The spec does the work here. Examples of input and expected output beat a paragraph of description.
Write a [language] function named [name]. Purpose: [one sentence]. Inputs: [names and types]. Output: [type and shape]. Examples: - [input] -> [expected output] - [input] -> [expected output] - [edge case input] -> [expected output or error] Constraints: [version], no new dependencies, [performance limit if any]. Return the function, then 3 assertions that check the examples above.
Ports fail on the details nobody wrote down: integer division, null handling, date and time zone behavior.
Port this [source language] code to [target language] [version]. Keep the behavior identical, including error cases. Before the code, list every place where the two languages behave differently for this code (numbers, nulls, string encoding, dates, error handling) and how you handled each one. Use idiomatic [target language], and only the standard library unless I name a package. [paste code]Build this with a prompt on Greta.sh — describe the app, Greta writes and deploys it.
Debugging prompts work when they force a cause before a fix. A model that jumps straight to code will often patch the symptom and leave the bug.
Paste the trace and the code it points to. The model can't open your files from a chat window.
This [language] code throws an error. Stack trace: [paste full stack trace] Code at the lines the trace points to: [paste the relevant functions] What I expected: [behavior]. What happened: [behavior]. Find the root cause, not just the line that throws. Explain it in two sentences, then give the smallest fix and one test that would have caught it.
The hardest bugs throw nothing. This prompt makes the model trace one real input through the code.
This function returns the wrong result but raises no error. Input: [exact input] Expected: [exact output] Actual: [exact output] [paste function] Trace the input through the code step by step and show the value of each variable that changes. Stop at the first step where the value differs from what the expected output needs, and explain why.
Give it your measurement. Without numbers, models tend to suggest generic speedups.
This [language] code takes [time] for [input size]. I need it under [target]. [paste code] [paste profiler output or timing, if you have it] Identify the bottleneck and its time complexity. Suggest the single change with the biggest effect first, explain why it is faster, and tell me how to measure the difference. Don't change the output format.
Tests are where AI help pays off fastest, and where it's easiest to fool yourself. A generated test that only checks the happy path will pass forever and prove nothing.
Name your test framework, or you'll get one you don't use.
Write [framework, e.g. pytest / Jest / JUnit] tests for this function. Cover: the normal case, empty and null input, boundary values, invalid types and [domain-specific case]. One behavior per test, with a name that says what it checks. If a test exposes a bug in the function, mark it clearly and explain the bug instead of changing the test to pass. [paste function]
Write the test before the fix. When it passes later, you know the fix worked.
Bug report: [what the user saw]. Steps: [steps]. Relevant code: [paste code] Write one [framework] test that fails today because of this bug and will pass once it's fixed. Use the smallest input that triggers it. Explain why it fails now. Don't fix the bug yet.
Realistic fake data finds bugs that tidy examples hide.
Generate test data for this [schema / type definition]: [paste schema] Give me [number] records as [JSON / SQL inserts / factory functions in language]. Include: names with accents and apostrophes, empty optional fields, the longest allowed values, dates around month ends and leap years, and [case]. No real people's data. Label which record covers which edge case.
Refactors go wrong when the model "improves" behavior you depend on. Both refactor prompts pin the behavior down first, and both review prompts ask for a triggering input so you can confirm each finding yourself.
Ask for a plan before the code, and keep your tests running between steps.
Refactor this [language] code for readability. Behavior must not change: same inputs, same outputs, same errors. First list the changes you'd make (naming, duplication, nesting), in order, and wait for my OK. Don't add features, don't change the public function signatures, and don't add dependencies. Existing tests: [paste or describe]. [paste code]
For the 200-line function everybody avoids touching.
This function is [number] lines long. Split it into smaller functions, each doing one job. For each new function: its name, signature and one-line purpose. Keep the original function as a short coordinator that calls them, so every caller still works. Point out any hidden coupling, such as a variable that is set in one part and read much later. [paste function]
A first pass before a person reviews it, not a replacement for one.
Review this diff. The change is meant to [goal]. [paste diff] Look for bugs, missing edge cases, error handling gaps and anything that breaks existing callers. Skip style comments unless they hide a bug. For each finding: file and line, what goes wrong, an input that triggers it, and a suggested fix. Rank by severity. If you find nothing serious, say so.
Name the threats you care about. 'Is this secure?' gets a generic checklist.
Review this [language/framework] code for security problems. It handles [what: user input / file uploads / payments / auth]. Check specifically for: injection (SQL, command, template), missing authorization checks, secrets in code or logs, unsafe deserialization, and [other concern]. For each issue: the line, how an attacker would use it, and the fix. Don't report theoretical issues without a realistic path. [paste code]
SQL and regex answers look right more often than they are right. Make the model show sample rows and test strings, then run them.
Paste the real table definitions. Guessed column names are the most common failure.
Database: [PostgreSQL / MySQL / SQLite] [version]. Tables: [paste CREATE TABLE statements] Write a query that returns [result in plain words], sorted by [column], for [time range or filter]. Explain any JOIN that could duplicate rows, and how NULLs in [column] are handled. Then give me 3 tiny sample rows per table and the result I should expect from them.
The query plan matters more than the query. Paste both.
This [database] query takes [time] on [row count] rows: [paste query] Plan output: [paste EXPLAIN or EXPLAIN ANALYZE output] Existing indexes: [list]. Explain what the plan shows in plain words, then suggest changes in order of impact (rewrite, index, or both). For any new index, say what it costs on writes.
A regex without test strings is a guess. Make the model prove it.
Write a regex for [regex flavor: JavaScript / Python / PCRE] that matches [description]. Must match: - [example] - [example] Must not match: - [example] - [example] Return the pattern, a part-by-part explanation, and a short [language] snippet that runs every example above and prints pass or fail.
For the pattern in a config file that nobody dares to change.
Explain this [flavor] regex piece by piece: [paste regex] Then give 3 strings it matches, 3 similar strings it rejects, and any input that could make it slow (catastrophic backtracking). If it looks like it has a bug for [intended purpose], say where.Want to try one of these? Start on Greta.sh — no setup, no boilerplate — just a prompt.
Docs prompts save time on the writing nobody enjoys. Migration prompts carry the most risk on this page, so both ask for a rollback or a quote from the official notes. For more on structuring prompts like these, see our guide to AI prompting techniques for code quality.
Comments should say why, not repeat what the code says.
Add documentation to this [language] code in [docstring style, e.g. Google / JSDoc]. For each public function: purpose, parameters, return value, errors raised and one usage example. Add inline comments only where the reason for the code isn't obvious. Don't change any code, and don't comment lines that explain themselves. [paste code]
Turns a diff into something a reviewer can read in a minute.
Write a pull request description for this diff: [paste diff] Sections: what changed and why (2 to 3 sentences), how to test it (numbered steps), risks and rollback, and anything the reviewer should look at closely. Plain language, no marketing tone, under 200 words. Context: [ticket or goal].
For schema changes on tables that already hold data. Ask for the rollback in the same breath.
I need to change [table] from [current schema] to [new schema] in [database]. The table has about [row count] rows and the app reads and writes it constantly. Write the migration as steps that keep the app working during each one (add, backfill, switch reads, drop later). For each step: the SQL, how long it might lock the table, and the rollback. Flag anything that needs a maintenance window.
Paste the official changelog or migration guide. The model may not know the newest version.
I'm upgrading [library] from [old version] to [new version] in a [framework] project. Official migration notes: [paste the relevant part of the changelog or migration guide] My code that uses it: [paste the relevant files or functions] List every change my code needs, quoting the line from the notes that requires it. Mark anything you're unsure about instead of guessing an API.
Claude users can go further with our best Claude prompts, which build on Anthropic's own prompting guidance for writing, research and code.
What are good coding prompts for ChatGPT?
Good coding prompts give the model what it can't guess: the language and version, the code or error itself, what the code should do, and what done looks like, such as a test that passes. The 22 prompts on this page follow that shape for explaining code, writing functions, debugging, tests, refactors, reviews, SQL, regex, docs and migrations.
Do these coding prompts work in Claude and Gemini too?
Yes. They are plain text with no app-specific syntax, so you can paste them into ChatGPT, Claude or Gemini. Replace everything in [square brackets] with your own code, errors and versions before you send them.
How do I write a good prompt for coding?
State the job in one sentence, paste the real code and error output, name the language, framework and versions, list the constraints (what must not change, which libraries to avoid), and say how you will check the result. Ask for one change at a time, and ask the model to list its assumptions.
Is it safe to paste my code into ChatGPT, Claude or Gemini?
Never paste API keys, passwords, tokens or customer data; replace them with placeholders. For company code, follow your employer's AI policy and check each app's data controls first. OpenAI's help page on custom instructions, for example, says that information is used to improve model performance and explains how to opt out.
When should I use a coding agent instead of a chat window?
Use a chat window when you can paste everything the model needs: one function, one error, one query. When the job spans many files, needs the model to run tests, or changes your repository, a coding agent such as Cursor or Claude Code is the better fit, because it can read the files and run commands itself.
© 2026 Questera
Follow in Google