# How to learn while coding with an AI agent

Keep the thinking on your side. Predict what code will do before you run it, ask the agent for a hint instead of the fix, explain its diff back in your own words, review what you learned days later, and write the next similar piece without help.

By João Marcos Torres Gardingo. Updated November 16, 2026. https://klugg.app/en/guides/learn-while-coding-with-ai

## In short

- In a randomized study by Shen and Tamkin (2026), developers who learned a new Python library with an AI assistant scored 17% lower on a skills quiz and were not significantly faster.
- In the same study, developers who asked the AI conceptual questions or asked for explanations averaged 65% or more on the quiz. Those who handed it the code averaged under 40%.
- In a high school math trial by Bastani and colleagues (2025), open GPT-4 access raised practice grades 48% but cut exam grades 17% once the access was removed.
- Five habits keep you learning with an agent: predict before you run, ask for a hint, explain the diff back, review days later, and write the next piece yourself.

## Does coding with an AI agent stop you from learning?

Coding with an AI agent can stop you from learning, depending on how you use it. In a randomized study, developers who learned a new Python library with an AI assistant scored 17% lower on a skills quiz than developers who worked without AI. On average, they were not significantly faster ([Shen and Tamkin, 2026](https://doi.org/10.48550/arXiv.2601.20245)).

The main experiment had 52 developers. All had more than a year of Python experience and had never used Trio, the library they had to learn. The quiz checked conceptual understanding, code reading and debugging. The 17% gap was about 4 points on a 27-point quiz. The study was preregistered, and the paper is a preprint, so it was posted before peer review ([Shen and Tamkin, 2026](https://doi.org/10.48550/arXiv.2601.20245)). The authors sum it up in their abstract:

> AI-enhanced productivity is not a shortcut to competence

## What does other research say about AI help and learning?

Other research on AI help points the same way: better work during practice does not always mean more learning. In a high school math trial with nearly a thousand students, open GPT-4 access raised practice grades by 48%. When the access was removed, those students scored 17% lower than students who never had it ([Bastani et al., 2025](https://doi.org/10.1073/pnas.2422633122)).

- **Guardrails changed the result.** In the same trial, a tutor version with teacher-designed hints instead of answers raised practice grades by 127%. It largely removed the harm on the exam. The authors say students without guardrails used GPT-4 as a "crutch" ([Bastani et al., 2025](https://doi.org/10.1073/pnas.2422633122)).
- **A better product is not more knowledge.** In a writing experiment with 117 university students, the ChatGPT group improved their essay scores more. Their knowledge gain and transfer did not differ from the other groups. The authors warn of "metacognitive laziness" ([Fan et al., 2024](https://doi.org/10.1111/bjet.13544)).
- **Beginners were not always harmed.** In a study with 69 novices aged 10 to 17, access to an AI code generator gave 1.8 times higher scores on coding tasks. It did not lower scores on tasks done by hand. One week later, the AI group did slightly better, but the difference was not significant ([Kazemitabaar et al., 2023](https://doi.org/10.1145/3544548.3580919)).
- **A well-designed AI tutor helped.** In a Harvard physics course with 194 students, an AI tutor built on the same teaching practices as the class gave a higher median post-test score than an active-learning class, 4.5 against 3.5, in less time ([Kestin et al., 2025](https://doi.org/10.1038/s41598-025-97652-6)).

For more on studying with chatbots, see [does studying with AI work](https://klugg.app/en/guides/does-studying-with-ai-work).

## Which ways of using AI kept developers learning?

Developers kept learning when they used the AI to understand, not to finish. In the Trio study, people who asked only conceptual questions, or asked for code together with an explanation, averaged 65% or more on the quiz. People who handed the whole task to the AI, or let it debug for them, averaged under 40% ([Shen and Tamkin, 2026](https://doi.org/10.48550/arXiv.2601.20245)).

| How the developer used the AI | Average quiz score |
| --- | --- |
| Asked only conceptual questions, then wrote the code | 65% or more |
| Asked for code together with an explanation of it | 65% or more |
| Generated code, then asked follow-up questions to understand it | 65% or more |
| Let the AI write all the code | Under 40% |
| Asked a few questions, then handed over all the code | Under 40% |
| Relied on the AI to debug or check the code | Under 40% |

Each group was small, from 2 to 7 people, and people chose their own style. So these patterns show what went with learning, not proof of cause. The authors link the higher scores of the group without AI to running into errors and fixing them alone ([Shen and Tamkin, 2026](https://doi.org/10.48550/arXiv.2601.20245)).

## How do I learn while coding with an AI agent?

To learn while coding with an AI agent, keep the thinking on your side. Predict what code will do before you run it. Ask the agent for a hint, not the fix. Explain each diff back in your own words. Review what you learned days later. Then write the next similar piece yourself, without help.

### 1. Predict before you run

Before you run the agent's code or a test, write down what you expect: the output, the error, or which test fails. Then run it and compare. In a lab study, people who predicted an outcome before seeing it learned more facts than people who judged the outcome afterward. Wrong predictions caused surprise, and stronger surprise went with more learning ([Brod et al., 2018](https://doi.org/10.1016/j.learninstruc.2018.01.013)). That study taught geography, not code. In programming, many students in a seven-country study were weak at predicting what a short piece of code would output ([Lister et al., 2004](https://doi.org/10.1145/1041624.1041673)). Prediction is a skill you can train.

### 2. Ask for a hint, not the fix

When something breaks, look for the cause yourself first. Then ask the agent for one hint and tell it not to edit files. In the math trial, teacher-designed hints instead of answers largely removed the harm of open GPT-4 access ([Bastani et al., 2025](https://doi.org/10.1073/pnas.2422633122)). In the Trio study, the people who let the AI debug for them were among the lowest scorers ([Shen and Tamkin, 2026](https://doi.org/10.48550/arXiv.2601.20245)).

### 3. Explain the diff back in your own words

When the agent writes code, read the diff and explain each change before you accept it, out loud or in a note. If you cannot say why a line is there, ask the agent about that line. In the Trio study, one high-scoring group generated code and then asked follow-up questions until they understood it. Explaining material to yourself is a well-studied way to learn. See [self-explanation](https://klugg.app/en/guides/self-explanation).

### 4. Review what you learned days later

Write down each new idea in one or two sentences, such as "a Python generator does not run its body until you ask for the next value". A few days later, answer a question about it without the agent. Testing yourself improved classroom learning across 222 studies, with a medium effect (g = 0.499) ([Yang et al., 2021](https://doi.org/10.1037/bul0000309)). Spacing the reviews also helps you remember longer ([Cepeda et al., 2006](https://doi.org/10.1037/0033-2909.132.3.354)). See [retrieval practice](https://klugg.app/en/guides/retrieval-practice) and [spaced repetition](https://klugg.app/en/guides/spaced-repetition).

### 5. Write the next similar piece yourself

After the agent shows you one solution, write the next similar function, test or query alone. Then ask the agent to review it. In experiments on learning from examples, learners did better on similar problems when the worked steps were removed one at a time until they solved problems alone ([Renkl et al., 2002](https://doi.org/10.1080/00220970209599510)). See [worked examples](https://klugg.app/en/guides/worked-examples).

## What should I tell my coding agent?

Tell your coding agent what kind of help you want before you start. A short instruction at the start of a session changes what the agent does. The table pairs common requests with versions that keep you doing the thinking. Use them when the goal is to learn the skill, not only to ship the change.

| Instead of | Try |
| --- | --- |
| "Fix this error." | "Give me one hint about where this error comes from. Do not edit any files." |
| "Write the function." | "Write the tests first. I will write the function, then you review it." |
| "Implement this feature." | "Explain the approach in a few steps. I will write the first step." |
| "Explain this code." | "Ask me what I think this code does, then correct me." |
| "Looks good." | "Ask me three questions about this diff before I accept it." |

## When is it fine to let the agent write the code?

Letting the agent write the code is fine when you do not need to own the skill: a one-off script, boilerplate you already understand, or a format you will never touch again. In the Trio study, developers who delegated fully gained some speed, but at the cost of learning the library ([Shen and Tamkin, 2026](https://doi.org/10.48550/arXiv.2601.20245)). Decide per task which one you want.

A useful test: will you need to debug or review this kind of code later? If yes, learn it now. Checking AI code is hard in an area you never learned.

## What mistakes stop you from learning with an agent?

The mistakes that stop you from learning with an agent all hand your thinking to the agent. Common ones are accepting a diff you cannot explain, pasting every error straight into the chat, judging progress by finished tasks, and never coding without the agent. Each one feels fast, and each one skips the step that builds the skill.

- **Accepting a diff you cannot explain.** You now own code you do not understand. Ask about each line you cannot explain.
- **Pasting every error into the chat.** Read the error and guess the cause first. That guess is the practice.
- **Judging progress by finished tasks.** Count what you can do alone a few days later.
- **Never coding without the agent.** Write a small piece alone each week to see where you stand.

## How Klugg does this

Klugg is an AI study tutor that runs in the browser, separate from your coding agent. When a coding session leaves you with a topic worth keeping, you can describe it to Klugg as a goal. Klugg writes a lesson with cited sources, checks what you learned with practice that follows the habits above, and schedules reviews.

- For a code topic, you write a JavaScript or Python function in a code editor in your browser. Tests run there and check it, with no AI grading.
- In "Predict, then compare", you predict what a small change will cause, explain why, then compare with the expected result. In "Teach it back", you explain a topic and Klugg asks up to three follow-up questions.
- Hints come before answers: first a hint, then a worked step, then the answer. An answer given after a hint counts as answered with help.
- Practicing a topic adds it to spaced reviews scheduled with FSRS, so you answer it again later, without the agent.

Klugg's hosted beta is invite-only, and Klugg has not been tested in a trial of its own. To try it, join the waitlist on the [home page](https://klugg.app/en).

## Questions

### Does using Claude Code or Cursor make you a worse programmer?

Not by itself. In one randomized study, developers who let AI write code for a new library learned less of it. Developers who asked conceptual questions or asked for explanations kept their quiz scores high. How you use the agent matters more than whether you use it.

### How do I make an AI coding agent teach me instead of writing the code?

Tell it at the start of the session: do not edit files, give one hint at a time, ask me what I expect before running anything, and ask me to explain each change. Then write the code yourself and ask the agent to review it.

### Should beginners use AI coding agents?

They can, with limits. In a study with 69 novices aged 10 to 17, an AI code generator raised task scores and did not hurt later tasks done by hand. Try each problem first, ask for hints, and check yourself without the AI.

### How do I remember what I learned from an AI agent?

Write the idea down in one or two sentences. A few days later, answer a question about it without the agent, and repeat at longer gaps. Answering from memory and spacing the reviews both help you keep what you learned.

## Sources

1. Shen, J. H., & Tamkin, A. (2026). How AI impacts skill formation. arXiv preprint 2601.20245 (preregistered randomized experiment). https://doi.org/10.48550/arXiv.2601.20245
2. Bastani, H., Bastani, O., Sungu, A., Ge, H., Kabakcı, Ö., & Mariman, R. (2025). Generative AI without guardrails can harm learning: Evidence from high school mathematics. Proceedings of the National Academy of Sciences, 122(26), e2422633122. https://doi.org/10.1073/pnas.2422633122
3. Fan, Y., Tang, L., Le, H., Shen, K., Tan, S., Zhao, Y., et al. (2024). Beware of metacognitive laziness: Effects of generative artificial intelligence on learning motivation, processes, and performance. British Journal of Educational Technology, 56(2), 489-530. https://doi.org/10.1111/bjet.13544
4. Kazemitabaar, M., Chow, J., To, C. K., Ericson, B. J., Weintrop, D., & Grossman, T. (2023). Studying the effect of AI code generators on supporting novice learners in introductory programming. CHI Conference on Human Factors in Computing Systems. https://doi.org/10.1145/3544548.3580919
5. Kestin, G., Miller, K., Klales, A., Milbourne, T., & Ponti, G. (2025). AI tutoring outperforms in-class active learning: an RCT introducing a novel research-based design in an authentic educational setting. Scientific Reports, 15, 17458. https://doi.org/10.1038/s41598-025-97652-6
6. Brod, G., Hasselhorn, M., & Bunge, S. A. (2018). When generating a prediction boosts learning: The element of surprise. Learning and Instruction, 55, 22-31. https://doi.org/10.1016/j.learninstruc.2018.01.013
7. Lister, R., Adams, E. S., Fitzgerald, S., et al. (2004). A multi-national study of reading and tracing skills in novice programmers. ACM SIGCSE Bulletin, 36(4), 119-150. https://doi.org/10.1145/1041624.1041673
8. Yang, C., Luo, L., Vadillo, M. A., Yu, R., & Shanks, D. R. (2021). Testing (quizzing) boosts classroom learning: A systematic and meta-analytic review. Psychological Bulletin, 147(4), 399-435. https://doi.org/10.1037/bul0000309
9. Cepeda, N. J., Pashler, H., Vul, E., Wixted, J. T., & Rohrer, D. (2006). Distributed practice in verbal recall tasks: A review and quantitative synthesis. Psychological Bulletin, 132(3), 354-380. https://doi.org/10.1037/0033-2909.132.3.354
10. Renkl, A., Atkinson, R. K., Maier, U. H., & Staley, R. (2002). From example study to problem solving: Smooth transitions help learning. The Journal of Experimental Education, 70(4), 293-315. https://doi.org/10.1080/00220970209599510
