410 words
2 minutes
How to Reduce AI Hallucinations and Cut Token Costs

How to Reduce AI Hallucinations and Cut Token Costs#

I spent a couple months vibe coding with AI and figured out how to stop AI hallucinations and save on tokens. Here are 4 strategies that actually work.

1. Break Large Tasks Into Step-by-Step Prompts#

When working with large codebases, divide your prompts into small steps instead of asking AI to do everything at once. This helps reduce hallucinations and prevents AI from being stuck in loops (“Let me reconsider… Wait actually… Let me reconsider… Wait actually… Let me reconsider… Wait actually…”). You don’t need shorter prompts, but you need sequential ones. Instead of saying “build a house,” ask AI to build the foundation, then the walls, then the roof.

2. Help AI Understand Persistent Bugs#

When AI struggles to fix a bug due to hallucination, teach it what’s causing the problem. Don’t just say “the car isn’t moving.” Start by asking what makes a car move. AI will answer: “the engine.” Then you can say: “I think the engine is broken. Check it.” Once AI fixes the bug, have it document what it did. Create a lessons folder in root with markdown files logging each fix. Next time you have a similar issue, point AI to the lessons folder instead of letting it hallucinate a solution.

3. Use New Chat Sessions for Separate Tasks#

Start a fresh chat session for each separate task instead of keeping one long conversation going. Long sessions cause AI to reference unnecessary previous conversations and burn additional tokens. Let’s say you’ve been working on a bird. If you start working on a dog in the same chat, the AI will refer to previous context and ask you things like “Do you want wings on your dog like the bird?” A new chat keeps things clean and helps AI concentrate on the current problem without getting distracted by past context.

4. Monitor Your Token Usage and Costs#

AI stores memories as local files, usually in hidden directories rather than your project folder, and reads them each chat, consuming tokens every time. To delete them, say Clear all memories including local, session, and workspace. In Step 2, I introduced the lessons folder. If I named it “memories,” AI might recognize it as project memory storage and accidentally delete it.

As your codebase grows, expect 10K+ tokens per chat. Using cheap models like DeepSeek V4 Flash can still cost around $0.50-$2/hour, which adds up to $100-$200/month. If you’re just building hobby projects, consider free models on OpenRouter instead.

How to Reduce AI Hallucinations and Cut Token Costs
https://blog.juyung.com/posts/en/2026/09/05/
Author
Jay Juyung
Published at
2026-09-05
License
CC BY