Learn to code with AI, the right way
AI tools can explain errors, suggest code and review your work. Used well, they help you learn faster. Used carelessly, they do the learning for you. This guide shows how to stay on the right side of that line.
Pick a tool
Popular AI coding assistants
You only need one to start. Most of these offer a free tier or a free trial, and some have programs for students. Plans change often, so check each official site for current details.
GitHub Copilot
An AI pair programmer that suggests code inside your editor as you type.
Good for: Autocomplete, small functions and quick questions without leaving VS Code or another supported editor.
Cursor
A code editor built around AI, with chat and edits that can see your project.
Good for: Asking questions about a whole codebase and making changes across several files.
Claude
Anthropic's AI assistant, available as a chat app and as coding tools.
Good for: Talking through a problem, explaining unfamiliar code and reviewing what you wrote.
ChatGPT
OpenAI's general-purpose AI chat assistant.
Good for: Explaining concepts in plain language, brainstorming and debugging pasted snippets.
Gemini
Google's AI assistant, available on the web and in other Google products.
Good for: General questions, explanations and help with code alongside other Google tools.
Replit
A browser-based place to write, run and share code, with built-in AI help.
Good for: Starting a project with nothing installed and getting AI help in the same window.
Listed in no particular order. CodeWithPurpose isn’t affiliated with any of these companies.
Prompt templates
Prompts that teach you, not just answer you
Copy a template, fill in the brackets, and paste it into any AI tool. Each one keeps you doing the thinking.
Explain this error step by step
Learn to read error messages yourself next time.
I'm learning to code and got this error. Explain what it means step by step, point to the line that probably causes it, and tell me how to find this kind of bug myself. Don't rewrite my whole program. Error: [paste the error] Code: [paste the relevant code]
Review my code, but ask me questions first
You explain your thinking before getting feedback.
Please review my code. Before giving any feedback, ask me 2-3 questions about what I was trying to do and why I made certain choices. After I answer, point out the most important issues, starting with the biggest one. [paste your code]
Give me a hint, not the answer
Keeps the thinking (and the learning) on your side.
I'm stuck on this problem. Give me one small hint that moves me forward without giving away the solution. If I'm still stuck after trying, I'll ask for the next hint. Problem: [describe the problem] What I've tried: [describe your attempt]
Write tests for my function
See what "working" really means, including edge cases.
Write a few tests for this function. Include normal cases, edge cases (empty input, very large or negative values) and one case you think might fail. For each test, explain in one sentence what it checks. [paste your function]
Explain this line by line for a beginner
Understand code before you use it.
Explain this code line by line as if I'm a beginner. Use plain language, define any new terms, and tell me what would change if I removed or edited each line. [paste the code]
Turn this into a smaller exercise
Practise the core idea on your own.
Take this code and turn its main idea into a small practice exercise I can solve myself in about 15 minutes. Give me the task and a few example inputs and outputs, but not the solution. [paste the code or concept]
Quiz me on what I just learned
Check whether it actually stuck.
I just learned about [topic]. Ask me 5 short questions, one at a time, that check whether I really understand it. Wait for my answer before asking the next one, and tell me where my answers are wrong.
Compare two ways to solve this
Build judgement, not just a working answer.
Here is my solution. Show me one different way to solve the same problem, then compare the two: which is easier to read, which is faster, and when would you pick each one? [paste your solution]
A healthy AI workflow
Think first, then ask
The order matters. Each step builds on the one before, and skipping ahead is how you end up with code that works but that you don't understand.
Step 1: Understand the problem
Say in your own words what the program should do, what goes in and what comes out.
Step 2: Try it yourself first
Write a plan or a first attempt, even a broken one. It gives you something real to ask about.
Step 3: Ask for hints, not answers
Share what you tried and ask for the next small step, not the finished code.
Step 4: Read every line
Never paste code you can't explain. If a line is unclear, ask about that line.
Step 5: Run it and test it
Run the code, try edge cases and check the result yourself. Looking right is not the same as working.
Step 6: Explain it back
Describe how the solution works to a friend, a rubber duck or the AI. If you can't, go back a step.
Stay safe
Five rules before you hit enter
AI tools are useful, but they aren't always right and they aren't a safe place for private information.
Never paste secrets
Keep passwords, API keys, tokens and .env files out of prompts. Treat anything you paste as something that could be stored.
Protect personal data
Don't share your own or anyone else's private information, like addresses, phone numbers or school records.
Verify everything
AI can be confidently wrong. It may invent functions, libraries or facts. Run the code and check the official docs.
Check licences
Generated code can resemble existing code. For anything you publish, check the licences of libraries and snippets you use.
Follow your school's rules
Some classes ban AI help, others allow it with credit. Know the policy and cite AI help where it's required.
Glossary
Words you'll hear a lot
Plain definitions for the terms that come up most when people talk about AI and code.
- Prompt
- The message or instructions you give an AI tool. Clearer prompts with more context usually get better answers.
- Context window
- How much text (your messages, pasted code and the AI's replies) a model can take into account at once. Very long chats can push early details out.
- Hallucination
- When an AI states something false as if it were true, such as a function or library that doesn't exist.
- Agent
- An AI tool that can take several steps on its own, like reading files, running commands and editing code, instead of only replying in chat.
- Autocomplete
- AI suggestions that appear in your editor as you type, from the rest of a line to a whole function. You accept or ignore them.
Ready to build something with AI?
Our free Vibe Coding course walks you through building real projects with AI, one step at a time. Questions along the way? Ask the community.