# Learn to code with AI without skipping the learning

ChatGPT or Claude matters less than how you set it up. Make it a tutor, write each piece yourself first, use it to explain errors and code, and test yourself without it every week.

Guides · v1.0 · draft · https://hayzlabs.com/guides/learn-to-code-with-ai/

In short:
- Either assistant works. Set it up as a tutor that gives hints before answers and asks you to predict what code will do.
- Write it yourself first, run it, read the error, then ask for a hint. Compare with a model answer only after yours runs.
- Once a week, write a small program with the assistant closed. Let it write code for you only once you can read and test it.

## Short answer

Use whichever assistant you already have. We found no study comparing ChatGPT and Claude for learning to code, and the studies below suggest the setup matters more than the brand. Tell it to act as a tutor: hints before answers, explanations you then test by predicting output, and no full solutions. Write each piece yourself first, and once a week write something with the assistant closed. The routine below is our suggestion.

For general study rules (any subject), see [Learning with AI without losing the learning](https://hayzlabs.com/guides/learning-without-losing-the-learning/). To build things with an agent (an AI that can take actions, such as writing and running code, not only chat) without learning to code, see [Coding agents for people who don't write code](https://hayzlabs.com/guides/coding-agents-for-non-coders/). This page is for learning to write the code yourself.

## What the studies show

**Asking for answers can cost the learning.** In a maths trial, a hints-not-answers tutor avoided the exam drop that unrestricted ChatGPT caused ([Bastani et al., PNAS 2025](https://ideas.repec.org/a/nas/journl/v122y2025pe2422633122.html); see [Learning with AI without losing the learning](https://hayzlabs.com/guides/learning-without-losing-the-learning/)). That was maths, not coding, but the pattern repeats below.

**The same for coding, especially debugging.** In an Anthropic trial, 52 mostly junior software engineers learned Trio, a Python library (a ready-made bundle of code). The AI group "averaged 50% on the quiz, compared to 67% in the hand-coding group", and "finished about two minutes faster, although the difference was not statistically significant". The largest gap was on debugging (finding and fixing errors) questions. Those who scored well tended to ask conceptual questions or ask for explanations along with code ([Shen and Tamkin, Anthropic, 2026](https://www.anthropic.com/research/AI-assistance-coding-skills)). The publisher sells an assistant, and the two high-scoring groups named here were small (7 and 3 people).

**Used as a helper, it need not hurt.** In a controlled experiment with 69 novices aged 10 to 17 on 45 Python tasks, access to a code generator (OpenAI Codex) made code-writing scores 1.8 times higher, "while not decreasing performance on manual code-modification tasks". A week later the Codex group did slightly better on post-tests, "although this difference did not reach statistical significance" ([Kazemitabaar et al., CHI 2023](https://arxiv.org/abs/2302.07427)).

**Struggling students may not notice they are struggling.** In 21 lab sessions with novice programmers, 20 of 21 finished the problem. Struggling students "thought they performed better than they did, and finished with an illusion of competence" ([Prather et al., ICER 2024](https://arxiv.org/abs/2405.17739)). Finishing a task is not evidence that you learned it.

**Confident answers can be wrong.** In one study of the free GPT-3.5 version, "52% of ChatGPT answers contain incorrect information" ([Kabir et al., CHI 2024](https://arxiv.org/abs/2308.02312); more in [Fix a computer, phone or app problem with AI, safely](https://hayzlabs.com/workflows/fix-a-tech-problem-with-ai/)).

## Set it up as a tutor

Paste this at the start of a chat, or save it as custom instructions or a project (settings that keep standing instructions for every chat):

```text title="Coding tutor · v1.0"
I am learning <LANGUAGE> from scratch. Act as my tutor, not my coder.
- Never give me a full solution unless I type "SHOW SOLUTION".
- When I am stuck, give one hint at a time, smallest first.
- When you explain code, ask me to predict its output before I run it.
- When I share an error, help me read the message. Do not fix it for me.
- If you are not sure something is correct for <LANGUAGE_VERSION>,
  say so and point me to the official documentation.
My current level: <LEVEL>. Today's goal: <GOAL>.
```

Replace the following:
- `<LANGUAGE>` and `<LANGUAGE_VERSION>`: such as `Python` and `Python 3`.
- `<LEVEL>`: such as `I can write loops and if statements, not functions yet`.
- `<GOAL>`: one small thing, such as `write a function that counts words in a sentence`.

Built-in study or learning modes do a similar job; [Learning with AI without losing the learning](https://hayzlabs.com/guides/learning-without-losing-the-learning/) lists them.

## The practice loop

To run code you need the language on your computer. For Python, [Python For Beginners](https://www.python.org/about/gettingstarted/) shows how to install it.

| Step | What you do | Check |
|---|---|---|
| 1. Write it | Write the code yourself, even if it is wrong. | You typed every line. |
| 2. Predict | Say what it should print before you run it. | Your prediction is written down. |
| 3. Run it | Run it and compare with your prediction. | You know where they differ. |
| 4. Read the error | Read the last line of the error and the line number it names. | You can say what kind of error it is. |
| 5. Ask for a hint | Paste the code and the error, and ask for one hint. | You fixed it yourself. |
| 6. Compare | Once yours runs, ask for a model answer and the differences. | You can explain each difference. |

To understand an error or someone else's code, ask for an explanation, not a fix:

```text title="Explain, don't fix · v1.0"
Explain this <ERROR_OR_CODE> line by line in plain words.
Do not rewrite it. After the explanation, ask me one question
that checks whether I understood it.
---
<PASTE_HERE>
```

Replace `<ERROR_OR_CODE>` with `error message` or `code`, and `<PASTE_HERE>` with the error or code itself. Keep API keys (secret codes that let programs use a paid service), passwords and personal data out of what you paste.

**Build small projects.** Exercises teach syntax (the spelling and grammar rules of code); small projects teach you to break a problem down. Examples (illustrative): a tip calculator, a program that renames files in a test folder, a word counter for a text file, a quiz that reads questions from a file. Ask the assistant to help you plan the steps, then write each step with the loop above.

**Check it against the official docs.** If you are new to programming, start from [Python For Beginners](https://www.python.org/about/gettingstarted/), which links guides for people who have never programmed. The official [Python Tutorial](https://docs.python.org/3/tutorial/index.html) says it "is designed for programmers that are new to the Python language, not beginners who are new to programming", so it suits the stage after your first few weeks. When an answer names a function or option, look it up there before you rely on it ([Check before you trust](https://hayzlabs.com/start/check-before-you-trust/)).

## The weekly check

> [!CHECK]
> Once a week, close the assistant and write a small program from a blank file, with only the official docs open. Pick something like last week's practice, such as a word counter (illustrative). Then read a short program you did not write and predict its output. If you can do both, the learning is sticking. If not, spend next week with fewer hints.

## When to let it write code

> [!OUR RULE]
> Let the assistant write code for you once you can read every line it gives you, predict what it will do, and test it yourself. Until then, it explains and you write. For code you could not write yourself, ask it to explain each line before you run it.

## How to tell it worked

- You can write a small program from a blank file without the assistant.
- You can read an error message and say what it means before you ask.
- You can explain every line of your projects to someone else.
- When the assistant is wrong, you notice.

> [!LIMIT]
> None of these studies tests self-taught adults learning a first language over months. The maths trial was in schools, the coding trials were short and small, and one was run by a company that sells an assistant. The error rate study used an older version of ChatGPT. The tutor setup and the weekly check are our suggestions, built from these results, and not tested together.

## Sources

1. Bastani H et al. Generative AI without guardrails can harm learning: evidence from high school mathematics. PNAS, 2025. Randomised trial, nearly 1,000 students. [Link](https://ideas.repec.org/a/nas/journl/v122y2025pe2422633122.html)
2. Shen JH and Tamkin A. How AI assistance impacts the formation of coding skills. Anthropic, 2026. Randomised trial, 52 engineers; vendor. [Link](https://www.anthropic.com/research/AI-assistance-coding-skills)
3. Kazemitabaar M et al. Studying the effect of AI code generators on supporting novice learners in introductory programming. CHI 2023. Controlled experiment, 69 learners aged 10 to 17. [Link](https://arxiv.org/abs/2302.07427)
4. Prather J et al. The widening gap: the benefits and harms of generative AI for novice programmers. ICER 2024. Lab study, 21 students. [Link](https://arxiv.org/abs/2405.17739)
5. Kabir S et al. Is Stack Overflow obsolete? An empirical study of the characteristics of ChatGPT answers to Stack Overflow questions. CHI 2024. Peer-reviewed study, 517 questions. [Link](https://arxiv.org/abs/2308.02312)
6. Python Software Foundation. Python For Beginners and The Python Tutorial. Official documentation. [Beginners](https://www.python.org/about/gettingstarted/) · [Tutorial](https://docs.python.org/3/tutorial/index.html)
