Debugging & fixing errors
Strategies for diagnosing and fixing issues when things go wrong.
These strategies help you build more complex apps efficiently while keeping token usage under control.
Don’t try to describe your entire app in one message. Build it up in phases, using the right model for each stage.
Set up the core structure: screens, navigation, and data models. Use Opus or Auto for this — a strong foundation saves rework later.
Create a recipe app with 4 screens: Home (recipe grid), Recipe Detail, Add Recipe form, and Favorites. Use bottom navigation. Dark theme with orange accents.
Add features one at a time. Each message builds on the previous result. Verify each feature works before adding the next.
Add search functionality to the Home screen with a search bar at the top that filters recipes by name.
Add the ability to save recipes to favorites with a heart icon on each recipe card.
Add a pull-to-refresh gesture on the Home screen that reloads the recipe list.
Switch to Sonnet for quick, cost-effective refinements:
Add a loading spinner when the recipe list is being loaded.
Show an empty state illustration when no recipes match the search.
Make the recipe card corners more rounded and add a subtle shadow.
Set your app icon, test on your device, and publish. See Publishing Overview for all platform options.
As your app grows, @file: references become essential for directing the AI to the right place.
@file:lib/screens/home_screen.dart, add a pull-to-refresh gesture”@file:lib/widgets/recipe_list.dart doesn’t scroll when there are more than 10 items”@file:lib/screens/settings.dart match the style of @file:lib/screens/profile.dart”Without file references, the AI might modify unrelated files or create new files when it should be editing existing ones. This matters more as your project grows beyond a few screens.
See Attaching Context for details on the @file: syntax.
After the AI has made many changes, your codebase can accumulate redundancy — duplicate functions, unused imports, overly nested logic. Use the Prompt Library’s Review & Simplify Code template periodically to clean up.
A good rule of thumb: run it after every 5-10 feature additions, or whenever you feel the AI’s responses are getting slower or less accurate (a sign that the codebase complexity is working against it).
Different tasks have different complexity. Match the model to the work:
| Task | Model | Why |
|---|---|---|
| App foundation and navigation | Opus | Complex structure needs deep reasoning |
| Multi-screen features | Opus or Sonnet | Moderate-to-high complexity |
| Simple text or color change | Sonnet | Fast and efficient for straightforward edits |
| Adding a single button or field | Sonnet | Straightforward edit |
| Design-heavy work | Opus | Best visual output |
| Quick bug fix | Sonnet | Clear fix, low complexity |
| Not sure | Auto | Let the system choose |
A color change on Sonnet costs less than what Opus would charge. Over the course of building an app, strategic model switching can save significant tokens.
See Model Selection for full details on each model.
Vague debugging requests can cause the AI to enter loops — making changes, finding new things to adjust, and consuming tokens without meaningful progress.
Instead: Describe the specific issue: “The login button doesn’t navigate to the home screen after successful authentication.”
The AI may complete 80% of a multi-part request and miss the rest. You’ll then spend additional tokens on follow-ups to catch the gaps.
Instead: One feature per message. Verify each before moving on.
If the AI keeps getting something wrong after 2-3 attempts with different phrasings, stop iterating. You’re spending tokens on diminishing returns.
Instead: Rollback to a clean state and try a completely different approach. See Rollback for how.
Sometimes the AI delivers partial results — it adds three of four screens, or implements a feature but forgets the navigation to it. When this happens:
Apps with many screens need careful navigation management. Establish the structure early and be consistent in how you reference screens.
Knowing when to rollback saves both time and tokens.
Rollback when:
Iterate when:
See Rollback for step-by-step instructions.
For a typical app build, the workflow looks like this:
Debugging & fixing errors
Strategies for diagnosing and fixing issues when things go wrong.
Building a complete app
End-to-end walkthrough of building a full app from idea to publish.