GPT for coding: give it context, then review everything
GPT can read an error, draft a function, explain a strange file and suggest tests. It only sees what you paste, and it can be confidently wrong. This guide covers what to send, what to ask and what to check.

GPT is a useful pair of hands for programming: it reads stack traces without complaint, drafts the boring parts of a function, explains a regular expression you inherited and suggests test cases you did not think of. It also invents functions that do not exist, misses edge cases and writes code that looks right and fails on the second input. The way to get the first without the second is to give it real context and to review everything it gives back. This guide shows how to do both in our free GPT chat.
What GPT does well, and where it slips
Language models have seen a vast amount of public code and documentation during training, so they are strong at common patterns in popular languages. Typical good uses:
- explaining what a piece of code does, line by line;
- turning an error message into a short list of likely causes;
- writing small, self-contained functions, scripts and SQL queries;
- drafting unit tests for code you paste;
- translating code between languages or between library versions;
- reviewing a diff for bugs, naming and readability.
Weak spots are just as predictable. The model only sees what you paste, so it guesses about the rest of your project. Its knowledge stops at a training cut-off, so very new library releases may be unknown to it. And it cannot run your code: in our chat it has no terminal and no internet access, so every claim that "this works" is a prediction, not a test result.
Paste the context a colleague would ask for
Before you ask for help with a bug, collect what a human reviewer would want to see:
- Language, framework and version, for example "Python 3.12, Django 5".
- The smallest piece of code that shows the problem, not the whole repository.
- The exact error message and stack trace, copied, not retyped.
- What you expected, what happened instead and what you have already tried.
Weak: My code doesn't work, fix it. Strong: Node 22, Express 5. This route should return the user as JSON but the request hangs and never responds. No error in the console. Here is the route and the middleware it uses: [paste code] Explain the cause first, then show the corrected route only.
The strong version tells the model where to look, what "fixed" means and how to format the answer. Asking for the explanation before the code also makes it easier to spot a wrong diagnosis early.
Prompts for everyday coding jobs
A few templates you can adapt. Copy the parts in square brackets with your own details.
- Explain: "Explain this [language] function to someone who knows basic programming but not this library. Point out anything surprising."
- Tests: "Write [framework] unit tests for this function. Cover normal input, empty input, very large input and invalid types. Do not change the function."
- Refactor: "Refactor for readability without changing behaviour. Keep the public function names. List every change you made."
- Review: "Review this diff like a strict senior developer. Report bugs first, then risky patterns, then style. Quote the line for each point."
- Regex: "Write a regular expression that matches [pattern] but not [counter-example]. Show five strings it should match and five it should reject."
Try one now: ask for a function with tests. The coding prompts page has many more, and the assistants include ready-made coding helpers.
Luna or Terra for code?
Our chat has two models. GPT-6 Luna, the default, is quick and fine for explanations, small functions, boilerplate and one-line fixes. For anything that needs careful tracing, turn on Think: it selects GPT-6.1 Terra, which reasons briefly before it answers. OpenAI describes Terra as a significant step up from its predecessor for software engineering, and also says that for the most complex coding tasks its larger models, GPT-6.1 Sol and GPT-6 Astra, remain the better choice. Those are not available on gpt.me; GPT-6 Sol is in our AI Chat app with a Pro subscription.
A practical split:
- Luna: "what does this do", syntax questions, converting a snippet, writing a docstring.
- Terra: off-by-one bugs, concurrency problems, algorithm design, reviewing logic in a long function.
The Luna vs Terra comparison covers the difference in more detail.
A review-first workflow
Treat every answer as a pull request from a fast junior colleague who never runs the tests.
- Read the explanation. If the stated cause does not match your symptoms, say so before reading the code.
- Read the diff, not just the result. Ask "show only the lines you changed" if the answer rewrites everything.
- Run it locally with your own tests, including the inputs that broke it.
- Feed back the result. Paste the new error or the failing test. This loop is where the chat earns its keep.
Two features of our chat help here. Code comes in formatted blocks with a copy button, so you do not pick up stray characters. And when you regenerate, earlier answers are kept as versions, so you can compare two approaches to the same bug side by side and keep the better one.
Safety habits for AI-written code
- Never paste secrets. Replace API keys, passwords, tokens and connection strings with placeholders like
YOUR_KEYbefore you send. - Check that packages exist. Models sometimes name libraries or functions that sound plausible but are not real. Look them up in the official package registry before installing.
- Be careful with shell commands. Read any command that deletes, moves or changes permissions before you run it, and never run one as administrator just because a chat suggested it.
- Watch for security basics. Ask explicitly about SQL injection, input validation and error handling; the first draft often skips them.
- Respect licences and your employer's rules about sharing internal code with outside services.
When a chat is not the right tool
A chat window works on what you paste into it. Very long chats are trimmed so that the model sees the recent part of the conversation, which means it can lose track of a file you pasted an hour ago. For changes spread across many files, an editor with AI built in, or a coding agent that can read your project and run tests, will do better. For a single function, an error message or a quick review, the chat is often the fastest route. Developers can also read our page for developers and the code assistant tool.
FAQ
Can GPT run my code in your chat?
No. Our chat has no code execution and no internet access. It reads your code and predicts what it will do, so always run and test the result yourself.
Which programming languages does it know?
All the widely used ones, including Python, JavaScript and TypeScript, Java, C#, C and C++, Go, Rust, PHP, Ruby, Swift, Kotlin and SQL. Quality drops for rare languages and very new library versions.
Is it safe to paste my company's code?
Check your employer's policy first. Messages pass through our server and our AI gateway to OpenAI's models; we do not store the text, but you should still remove secrets and anything confidential. See the privacy policy.
Why does the answer use a function that does not exist?
The model predicts likely code, and a plausible name can come out even when the library has no such function. Paste the relevant part of the documentation and ask it to use only what is listed there.
Got a question? Ask it now
No account and no download. Open the chat, type what is on your mind, and the answer starts appearing in a second or two.
Start chatting

