I spent four hours last Thursday fighting a "hallucination loop" where ChatGPT kept insisting my TypeScript interface was missing a property that was clearly defined in the file I'd uploaded to my Project. This happened despite the file being sitting right there in the "Knowledge" section of the Project.
The fix wasn't a better prompt. It was realizing that over a Project with too many documents creates a "noise" floor that makes the LLM ignore specific lines of code.
The specific failure point
I was building a custom dashboard using Next.js 14 and a complex Zod schema for validation. I had uploaded my entire /types directory and three API documentation PDFs into a ChatGPT Project to keep the context persistent.
Then I hit this:TypeError: Cannot read properties of undefined (reading 'user_id')
I asked the AI why the validation was failing. It replied:
"It looks like your UserSchema is missing the user_id field. Please add it to your interface to resolve the error."
I stared at the screen. The user_id was right there on line 14 of types/user.ts. I told the AI it was there. It apologized, then told me it still couldn't find it.
The bottleneck wasn't the model's intelligence. It was the way ChatGPT Projects handles retrieval. When you dump 20+ files into a Project, the RAG (Retrieval-Augmented Generation) mechanism sometimes retrieves the wrong "chunk" of a file or misses a critical one entirely, leading to those confident but wrong assertions.
How I optimized my AI coding workflow
I stopped treating the Project Knowledge base as a dumping ground. Instead, I shifted to a "Lean Context" strategy.
First, I purged every file that wasn't strictly necessary for the current feature. If I'm working on the frontend UI, I don't need the full AWS infrastructure YAML files in the project knowledge.
Second, I started using "Index Files." Instead of up 10 small .ts files, I concatenated the most important interfaces into a single CONTEXT_MAP.md file.
| Old Approach | New Approach | Result |
| :--- | :--- | :--- |
| 15 separate type files | 1 consolidated CONTEXT_MAP.md | Zero "missing property" hallucinations |
| Full API PDFs | Markdown summaries of endpoints | 40% faster response time |
| Everything in one Project | Feature-specific Projects | Higher accuracy per task |
The difference was immediate. By reducing the number of files the model had to "search" through, the precision of the code generation spiked.
Connecting the dots with community patterns
While cleaning up my local setup, I realized I was basically rebuilding a manual version of what people share in Prompt Sharing circles. The trick isn't the prompt itself, but the structure of the data you feed the AI. I've found that if you're struggling with the "forgetfulness" of a long session, you need to stop relying solely on the Project's uploaded files. I now use a "State Log" file. At the end of every major coding milestone, I ask the AI to summarize the current state of the architecture and any "gotchas" it found. I then save that summary and upload it as a new file to the Project, while deleting the old, outdated summary.
This keeps the context window clean and prevents the AI from referring back to a version of the code from three hours ago.
When to move beyond a single chat
There is a point where the standard Workflows in a chat interface break down. For me, that happens when a project exceeds 5,000 lines of code.
If you find yourself constantly correcting the AI on basic project structure, you've likely hit the "Context Ceiling." This is where I stop using the web interface and move the logic into a dedicated IDE tool or a more structured environment.
If you're just starting to organize your AI-assisted builds, the [PromptCube homepage](/en/) is a great place to see how others are structuring their prompts to avoid the exact loop I fell into.
The "Clean Context" checklist for your next Project
If your AI is starting to hallucinate code that you know exists in your uploaded files, try this:
-
The 5-File Rule: Try to keep your Project Knowledge under 5 high-density files.
-
MD over PDF: Convert your documentation to Markdown. The LLM parses
.mdsignificantly better than formatted PDFs. -
Explicit Referencing: Instead of saying "look at the files," say "Refer to the
UserSchemadefinition inCONTEXT_MAP.mdon line 22." -
The Purge: Every two hours, delete any file that represents a "previous version" of your logic.
The real cost of AI coding isn't the subscription fee; it's the time you lose fighting a model that thinks it knows your code better than you do. Tightening the context is the only way to stop the drift.
Next Should AI companions be banned for under 18s to prevent emotional dependence? →