Back to Handbook

Mastery · Intermediate

Debugging & Optimization

Fixing & Refining

Strategies for breaking Hallucination Loops, conducting Vibe Checks, and using AI to Refactor code for performance and cost.

01

The Hallucination Loop

Sometimes AI tries to fix a bug and creates two new ones. This spiral is a 'Hallucination Loop'. If you find yourself arguing with the AI, Stop.

  • Don't double down. The context window is likely polluted with errors.
  • Revert to the last working commit (Git is essential).
  • Clear the chat history and re-prompt with a cleaner problem description.

02

The Vibe Check

Automated tests are great, but the 'Vibe Check' is the manual human review of the 'Gestalt'.

  • Does the UI feel responsive?
  • Are the animations smooth?
  • Does it solve the user's actual problem?
  • This step cannot be automated. It is the core responsibility of the vibecoder.

03

Optimization & Refactoring

Once it works, make it fast. Use the 'Jeff Dean' persona to optimize your codebase.

01

Algorithmic

Ask AI: 'Identify O(n^2) loops in this file and refactor to O(n)'.

02

Memory

Ask AI: 'Check for memory leaks or unclosed connections'.

03

Cost

Use cheaper models (Haiku/Flash) for simple refactors, save Opus/Sonnet for logic.

04

Tool Chaining for Debugging

If Cursor is stuck, copy the error log and paste it into a 'Reasoning Model' like o1 or Claude 3.5 Sonnet in a separate window. Ask it to diagnose the logic, then paste the solution back.