Ways to ask Claude to debug
1) Asking for verification - do not use a generic prompt.
I'm working on a project to upgrade a liferay project from 7.2 to 7.4. Whenever I encounter an error, I would usually form a hypothesis in my mind, and ask Claude to verify if it's true or not. For example, I am having an issue with a library declared in build.gradle not being found in one of the module. The library being used in 7.2 was:
compileOnly group: "javax.portlet", name: "portlet-api"
compileOnly group: "javax.servlet", name: "javax.servlet-api"
But in 7.4, Claude recommended me to replace javax with jakarta.
compileOnly group: "jakarta.portlet", name: "portlet-api"
compileOnly group: "jakarta.servlet", name: "jakarta.servlet-api"
Upon building, I get an error:
> Could not find jakarta.portlet:portlet-api:.
Required by:
project :modules:thebank-cam-module:thebank-cam-services
> Could not find jakarta.servlet:jakarta.servlet-api:.
Finding it weird, I went ahead to the project settings.gradle file, and find out the source of the library, which is in
repositories {
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
I checked the repository, and the library - compileOnly group: "jakarta.servlet", name: "jakarta.servlet-api", does exist.
Normally, I would just feed the error message to Claude, have it identify the root cause of the issue, and suggest a solution. And guess what's Claude solution, removing the library out of build.gradle
Therefore, I tried changing the way to ask Claude, for example,
<verify>the library is getting from "https://repository-cdn.liferay.com/nexus/content/groups/public" defined in settings.gradle, and the library exists in the repository.</verify><instructions>identify the source of the library <verify>jakarta.servlet", name: "jakarta.servlet-api is an existing library, and there is no other library that replaces that.</verify>, and identify the root cause of why Could not find jakarta.servlet:jakarta.servlet-ap as shown in the deploy log</instructions>
2) Asking Claude in another angle
I'm developing a game in Unity, specifically a first person shooter game, and I'm coding the mechanic for first person view camera rotation + movement. The issue I'm facing is that, when hitting the key 'D', and moving the camera to the left, the player's movement feels like opposing movement vectors are cancelling each other out. So I prompted Claude with the following :
<context>option a fix still causes the issue to persist - where when user hit d, and rotate mouse to left, moving the mosue to left causes the plalyer movement to go to the left, which cancels out the movement done by hitting d. the goal is to move the player to the left (hit d) to the direction where the player is facing. option b does not do that, it is fixed by the axis, but not the player's camera angle. so for example, if player is facing z, and hitting d will move player to the x, and hitting a will move player to -x. and so on</context><instructions>identify a fix to achieve the goal</instructions>
Basically, the prompt tells Claude to fix the lateral movement influence caused by the player looking around, and Claude responded with the root cause that it's caused by using different udpate functions causes the movement behavior to desynchronize. Claude explained it quite convincingly, and I was optimistic that Claude fixed the issue. But when I ran game with the fix, the issue still occurs.
So, I changed the approach to asking Claude by prompting:
I realized that you are providing me the wrong solution, perhaps I am labelling the issue wrongly. Ask me questions about the issues at hand, so you can give me a more accurate and focused solution that works.
By using this approach, I was able to fix the issue.
3) Don't stop until the issue is fixed.
I've came across this reddit post on how to have Claude troubleshoot issue. https://www.reddit.com/r/PromptEngineering/comments/1s2dr1u/53_prompts_that_catch_code_bugs_before_your_team/, and it gave me an idea on how I should ask Claude to help me troubleshoot issues. Instead of asking Claude for information about the issue, why not have Claude fix it for you?
So instead of asking how the process works in the background, I gave Claude the literal issue I'm facing, the expected outcome, and asked Claude to NOT STOP until the issue is fixed. Here is the exact prompt I used:
`resolve the accountentrylocalserviceimpl is unsatisfied, and don't stop until it's fixed`
4) Have Claude auto verifies itself
This is one of my favourite ways to prompt in Claude. Often times we would prompt to resolve symptoms, not root causes. But it would be much better if we can resolve issues by resolving the root cause itself, and have the system auto verifiies itself.
For example, sometimes, we would hit an issue, for example, a user can see a website is really slow, and would think that the number of CPU is insufficient (the symptom), but in reality, its database query that scans 10 million rows because of a missing index (root cause).
Then, have Claude study the entire pipeline and lifecycle of the process related to the root cause. Then, in each stages in the pipeline, create verifiers, coupled with the input, expected output, verification method and error signature, then, identify the point where the expected output starts to diverge to pinpoint the root cause. Put your findings in a html file in <file>
Example:
<context>the issue right now is, when visiting http://localhost:8080/group/ep/~/control_panel/manage after logging in, the control menu does not show up. <example>the example of the control menu im referring to is this [Pasted text #1 +154 lines]</example>. the goal is to be able to see the control menu when visiting the page.</context><instructions>study the entire lifecycle and pipeline of how the control menu shows up. in each stage of the pipeline, identify the input, expected output, the verification method and the error signature. then, identify the point where the expected output starts to diverge to pinpoint the root cause. put your findings in a html file in C:\Miscellaneous\21062026 - Control Panel doesn't show up when visiting control panel. and do not refer to other html file, just focus on your own findings</instructions>
5) Be specific in how you prompt
Instead of prompting generically like, "Fix this problem", give a deteailed description on what you want to acheive, and feed as much context as you can. For example, if you have a login page that keeps redirecting you. Instead of asking, "The login page redirects infinitely. Fix the issue.".
Comments
Post a Comment