GPT - Long Code Conversations Fail

It seems after a long conversation of passing code back and forth with GPT, eventually causes it to get REALLY slow, or suddenly break and write code half in text and half in code, or crash entirely.

How can I retain the valuable information from a longer code-related conversation, while also preventing GPT from eventually crashing because it can’t keep up?