BlogAI

Getting Useful Debugging Help From Claude: Context, Hypotheses and Blind Spots

Why AI can give confident wrong answers to a PHP session bug, and how to structure prompts so Claude becomes a useful debugging partner.

Denny Pratama

09 Jun 2026 · 6 min read · AI

Getting Useful Debugging Help From Claude: Context, Hypotheses and Blind Spots

01The Setup

Picture a PHP-based internal tool running on shared cPanel hosting: session-driven authentication, no framework, just vanilla PHP doing its job. Users report that they're getting randomly logged out after switching pages. Classic. The kind of bug that's boring to debug and nearly invisible in logs.

Instead of diving into the code yourself, you decide to use Claude as a first-pass collaborator. Feed it the relevant code, describe the symptoms, see what it surfaces.

What can happen next is genuinely instructive — not because Claude is useless, but because it can be confidently wrong in a way that teaches a lot about how to use AI for code review properly.

02Round One: The Confident Wrong Answer

Say you paste in your session initialization code and describe the problem. Claude comes back quickly with a diagnosis: you aren't calling session_start() before any output, which is causing headers to fail silently on some pages.

Except you are. session_start() is at the very top of every page, before any HTML.

You tell Claude this. It apologizes and gives you a new theory: your session.gc_maxlifetime is probably mismatched with the cookie lifetime, causing premature expiry.

Plausible! But the values in php.ini are fine — both aligned. Dead end.

Third attempt: Claude suggests the session save path might not be writable on your hosting environment. You check the path; it's writable and other sessions are saving fine.

Three confident answers. Three wrong answers.

03What Was Actually Happening

Now suppose the real cause is a page that redirects after setting a session variable, and the redirect lands on a different subdomain than the one where the session cookie was set. The session cookie domain doesn't match, so the browser silently doesn't send it.

A one-line fix. But here's the thing: Claude never could have found this with the information it was given. It got isolated snippets of code and a vague symptom description. The actual bug lived in the intersection of the server configuration, the hosting directory structure, and a redirect URL — none of which were shared.

That's not Claude's failure. That's a failure of the person asking the question.

04Three Mistakes to Avoid

1. Giving it symptoms, not evidence

"Users are getting randomly logged out" is not a useful debugging input. It's a user complaint, not a technical observation. Come with logs, session data, reproduction steps, and environment context. Otherwise it's the equivalent of calling a doctor and saying "I feel bad sometimes."

2. Giving it code out of context

Pasting individual files isn't enough when the bug is architectural — when it requires understanding the whole request flow, the server config, and how pages link to each other. No AI can debug a system it can only see through a keyhole.

3. Treating it like a magic oracle

It's easy to accept a confident-sounding answer as a legitimate hypothesis worth testing before you've even read it critically. That's outsourcing your thinking instead of using the AI as a thinking partner.

05Restructuring the Approach

Here's a prompt structure that gets more useful output:

Step 1: Establish full environment context first

Before sharing any code, write a context block like this:

Environment:
- PHP 8.1 on shared cPanel hosting
- No framework — vanilla PHP
- Session storage: default file-based
- Directory structure: public_html/app/ with subdirectories per module
- Authentication: session-based, no JWT
- Known constraints: can't modify php.ini globally, .htaccess only

Problem: [specific, observable symptom with reproduction steps]

This keeps Claude from suggesting server-level fixes you can't make and gets it working within your actual constraints.

Step 2: Ask for hypotheses, not answers

Instead of "what's wrong with this code?", ask: "What are the five most likely causes of this symptom in this environment? Rank them by probability and explain your reasoning."

This forces a probabilistic framing instead of a single confident answer. It also makes the output much easier to evaluate — you can immediately discard hypotheses you know are wrong and focus on the ones you haven't checked yet.

Step 3: Share the full request flow, not just a file

For auth bugs specifically, paste the entire flow: the login handler, the session initialization include, the redirect target, and the page that's failing. Annotate what each piece does in comments so Claude has narrative context, not just syntax.

Step 4: Ask it to identify what it can't see

This prompt is easy to overlook. After sharing code and getting an initial analysis, follow up with: "What information would you need to be more certain about this diagnosis? What parts of the system are you not seeing that could affect this?"

Claude handles this meta-level question well. It will often surface exactly the blind spots — "I can't see your redirect targets" or "I don't know how your session include is being loaded relative to your subdirectory setup" — that you need to go investigate yourself.

06Where AI-Assisted Code Review Actually Shines

Here's a breakdown of where to lean on Claude for code review and where not to:

  • Great for: Spotting security issues in isolated functions (SQL injection, unescaped output, file path traversal)
  • Great for: Reviewing logic errors in self-contained algorithms
  • Great for: Suggesting improvements to code structure and naming
  • Great for: Generating a checklist of things to verify when debugging a class of problem
  • Weak for: Bugs that emerge from system architecture and configuration
  • Weak for: Environment-specific issues (hosting quirks, shared server constraints)
  • Weak for: Anything where the bug is in the interaction between components you haven't shown it

07The Mindset Shift That Actually Matters

The biggest takeaway here isn't a prompt template. It's a mindset reframe.

Claude is not a senior developer who knows your codebase. It's an extremely well-read collaborator who knows a lot about programming in general and nothing about your specific system. The quality of its help scales directly with the quality of context you provide — and with your willingness to critically evaluate its output instead of just running with it.

The AI doesn't slow you down — uncritical trust in it does.

That's the real lesson. AI-assisted code review is genuinely powerful when you treat the AI as a structured thinking partner and yourself as the final authority. The moment you reverse that relationship, you're just outsourcing your judgment to a system that sounds confident but has no idea what's actually running on your server.

08A Workflow for Non-Trivial Bugs

  1. Reproduce it yourself and write down exact steps
  2. Check logs before opening any chat window
  3. Form your own hypothesis first
  4. Use Claude to pressure-test your hypothesis and surface alternatives you might have missed
  5. Use Claude to generate a checklist of things to verify — then go verify them yourself
  6. Treat any single confident answer from Claude as one data point, not a verdict

It's slower than just asking "what's wrong?" and accepting the first answer. But it's faster than chasing confident wrong answers down dead-end rabbit holes.

The tool is good. The discipline around using it is what takes practice.

AI

Denny Pratama

Product designer in Indonesia. Since 2018 I’ve designed SaaS products, dashboards and marketing sites, and now I build my own designs too.

About me