// 39 tips tagged "debugging"
Paste error messages with "why did this fail?" instead of "fix this" to get Claude to diagnose the root cause before applying a fix.
After Claude finishes a task, ask it to list everything that could go wrong before you ship for a free second review that catches edge cases.
Most code is written for the happy path — everything works, data exists, APIs respond, and inputs are valid. Tell Claude to read your code and add error handling for every failure mode — null values, network timeouts, invalid data, missing config, and unexpected states — so your app degrades gracefully instead of crashing.
When a page takes five seconds to load or an API endpoint times out under load, tell Claude which route is slow and it traces the entire code path — controller, services, queries, loops — identifying N+1 queries, redundant computations, missing indexes, and cacheable operations, then fixes each bottleneck.
Flaky tests are maddening — they pass locally, fail in CI, pass again when you retry. Tell Claude to read the test, identify the source of non-determinism — timing issues, shared state, date dependencies, or order-dependent setup — and fix the root cause so the test is reliably green or reliably red.
When your app throws an error, don't just Google the message — paste the full stack trace into Claude Code. It reads the trace, opens the referenced files in your codebase, follows the call chain, and pinpoints the actual root cause instead of just explaining the symptom.
Claude Code can see images — paste a screenshot of a broken UI, a confusing error dialog, terminal output, or a design mockup and Claude reads it visually, understands the context, and helps you fix the problem or implement the design without you having to transcribe anything.
Tell Claude to read your business logic and add log statements at the important decision points — where conditions branch, where external calls happen, and where data transforms — so when something goes wrong in production, the logs tell you exactly where and why.
Tell Claude to trace every import and dependency across your codebase, then show you which modules depend on which — spotting circular dependencies, God modules everything imports, and tightly coupled layers that should be independent.
Tell Claude to check that related files are in sync — models match their migrations, forms match the APIs they submit to, TypeScript types match the backend responses, and config matches what the code actually references. When they drift apart, bugs hide in the gaps.
When Claude Code isn't working right — MCP servers failing, authentication errors, or unexpected behavior — run /doctor to get a diagnostic report that checks your configuration, API connection, installed tools, and settings across all scopes so you can pinpoint what's wrong.
When a specific query is slow, run EXPLAIN on it and paste the execution plan into Claude — it reads the plan, spots full table scans, bad join orders, and missing indexes, then rewrites the query and suggests schema changes to make it fast.