How to learn to code with AI is a different question from how to code with AI, and most advice online answers the second one. A working developer wants the program finished. You, a student in AP Computer Science, GCSE or A-Level Computer Science, or a first-year CS course, want something else: to be able to write the program yourself in an exam room with no assistant at all.
Here's the uncomfortable truth. AI code that is almost right hides exactly the gap you need to learn. In the 2025 Stack Overflow Developer Survey, 66% of developers named "AI solutions that are almost right, but not quite" as a frustration with AI tools, and 45.2% said debugging AI-generated code takes more time (Stack Overflow, 2025). Those are professionals who can spot the "not quite." A beginner can't, so the bug becomes invisible and so does the lesson.
This guide gives you four rules that keep the AI useful without letting it do your learning for you, a session routine you can copy, and a way to keep what you look up so you don't look it up again next week. If you're new to studying the subject itself, read our guide to studying computer science alongside this one.
What Does It Mean to Learn to Code With AI?
Learning to code with AI means using an assistant such as Claude, ChatGPT or Cursor as a tutor that explains, questions and reviews your code, while you do the writing, the debugging and the remembering. The AI speeds up the slow parts of learning (finding the right concept, decoding an error message). It must not replace the effortful parts, because those are the parts that build skill.
There are two ways a student ends up using an assistant:
| Mode | What you type | What you get | What you learn |
|---|---|---|---|
| Generator | "Write a function that reverses a linked list" | Working code | How to ask for code |
| Tutor | "Here's my attempt. Don't fix it. What concept am I missing?" | A question or a hint | How to reverse a linked list |
Both feel productive. Only one shows up on your exam.
The Science: Why AI Can Make Beginners Worse
The research on AI and learning is young, but it points one way: the tool helps while you have it and can hurt once you don't, unless it's set up to make you think.
Help that disappears. Bastani et al. (2025) gave nearly a thousand high school maths students access to AI tutors built on GPT-4. With a plain ChatGPT-style interface, practice grades rose 48%; with a version designed to give hints rather than answers, they rose 127%. But when access was removed, students who had used the plain version scored 17% lower than students who never had AI. The hint-giving version largely avoided that harm (Bastani et al., 2025). That's maths, not code, but the mechanism is the same: students used the tool as a crutch.
The illusion of competence. Prather et al. (2024) watched novice programmers solve a problem with AI tools, using observation, interviews and eye tracking. Twenty of 21 students finished the task, which sounds great. The catch: struggling students often thought they had performed better than they had and finished with what the authors call an "illusion of competence" (Prather et al., 2024). Finishing is not the same as understanding.
It can help, when you still do the work. Kazemitabaar et al. (2023) ran a controlled study with 69 novices aged 10 to 17. Those with an AI code generator had a 1.15x higher task completion rate and 1.8x higher scores while learning, without doing worse on manual code-editing tasks. A week later their retention scores were slightly better, though the difference wasn't statistically significant (Kazemitabaar et al., 2023). Those learners still had to read, change and run the code themselves.
Underneath all three is older memory research. Producing an answer yourself beats reading it, a finding known as the generation effect (Slamecka & Graf, 1978), and retrieving something from memory beats re-reading it (Roediger & Karpicke, 2006). Pasting AI code is reading. Writing it from memory is generating. That's why the rules below look the way they do. For more on the retrieval side, see our active recall guide.
The AI isn't the problem. Skipping the struggle is. Every rule in this guide exists to put the struggle back.
The 4 Rules for Learning Programming With AI
Rule 1: Attempt first, always
Before you ask anything, write your own attempt, even a broken one, even pseudocode. Ten minutes of real effort is the minimum. The attempt is where your mental model gets tested; the AI's answer only means something when you have a wrong guess to compare it with.
If you're truly stuck at the blank page, ask for the first step, not the solution: "What should I figure out before I write any code for this?"
Rule 2: Ask for an explanation, not a fix
"Fix my code" teaches you nothing. Try these instead:
- "Don't give me corrected code. Which line is wrong, and what concept does it break?"
- "Explain this error message in plain words, then ask me what I think causes it."
- "Give me a hint, not the answer. If I'm still stuck, give me a smaller hint."
- "Here's my working solution. What would an experienced programmer do differently, and why?"
That last prompt is gold once your code works. It turns a finished exercise into a lesson on style, efficiency and idioms. Our guide to using Claude for studying has more prompts in the same tutor style.
Rule 3: Retype, never paste
If the AI does show you code, close it and type it out yourself, line by line, from memory where you can. It's slower, and that's the point. Typing forces you to read every token, notice the syntax you'd have skipped, and spot the "almost right" parts. A pasted solution goes straight from the screen to the file without passing through your head.
Rule 4: Review what you looked up
Every concept you had to ask about is a sign it isn't in your memory yet. If you don't revisit it, you'll ask the same question in two weeks. Keep a running list during each session, and turn that list into flashcards you review on a schedule. That's spaced repetition, and it's the step almost every "learn to code with AI" guide leaves out.
A 45-Minute Session Routine You Can Copy
Use this for any practice problem: a homework exercise, a past paper question, a small project feature.
Write in comments what the program must do, the inputs, the outputs and the steps. No AI yet.
Code it yourself. Run it. Note every error and every place you weren't sure what to type.
Paste your attempt and the error. Use the Rule 2 prompts: hints and explanations, not corrected code.
Make the fix in your own words. If the AI showed you a snippet, close it and type it from memory.
Write one card for each concept or bit of syntax you looked up, plus one card for the bug you made. Then you're done.
This is deliberate practice for programming: a specific goal, your own effort at the edge of your ability, and feedback right after.
A good tutor prompt to start every session
Paste this at the top of a new chat with your assistant:
I'm a student learning to program in Python. Act as a tutor, not a code generator. - Never write a full solution unless I type "show me". - When I share code, ask me what I expect it to do before you comment. - Point to the line and the concept that's wrong; let me write the fix. - Explain error messages in plain words, then ask what I think the cause is. - At the end, list the concepts I needed help with, so I can make flashcards.
Swap "Python" for Java, C# or whatever your course uses.
Keep What You Look Up: Your AI Assistant + Notesmakr
Rule 4 is the one that slips, because making cards after a long coding session is the last thing you want to do. So let the assistant write them.
Notesmakr is a notes maker and study app that turns material into notes, flashcards, quizzes and mind maps, then schedules your reviews. If you code in Claude Code or Cursor, you can connect them to Notesmakr with a personal access token from the app (Settings, Connect AI assistants), and the assistant can save cards straight into your library. Our plain-English explainer on MCP for students covers how the connection works, and the setup guides walk through each assistant.
At the end of a session, ask:
"Make a standalone Notesmakr flashcard deck called 'Python: week 6'. Write cloze cards for each piece of syntax and each concept I asked you about today, and one card for the bug I made and why it happened."
What you get:
| You looked up | The cloze card the assistant writes |
|---|---|
| How to loop over a list with its index | for i, item in {{enumerate}}(items): |
Why your function returned None | A function with no {{return}} statement returns None |
| The bug you made | Use {{==}}, not =, to compare values in an if condition |
The honest details:
- Standalone decks are free. They land in the app's Practice tab. Creating a full note through the connection uses 1 note from your plan (the free plan has 5).
- The assistant writes the content; Notesmakr runs no AI on this path. Your assistant itself may be a paid product.
- Claude Code and Cursor connect today. ChatGPT, the Claude.ai website and the Claude phone apps can't connect yet.
- The token can only add. It can't read, change or delete what's already in your library.
- Notesmakr doesn't run code or teach programming. It's where the cards live and get reviewed: the free SM-2 scheduler brings each one back just before you'd forget it.
No assistant set up? Upload your lecture slides or a chapter of your textbook to the PDF to flashcards tool, or test yourself on a topic with the AI quiz maker. AI generation is free within the free plan's limits of 5 notes and 40 generations. For the bigger picture on AI-made cards, see our complete guide to AI flashcards.
Watch: Using AI to Study and Learning to Code
Justin Sung, a learning coach, explains why asking a chatbot for answers feels efficient but skips the processing that builds understanding. His point applies directly to code: use the AI to question you, not to replace you.
CS Dojo's advice predates AI tutors, and that's useful: the fundamentals of learning to program (good resources and a project you actually build) haven't changed. AI changes how fast you get unstuck, not what you need to practise.
The Wrong Way vs the Right Way
Same student, same homework (a function that counts vowels in a string), same 40 minutes.
Student: "Write a Python function that counts vowels."
AI: A neat four-line solution using a generator expression.
Student: Pastes it, it passes the tests, moves on.
Two weeks later, in a timed test: can't remember how to loop over a string or why in "aeiou" worked. Blank page.
Student: Writes a loop that misses capital letters. Asks: "Don't fix it. Why does my count come out low?"
AI: "What happens when the loop reaches 'A'?" Student spots it, adds .lower().
Student: Asks for a more idiomatic version, closes it, retypes it from memory. Saves cards for .lower(), in with strings, and the capital-letter bug.
Two weeks later: the cards came back twice. Writes the function in three minutes.
Common Mistakes When Learning to Code With AI
Mistake 1: Asking before trying. The question arrives before the confusion does, so there's nothing for the answer to fix. The fix: Ten minutes of your own attempt first, every time.
Mistake 2: Accepting code you can't explain. If you can't say what each line does, you don't own it, and an "almost right" line will catch you later. The fix: Before you keep any AI suggestion, explain it out loud, line by line. That's the Feynman Technique applied to code.
Mistake 3: Using an autocomplete tool while learning syntax. Inline suggestions finish your lines before you've had to recall them. The fix: Turn inline completion off for practice exercises. Use chat for questions instead.
Mistake 4: Only ever working with AI open. Exams, interviews and timed tests have no assistant. The fix: Do at least one practice problem a week with no AI at all, under time pressure.
Mistake 5: Letting the session end in the chat. Everything you looked up is gone the moment you close the tab. The fix: Five minutes at the end to save cards, then review them on a schedule.
The Research Behind It
- Stack Overflow (2025): 2025 Developer Survey, AI section. 66% of respondents named almost-right AI solutions as a frustration; 45.2% said debugging AI-generated code is more time-consuming.
- Bastani, H., Bastani, O., Sungu, A., Ge, H., Kabakcı, Ö. & Mariman, R. (2025): "Generative AI Without Guardrails Can Harm Learning: Evidence from High School Mathematics." PNAS, 122(26). Read the paper.
- Prather, J., et al. (2024): "The Widening Gap: The Benefits and Harms of Generative AI for Novice Programmers." ICER 2024. Read the paper.
- Kazemitabaar, M., et al. (2023): "Studying the Effect of AI Code Generators on Supporting Novice Learners in Introductory Programming." CHI 2023. Read the paper.
- Slamecka, N. J. & Graf, P. (1978): "The Generation Effect: Delineation of a Phenomenon." Journal of Experimental Psychology: Human Learning and Memory.
- Roediger, H. L. & Karpicke, J. D. (2006): "Test-Enhanced Learning." Psychological Science. Read the paper.
FAQ
Should I use AI to learn to code?
Yes, as a tutor rather than a code generator. Use it to explain error messages, give hints, and review code you've already written. Avoid asking it to write solutions before you've tried, because research on students suggests unrestricted AI help can raise practice scores while leaving you weaker once the tool is gone.
Can you learn programming with ChatGPT or Claude?
You can learn a lot with either, as long as you do the writing. Ask for explanations, hints and questions instead of finished code, retype anything you're shown, and test yourself without the assistant regularly. Neither replaces a structured course, so pair one with your class, textbook or a free beginner course.
Is it cheating to use AI for coding homework?
It depends on your course. Some teachers allow AI for explanations, some forbid it on any assessed work, and exam boards set their own rules for coursework. Check your syllabus or ask your teacher. Using AI to understand a concept during practice is usually different from submitting AI-written code as your own.
What's the best way to learn Python with AI?
Write each exercise yourself first, then paste your attempt and ask the assistant what concept you're missing, without corrected code. Retype any snippet it shows you from memory. After each session, turn the syntax and concepts you looked up into flashcards and review them on a spaced schedule so they stick.
How do I stop relying on AI when coding?
Set a rule: ten minutes of your own attempt before any question. Turn off inline autocomplete for practice work, and do one timed problem a week with no AI at all. Keep a list of what you had to look up and review it with flashcards, so you need to ask less often.
Start Today
Learning to code with AI comes down to one idea: let the assistant explain, and keep the writing and the remembering for yourself.
- Paste the tutor prompt into your assistant before your next session.
- Attempt first, for ten minutes, every problem.
- Ask for explanations, not fixes, and retype anything you're shown.
- Save cards for what you looked up, and the bug you made.
- Review them for ten minutes a day, and do one AI-free problem each week.
The code you can write without help is the only code you've actually learned.
