Avoid These Common Mistakes When Coding With ChatGPT

July 1, 2025

Avoid These Common Mistakes When Coding With ChatGPT

Avoid These Common Mistakes When Coding With ChatGPT

AI has already changed the role of the developer in a positive way. It has become a powerful tool for improving efficiency, especially with repetitive or less complex tasks. When you’re using ChatGPT for coding, it’s essential to understand its limitations and how to work around them. These are the issues I’ve encountered and the solutions that have worked for me.

Rewriting and Optimizing Everything

Everyone runs into this when using an AI tool like ChatGPT. You paste an entire code file into the chat and ask it to fix one specific issue. But then ChatGPT suddenly rewrites other functions that were totally fine. It also “optimizes” other parts without telling you. I’m sure this sounds more than familiar to you.

Solution: Tell ChatGPT to make only the changes necessary to solve the issue and no optimizations. Also, tell it to always comment on the lines it changed.

Weird Workarounds

If you tell ChatGPT to do something in a specific way, it won’t question you. It will just do it, even if it’s completely impractical or not best practice.

Solution: Ask ChatGPT if your approach is a best practice or if it is rather unusual and if there is a better one. Also, you can open a new chat to get an unbiased answer that isn’t influenced by your previous conversation.

No Follow-up Questions

ChatGPT usually doesn’t ask follow-up questions. That means if you don’t give it all the information, it will make assumptions which might not match your use case.

Solution: You can ask ChatGPT to check the given information for holes and provide follow-up questions before continuing.

Inventing Libraries

Hallucination is a widely known problem of AI in general. Inventing libraries can be especially dangerous if an attacker realizes ChatGPT always references a specific non-existent library and then creates that library with malicious code in it.

Solution: Always verify libraries mentioned by ChatGPT. Stick to well-documented, widely used packages.

Forgetting Details

If your chat gets long, ChatGPT might perform worse and forget details because of its limited context window.

Solution: Use the edit function for messages that don’t matter much for your main thread (e.g., minor bug fixes or clarification on merge conflicts). Or move unrelated issues to a separate chat to protect context.

Stuck in a Loop

Sometimes, with more complex coding tasks, ChatGPT gets stuck in a loop. It gives you a response that doesn’t change anything meaningful or solve the issue. It’ll repeat the same approach dozens of times if you don’t interrupt it. And if you’re using the o3 model, you’ll notice it stops “reasoning” and just immediately answers your prompt.

Solution: Explicitly tell ChatGPT to stop repeating the same solution and reframe the problem. You can also ask it to summarize all the relevant details it currently has available. This will help you spot any incorrect assumptions or missing context.

Lack of Security

Usually, if you don’t explicitly ask for it, ChatGPT won’t address security at all.

Solution: Actively ask ChatGPT to highlight insecure code or missing best practices. Make sure you’re familiar with the OWASP Top 10 vulnerabilities and understand how to write secure code.

Contents