Debug and fix simple errors in Claude Code
Debug and fix simple errors in Claude Code using error messages, logs, stack traces, and the ultrathink keyword.
Lesson Content
You don't need a fancy prompt to have Claude Code fix bugs. You can just paste in the error message, and Claude Code is smart enough to figure out what to do.
That said, a little context goes a long way. Sometimes the error message alone isn't enough for Claude to pinpoint the issue.
Interrupting the AI when errors occur
In my Laravel app, I have Vite installed which automatically reloads the site as changes are happening. Claude Code will occasionally write something that contains a bug -- like referencing a variable that wasn't created yet, or forgetting to close a bracket on an if-else statement (though it continues to get better with this over time).
If you're like me and like to test the UI live while Claude Code is working, an error could prevent you from seeing other changes as they happen. In this case, I typically interrupt Claude Code with Ctrl + C, and then paste the error message into the prompt, along with any other pertinent information that might help it resolve the issue.
If you can, include the specific line of code where things went wrong, along with the file path. Stack traces are also super helpful to the AI as it can read through them methodically, trace the execution path back through your code, and propose very targeted solutions or fixes.
Claude Code's messaging workflow
Because you never know when or where Claude may create an error in your app, I went ahead and manually added one to this app by leaving out the endif clause of a conditional in a view template. This single error will prevent other updates that Claude Code is currently making from appearing in your window if it is included in the page you are currently on.
If you're right in the middle of a coding session, go ahead and paste the error directly into the prompt and submit it. When Claude completes whatever it's working on, or stops thinking -- it will process the message and proceed with attempting to fix the bug.
Claude Code is very good at recognizing one-off errors, so it will likely fix the bug first, then continue working on whatever it was doing before. If it just stops after fixing it, don't hesitate to send a "Continue with whatever you were working on before fixing this error." message.
Other debug methods
I typically copy and paste the message from Laravel's error screen. But if you aren't using Laravel, just about all other apps write error messages to application log files. In Laravel, the default location is storage/logs/laravel.log.
If you have application logs available, you can just command the AI to inspect them to fix the error. You don't even need to open up the log file yourself!
For those harder-to-debug issues, ensure that you have a higher effort level set with /effort. If you are really stuck, don't hesitate to add an "ultrathink" keyword to the mix, which will bump up Claude Code's reasoning level to the highest level for a more efficient debugging session.