Coding prompts
Prompts for everyday programming work: explaining, debugging, testing, refactoring, reviewing and documenting code in any language.
These coding prompts are written for real projects, not toy examples. They cover explaining unfamiliar code, debugging with ranked hypotheses, writing unit tests, refactoring, reviewing diffs, SQL, regular expressions, Git rescues, security checks, documentation and small scripts. Most of them work in any language: fill in the language, framework or tool in the [square brackets] and paste your code where the prompt says so. Short, focused snippets get better answers than whole files.
Each prompt asks for something you can verify. Tests can be run, explanations can be checked against the code, and fixes come with a reason. That makes wrong answers easier to spot, which matters because AI can produce code that looks correct but fails on edge cases or uses functions that don't exist. Use Copy to take a prompt to your editor or notes, or "Use in chat" to open it in ChatG, where code appears in highlighted blocks with a copy button.
Before you paste anything, remove API keys, passwords, tokens and customer data, and check whether your employer allows sharing the code with outside AI services. For single questions, the Code Assistant is quicker. For a longer read on workflows and limits, see AI for coding and ChatG for developers.
How to adapt these prompts
- Add versions and constraints: language version, framework, runtime and "no new dependencies".
- Shrink the input to a minimal example that still shows the problem.
- Paste the result back after you try a fix, including any new error, and ask what to try next.
- Ask for a specific output, such as a diff, a single function or a table of options.
Read generated code before running it, and run it somewhere safe first.
-
01
Explain code like a senior engineer
You are a senior [language] engineer mentoring a junior developer. Explain what the code below does, step by step, then point out anything unusual, risky or worth refactoring. Code: [paste code]
-
02
Debug an error with ranked causes
My [language or framework] code throws this error: [paste error and stack trace]. Here is the code involved: [paste code]. List the three most likely causes in order, tell me how to confirm each one, and give the fix for the most likely cause.
-
03
Unit tests with edge cases
Write unit tests with [testing framework] for the function below. Cover normal input, boundary values, empty or null input and invalid types, and name each test after the behavior it checks. Function: [paste function]
-
04
Refactor without changing behavior
Refactor this [language] code to be more readable and maintainable without changing its behavior. Use clear names, smaller functions and less duplication, and keep the public interface the same. Explain each change briefly. Code: [paste code]
-
05
Pull request review by severity
Review this pull request diff as a strict but friendly reviewer. Group your comments into bugs, security, performance and style, mark each one as blocking or optional, and suggest specific code changes. Diff: [paste diff]
-
06
SQL query from table definitions
Write a [PostgreSQL, MySQL or SQLite] query that [describe what you need] using these tables: [paste table definitions]. Explain the query in plain English and suggest an index if the tables are large.
-
07
Regular expression with test strings
Write a regular expression for [language or tool] that matches [describe pattern] but not [describe exceptions]. Explain each part of the pattern, and give five strings that should match and five that should not.
-
08
Convert code to another language
Convert this [source language] code to idiomatic [target language]. Don't translate line by line; use the target language's usual libraries and patterns, and point out any behavior that differs, such as integer division or error handling. Code: [paste code]
-
09
API endpoint with validation
Write a [framework] endpoint for [HTTP method] [route] that [what it should do]. Validate these input fields: [fields and rules], return clear error messages with the right status codes, and include an example request and response.
-
10
Safe shell script with dry run
Write a [bash or PowerShell] script that [task, e.g. renames all photos in a folder by date taken]. Make it safe: add a dry-run option, stop on errors and print what it is doing. Comment each section.
-
11
Find and fix a performance bottleneck
This [language] function is slow on large inputs of about [input size]: [paste code]. Explain its time and memory complexity, find the bottleneck, and propose a faster version with its new complexity. The output must stay the same.
-
12
Design a database schema
Design a database schema for [describe app, e.g. a small booking system] with these requirements: [requirements]. Give the tables, columns with types, keys and relationships, and name one design choice you would revisit as the app grows.
-
13
Add docstrings and comments
Add clear docstrings or comments in the standard [language] style to the code below. Describe each function's purpose, parameters, return values and possible errors, and don't change the code itself. Code: [paste code]
-
14
Get out of a Git mess safely
I'm in this Git situation: [describe what happened, e.g. committed to the wrong branch and pushed]. Explain what is going on, give me the exact commands to fix it safely, and warn me about any command that rewrites shared history.
-
15
Learn a concept with exercises
Teach me [programming concept, e.g. recursion or closures] in [language]. Start with a short explanation and a minimal example, then give me three exercises of increasing difficulty. Wait for my answer before showing each solution.
-
16
Security check of a code snippet
Check this [language] code for security problems such as injection, unsafe deserialization, missing input validation, hard-coded secrets and weak authentication. For each issue, explain the risk and show the fixed code. Code: [paste code]
-
17
Clear commit message from a diff
Write a commit message for these changes with a short imperative summary line under 72 characters and a body that explains what changed and why: [describe or paste the diff]
-
18
Compare libraries or approaches
I need to [task] in a [language or framework] project with these constraints: [constraints, e.g. small bundle, no native dependencies]. Compare two or three common approaches or libraries in a table with pros, cons and when to use each, and tell me which details to verify in their official docs.
-
19
Accessible UI component
Build an accessible [framework, or plain HTML, CSS and JavaScript] component for [component, e.g. a tabs widget]. Requirements: [requirements]. Include keyboard support, ARIA attributes where needed and a short usage example.
-
20
Script to clean and process a data file
Write a [language] script that reads [file type, e.g. a CSV file] with these columns: [columns], then [what to compute or transform], and writes the result to [output]. Handle missing values and malformed rows, and print a short summary at the end.
Ready when you are
Open the chat and ask your first question. It's free, and there is nothing to install.
Start chatting