ChatGPT Coding: How to Write, Fix and Test Code (2026)

ChatGPT coding help works best when you treat it as a fast, patient pair programmer: paste your code or error, explain what you want, and check everything it gives back before you use it. It can write functions, explain error messages, suggest tests and turn plain-English ideas into scripts. For bigger jobs across a whole project, OpenAI's coding agent, Codex, now sits inside ChatGPT and is included on every plan, from Free to Enterprise, with very different usage limits.

Can ChatGPT write code? Yes. ChatGPT can write, explain, fix and test code in most popular languages, including Python, JavaScript, SQL and Excel formulas. It makes mistakes, so read, run and test its code yourself, and never paste passwords, API keys or private customer data into a chat.
Key takeaways
Use the chat for small, self-contained jobs: a function, a formula, an error message, a regex.
Use Codex when the task spans several files or needs code to run on your machine or in the cloud.
Codex comes with every ChatGPT plan, but Free and Go are meant for quick or light tasks; Plus and above give more usage.
Always run and test what ChatGPT writes. It can sound sure and still be wrong.
Keep secrets out of your prompts, and check the licence of any library it suggests.
In this guide
What can ChatGPT coding help do?
ChatGPT is a general AI chatbot made by OpenAI, and coding is one of the things it does best. Because code either runs or it doesn't, you can check its work quickly, which makes it far more useful here than for, say, legal questions.
Here is what most people use it for:
Task | Example | How much to trust it |
|---|---|---|
Explain code | "What does this Python function do, line by line?" | High, but read it yourself too |
Fix an error | Paste the error message and the code that caused it | Good for common errors |
Write a small function | "Write a JavaScript function that formats a UK phone number" | Good, after testing |
Write tests | "Write unit tests for this function, including edge cases" | Good starting point |
Convert code | "Rewrite this Python script in JavaScript" | Check every line |
Spreadsheet formulas | "An Excel formula to total column C when column A says Paid" | High for common formulas |
SQL queries | "Write a SQL query to find customers with no orders this year" | Check against your real tables |
Learn to code | "Teach me Python loops with small exercises" | High |
If you are a complete beginner, ChatGPT is also a good tutor: ask it to explain one idea at a time and set you small exercises. Our guide to how to use ChatGPT covers the basics of writing good prompts.
How to use ChatGPT for coding in 6 steps
These steps work for any language and any plan.
Say what you're building and in which language. "I'm writing a Python 3.12 script that reads a CSV of orders" gives ChatGPT the context it needs. Mention any libraries or frameworks you already use.
Paste the real code or the real error. Copy the full error message, not a summary. Remove passwords, API keys, personal data and anything your employer wouldn't want shared first.
Ask for one thing at a time. "Fix this error" works better than "fix my app". Break big jobs into small, testable pieces.
Ask it to explain the change. "Explain what you changed and why" helps you learn and helps you spot a wrong fix.
Run and test the code yourself. Paste any new error straight back into the same chat. Two or three rounds are normal.
Ask for tests and edge cases. "What inputs might break this?" often finds bugs before your users do.
Our tip: when an answer goes wrong twice, start a new chat with a clean, short description of the problem. Long chats full of failed attempts can confuse it.
12 ChatGPT coding prompts to copy
Fill in the square brackets and paste.
"Explain this code in plain English, line by line, for a beginner: [code]"
"I get this error: [error]. Here's the code: [code]. What's causing it and how do I fix it?"
"Write a [language] function that [does X]. Include comments and one example of how to call it."
"Write unit tests for this function using [pytest / Jest]. Include edge cases: [code]"
"Review this code for bugs, security problems and readability. List issues before suggesting fixes: [code]"
"Rewrite this code to be easier to read without changing what it does: [code]"
"Convert this [language A] code to [language B] and point out anything that doesn't translate directly: [code]"
"Write a regular expression that matches [pattern]. Explain each part and give three test strings."
"Write a SQL query for these tables: [table structures]. I need [result]."
"Write an Excel formula that [does X]. My data is in columns [A to D] with headers in row 1."
"Teach me [concept] in [language] with three short exercises. Wait for my answer before giving the next one."
"Plan how to build [small app]. List the files, the main functions and the order to build them, but don't write the code yet."
Chat or Codex: which should you use?
ChatGPT now has two ways to help with code. The ordinary chat is best for questions and short snippets. Codex is OpenAI's coding agent: it can read a whole project, edit several files, run commands and tests, and propose changes for you to review. Our guide to ChatGPT Codex explains it in full.
ChatGPT chat | Codex | |
|---|---|---|
Best for | Questions, snippets, errors, learning | Changes across a project, running tests, longer tasks |
Where | chatgpt.com and the apps | Codex app, the ChatGPT desktop app, your editor and the terminal |
Sees your files? | Only what you paste or upload | Your project folder or a connected repository |
Runs code? | Can run Python for analysis | Runs commands and tests in a sandbox |
Plans | All plans | All plans, with very different limits |
OpenAI's pricing page says Codex is included with ChatGPT Free, Go, Plus, Pro, Business, Edu and Enterprise. Free is described as a way to explore Codex on quick tasks and Go as suitable for light coding, while Plus is pitched at a few focused coding sessions a week and Pro offers 5 or 20 times Plus's usage. Codex and ChatGPT Work share the same usage allowance. To compare everything else each plan includes, see ChatGPT limits by plan.
Which model writes the best code?
On 17 November 2026, OpenAI released GPT-6.2 Astra and GPT-6.2 Sol in ChatGPT Work and Codex for Plus, Pro, Enterprise and Edu users. OpenAI positions Sol as the more affordable model for everyday coding and writing, and says it came close to Astra on one real-codebase coding test at about a fifth of the cost. For most people, the default model ChatGPT picks is fine; switch to a stronger one only for hard problems.
Getting Codex on your computer
The Codex app first arrived on Mac, and OpenAI added Windows on 4 March 2026. You can also reach Codex from the ChatGPT desktop app, which since July 2026 combines Chat, Work and Codex. Our ChatGPT desktop app guide shows where to download it safely.
What are the limits and risks?
ChatGPT is a strong helper, but it isn't a senior developer who knows your system.
It can be confidently wrong. It may invent functions that don't exist, use out-of-date library versions or miss edge cases. Testing is not optional.
Security matters. Ask it to review code for common weaknesses, but don't treat its answer as a security audit. Never paste secrets, and rotate any key you accidentally share.
Your employer's rules come first. Many companies have policies on which AI tools may see their code. Business and Enterprise plans have different data protections from personal accounts.
Licences still apply. If it suggests a library or a large block of code, check the licence before you ship it.
You still need to understand the code. If you can't explain what a piece of code does, you can't maintain it. Ask ChatGPT to teach you until you can.
Wondering what this means for developer jobs? We look at the evidence in will ChatGPT replace programmers?
Frequently asked questions
Is ChatGPT good at coding?
Yes, for most everyday tasks. It is especially good at explaining code, fixing common errors and writing small functions and tests. It is weaker on large, unfamiliar codebases unless you use Codex, and it still makes mistakes, so always test its output.
Can I use ChatGPT for coding for free?
Yes. The free plan can explain, write and fix code in the chat, and OpenAI includes Codex on the free plan for quick tasks. Heavier use needs a paid plan such as Plus.
Which programming languages does ChatGPT know?
It handles all the popular languages, including Python, JavaScript, TypeScript, Java, C#, C++, PHP, Go, Rust, SQL and Excel or Google Sheets formulas. It is usually strongest in the most widely used ones.
Is it safe to paste my code into ChatGPT?
Remove passwords, API keys and personal data first, and follow your employer's rules. Personal accounts let you choose in Data controls whether chats help improve OpenAI's models; Business and Enterprise plans don't use your data for training by default.
Can ChatGPT build a whole app?
It can help you build one step by step, and Codex can make changes across a whole project. You still need to plan the app, review every change, test it and handle hosting and security yourself.
Start with one small job
Pick one annoying task from this week, such as an error message you couldn't solve or a formula you keep rewriting, and paste it into ChatGPT with the prompts above. Test what it gives you, ask it to explain the fix, and you'll quickly learn where it saves you time. When you're ready for larger projects, try Codex on a copy of your code first.
Related reading
References
Checked on 4 December 2026. We read OpenAI's Codex pricing page, the ChatGPT and Codex changelog and OpenAI's announcements. Plans and limits change often, so check OpenAI's pages before you rely on them. We are independent of OpenAI.
Free download: How to Fact-Check ChatGPT Answers (PDF). Free to download and print, no sign-up. See all our free ChatGPT downloads.
















